HTML Tags not closing with markdown extension #1598

Open
opened 2025-08-01 15:12:30 +02:00 by natsch93 · 1 comment
natsch93 commented 2025-08-01 15:12:30 +02:00 (Migrated from github.com)

Describe the issue

HTML Tags are not closing automatically with markdown() extension.

<div> seems to work fine, and closes automatically.

But trying other elements like <b>, <a>, <label>, etc. does not work, unless a <div></div> is present above.

Reproduction steps:

  • Open the reproduction link
  • Enter <b>, notice how doesn't auto-close
  • Delete <b> and enter <div>, <div> auto-closes successfully
  • Go below the <div></div> and enter <b> again, this time auto-close is successful for <b>

https://github.com/user-attachments/assets/359379bf-2428-4c64-8f51-d016f951747b

Browser and platform

Chrome

https://codemirror.net/try/#c=aW1wb3J0IHsgYmFzaWNTZXR1cCwgRWRpdG9yVmlldyB9IGZyb20gImNvZGVtaXJyb3IiCmltcG9ydCB7IG1hcmtkb3duIH0gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZy1tYXJrZG93biIKCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogIiIsCiAgZXh0ZW5zaW9uczogWwogICAgYmFzaWNTZXR1cCwKICAgIG1hcmtkb3duKCksCiAgXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSk=

### Describe the issue HTML Tags are not closing automatically with `markdown()` extension. `<div>` seems to work fine, and closes automatically. But trying other elements like `<b>`, `<a>`, `<label>`, etc. does not work, _unless_ a `<div></div>` is present above. Reproduction steps: - Open the [reproduction link](https://codemirror.net/try/#c=aW1wb3J0IHsgYmFzaWNTZXR1cCwgRWRpdG9yVmlldyB9IGZyb20gImNvZGVtaXJyb3IiCmltcG9ydCB7IG1hcmtkb3duIH0gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZy1tYXJrZG93biIKCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogIiIsCiAgZXh0ZW5zaW9uczogWwogICAgYmFzaWNTZXR1cCwKICAgIG1hcmtkb3duKCksCiAgXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSk=) - Enter `<b>`, notice how doesn't auto-close - Delete `<b>` and enter `<div>`, `<div>` auto-closes successfully - Go below the `<div></div>` and enter `<b>` again, this time auto-close is successful for `<b>` https://github.com/user-attachments/assets/359379bf-2428-4c64-8f51-d016f951747b ### Browser and platform Chrome ### Reproduction link https://codemirror.net/try/#c=aW1wb3J0IHsgYmFzaWNTZXR1cCwgRWRpdG9yVmlldyB9IGZyb20gImNvZGVtaXJyb3IiCmltcG9ydCB7IG1hcmtkb3duIH0gZnJvbSAiQGNvZGVtaXJyb3IvbGFuZy1tYXJrZG93biIKCmxldCB2aWV3ID0gbmV3IEVkaXRvclZpZXcoewogIGRvYzogIiIsCiAgZXh0ZW5zaW9uczogWwogICAgYmFzaWNTZXR1cCwKICAgIG1hcmtkb3duKCksCiAgXSwKICBwYXJlbnQ6IGRvY3VtZW50LmJvZHkKfSk=
marijnh commented 2025-08-01 18:14:14 +02:00 (Migrated from github.com)

What's happening is that the Markdown parser isn't yet parsing <b as an HTML tag, whereas it is <div (or <p or any block tag). As such, HTML-specific behavior like the auto-closing isn't firing when a > is typed. This parsing behavior matches the CommonMark spec (compare this and this example), but I agree that the outcome isn't great in this situation.

It seems kind of hard to work around, though. The closing logic is implemented with an input handler, which runs before the > is in the document (and thus in the parse).

What's happening is that the Markdown parser isn't yet parsing `<b` as an HTML tag, whereas it is `<div` (or `<p` or any block tag). As such, HTML-specific behavior like the auto-closing isn't firing when a `>` is typed. This parsing behavior matches the CommonMark spec (compare [this](https://spec.commonmark.org/dingus/?text=%3Cb) and [this](https://spec.commonmark.org/dingus/?text=%3Cp) example), but I agree that the outcome isn't great in this situation. It seems kind of hard to work around, though. The closing logic is implemented with an input handler, which runs before the `>` is in the document (and thus in the parse).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/dev#1598
No description provided.