commonmark / commonmark/commonmark.js

reMaybeSpecial and custom syntax

Open
#189 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
231
Avg merge
2d 11h
Merged PRs (30d)
3

Description

I'm upgrading the Markdown parsers on a client's site using CommonMark parsers on both the server and client side. The parser on the server side (in PHP) is the "official" one but we're doing previews on the client side and there were some inconsistencies with the previous scripts.

In the site's markup, there's some "custom" syntax elements which I'm trying to replicate under the CommonMark parsers/renderers as custom syntax/nodes (the previous scripts just did post-processing on the HTML after converting the Markdown). I've got this working on the PHP side, but I'm stuck on the JS side because the custom syntax uses the : character (specifically :::) to denote the start and end of a block similar to backtick fences, but there's an optimization which is stopping the parsing of custom blocks if they don't have a character in the reMaybeSpecial pattern:

https://github.com/commonmark/commonmark.js/blob/8c698a295f7cea58597769ccfaab2219add45e44/dist/commonmark.js#L8683

https://github.com/commonmark/commonmark.js/blob/8c698a295f7cea58597769ccfaab2219add45e44/dist/commonmark.js#L9438-L9444

If I use a debugger and set a breakpoint before line 9438 and then change reMaybeSpecial to include the : character, the rest of my code works more or less as expected…

Is there a way to work around this? I can't find a way to alter reMaybeSpecial from external code. It would be great if it were alterable somehow. (I'd try patching it myself, but I don't understand this newfangled JavaScript where require() is being used all over the place.)

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

Read dist/commonmark.js around lines 8683 and 9438-9444, then trace how reMaybeSpecial controls recognition of potential custom block syntax. Confirm the existing client-side extension behavior with ::: delimiters and define what an external workaround or configurable pattern must support without changing the bundled parser.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.