Skip to content

Added support to adding simple block rules - #1003

Closed
KostyaTretyak wants to merge 2 commits into
markedjs:masterfrom
KostyaTretyak:simple
Closed

Added support to adding simple block rules#1003
KostyaTretyak wants to merge 2 commits into
markedjs:masterfrom
KostyaTretyak:simple

Conversation

@KostyaTretyak

@KostyaTretyakKostyaTretyak commented Jan 6, 2018

Copy link
Copy Markdown
Contributor
constmarked=require('marked');constblockStr=`# Example usage with embed block code@@@ gista9dfd77500990871fc58b97fdb57d91f.js@@@@@@ youtubeJgwnkM5WwWE@@@`;marked.setBlockRule(/^@@@*(\w+)\n([\s\S]+?)\n@@@/,function(execArr){constchannel=execArr[1];switch(channel){case'youtube': {constid=marked.escape(execArr[2]);return`<iframe width="420" height="315" src="https://www.youtube.com/embed/${id}"></iframe>\n`;}case'gist': {constid=marked.escape(execArr[2]);return`<script src="https://gist.github.com/${id}"></script>\n`;}}});consthtml=marked.parse(blockStr);console.log(html);

Output:

<h1id="example-usage-with-embed-block-code">Example usage with embed block code</h1><scriptsrc="https://gist.github.com/a9dfd77500990871fc58b97fdb57d91f.js"></script><iframewidth="420" height="315" src="https://www.youtube.com/embed/JgwnkM5WwWE"></iframe>

@joshbruce

Copy link
Copy Markdown
Member

Thanks @KostyaTretyak! Gonna flag this for milestone 0.5.0. If you could take a look at #1002 - I believe it could cause this to have merge conflicts in the future as we would need to add tests to document and validate the solution works. Cheers.

@joshbrucejoshbruce added this to the 0.6.0 - Improve developer experience milestone Jan 6, 2018
@KostyaTretyak

Copy link
Copy Markdown
ContributorAuthor

@joshbruce no, it does not seem that my changes were in conflict with the changes introduced in #1002.

Comment threadlib/marked.js Outdated
for (var i = 0; i < simpleRules.length; i++) {
if (cap = simpleRules[i].exec(src)) {
src = src.substring(cap[0].length);
this.tokens.push({ type: 'simpleRule' + simpleRules.length, cap: cap });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be 'simpleRule' + i ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, I'll correct it right now. Thank you.

@joshbruce

Copy link
Copy Markdown
Member

See #1026

Closing as merge conflicts - also building out the issue above to consolidate ideas and approaches proposed.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@KostyaTretyak@joshbruce@Feder1co5oave