StackExchange / StackExchange/Stacks-Editor

bug(markdown) Adding code block around backticks doesn't work properly

Open
#186 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug mode - markdown
Dominant language
TypeScript
Stars
437
Forks
61
Avg merge
16h 2m
Merged PRs (30d)
8

Description

To Reproduce

  1. MD mode, type in 4 backticks
  2. Highlight them, set codeblock
  3. results in 3 lines with 3 backticks
  4. This gets mangled when go to RT, turning into 2 empty code blocks. So this translation is a problem.
  5. Going back to MD, ends up with 2 lines of 3 backticks, and empty line, and 2 lines of 3 backticks again (translation of the RT from step 4).

The MSE post points out several way to apply the codeblock to make this work, most practically in this case:

````
```
````

Which translates fine round-trip.

Expected behavior
Making this into a code block will do so in such a way that it can round trip and render properly

Screenshots
demo

Desktop (please complete the following information):
Windows 11 Chrome 103

Additional context
https://meta.stackexchange.com/a/380356/51

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the four-backtick code-block case in MD mode, apply the codeblock formatting, and round-trip it through RT and back to MD. Trace the Markdown-to-rich-text and rich-text-to-Markdown conversion paths involved; done means the content remains a valid, correctly rendered code block through the round trip, including the example shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
markdown, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.