Skip to content

Commit

Permalink
Customize renderer for block level code in marked module
Browse files Browse the repository at this point in the history
  • Loading branch information
devowhippit committed Oct 20, 2022
1 parent 5bf8a9a commit 1e92c3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions bin/slm.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ const compile = {

marked.setOptions(options().config.marked);

/**
* Renderer for code blocks
*
* @var {Object}
*/
let renderer = {
code(code) {
let escaped = code.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;');

return `<div class="code-block"><pre>${escaped}</pre></div>`;
}
};

marked.use({renderer});

md = marked(md);

md = mrkdwn.slm(md);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nycopportunity/pttrn",
"nice": "Patterns CLI",
"version": "1.4.7",
"version": "1.5.0",
"description": "A front-end CLI for building and managing design pattern libraries",
"author": "[email protected]",
"license": "GPL-3.0+",
Expand Down

0 comments on commit 1e92c3b

Please sign in to comment.