Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reMaybeSpecial and custom syntax #189

Open
GarrettAlbright opened this issue May 10, 2020 · 1 comment
Open

reMaybeSpecial and custom syntax #189

GarrettAlbright opened this issue May 10, 2020 · 1 comment

Comments

@GarrettAlbright
Copy link

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:

var reMaybeSpecial = /^[#`~*+_=<>0-9-]/;

if (
!this.indented &&
!reMaybeSpecial.test(ln.slice(this.nextNonspace))
) {
this.advanceNextNonspace();
break;
}

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.)

@jgm
Copy link
Member

jgm commented May 10, 2020

Since the API allows customization, we should probably allow this to be customized too (e.g. by having a list of special characters).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants