Alright so here's the deal. i'm using strapdown to render markdown posts. strapdown uses marked to parse these markdown posts, which in turn uses regular expression literals.
I've tried to extend marked to include the following markdown "extensions" as described here (shoutout to soffes).
literal for underline extension: /_(.*?)_/
literal for highlight extension: /==(.*?)==/
underline test code (some code omitted, for clarity):
var src = "two new features to the marked.js inline lexer. ==highlighted text==, and _underlined text_";
var underline = /_(.*?)_/;
var cap = underline.exec(src);
document.write("<em class='underline'>"+cap[1]+"</em>");
which works as expected (outputting <em class="underline">underlined text</em>
).
here's the highlight test code (again, some stuff omitted):
var src = "two new features to the marked.js inline lexer. ==highlighted text==, and _underlined text_";
var highlight = /==(.*?)==/;
var cap = highlight.exec(src);
document.write("<strong class='highlighted'>"+cap[1]+"</strong>");
which again, works as expected (outputting <strong class='highlighted'>highlighted text</strong>
).
the inline lexer for marked begins all of it's regex literals with ^
.
ie:
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/
so naturally, i feel as though i should do the same. i modify my literals like this:
literal for underline extension: /^_(.*?)_/
literal for highlight extension: /^==(.*?)==/
and then, highlighting stops matching. interestingly, underline continues to match.
I realize this might be a question that requires some knowledge of how marked works, but it usually can't hurt to ask...right?
you can see what i've worked up (which requires marked.js) here. To see how marked is being told to parse markdown with my extensions, you can check out line 658 here
I modified the underline
and stronghighlight
regexes a bit, and added |==
to the text
regex to make it work:
text: /^[\s\S]+?(?=[\\<!\[_*`]|==| {2,}\n|$)/,
stronghighlight: /^==([^=]+)==/,
underline: /^_([^_]+)_/
My jsfiddle test page is here. For the sake of simplicity, I copied marked.js at the beginning and edited it in place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With