StackExchange / StackExchange/Stacks-Editor

Multiple headings on a single line without newline are broken between MD and RT modes

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

Nobody has claimed this yet.

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

Description

Describe the bug
When multiple heading HTML tags are inlined without a newline at the end of the line, switching between Markdown and Rich Text mode will mangle the resulting headings into a single invalid tag, breaking the output.

To Reproduce
Steps to reproduce the behavior:

In Markdown mode, paste the following HTML into the editor. Ensure there are no newlines.

<h1>Heading1</h1><h2>Heading2</h2>

Switch to Rich Text mode and back to Markdown mode

You'll now see <h1Heading1h1h2>Heading2</h1Heading1h1h2>

Expected behavior
I expect the round-trip to preserve the headings as they were at the start.

Hunches:

When a heading in pure HTML is serialized, if it doesn't have a newline at the end, it goes through the heading: method of defaultMarkdownSerializerNodes in markdown-serializer.ts. If it has a newline at the end, it'll instead go through html_block() of customMarkdownSerializerNodes in the same file.

Screenshots
heading-merge-bug

Desktop (please
complete the following information):

  • OS: Windows 10
  • Browser Chrome
  • Version 103

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 round trip with the inline h1 and h2 HTML, then inspect markdown-serializer.ts, especially defaultMarkdownSerializerNodes.heading and customMarkdownSerializerNodes.html_block. Done means switching between Markdown and Rich Text preserves both headings instead of merging them into one invalid tag.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, markdown, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.