Skip to content

Commit

Permalink
Merge pull request hakimel#2956 from ryzokuken/plugin-markdown
Browse files Browse the repository at this point in the history
markdown plugin improvements
  • Loading branch information
hakimel authored May 17, 2021
2 parents 7daea49 + 03126c5 commit 2c115b8
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions plugin/markdown/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,34 +421,42 @@ const Plugin = () => {

deck = reveal;

let renderer = new marked.Renderer();
let { renderer, animateLists, ...markedOptions } = deck.getConfig().markdown;

renderer.code = ( code, language ) => {
if (!renderer) {
let renderer = new marked.Renderer();

// Off by default
let lineNumbers = '';
renderer.code = ( code, language ) => {

// Users can opt in to show line numbers and highlight
// specific lines.
// ```javascript [] show line numbers
// ```javascript [1,4-8] highlights lines 1 and 4-8
if( CODE_LINE_NUMBER_REGEX.test( language ) ) {
lineNumbers = language.match( CODE_LINE_NUMBER_REGEX )[1].trim();
lineNumbers = `data-line-numbers="${lineNumbers}"`;
language = language.replace( CODE_LINE_NUMBER_REGEX, '' ).trim();
}
// Off by default
let lineNumbers = '';

// Users can opt in to show line numbers and highlight
// specific lines.
// ```javascript [] show line numbers
// ```javascript [1,4-8] highlights lines 1 and 4-8
if( CODE_LINE_NUMBER_REGEX.test( language ) ) {
lineNumbers = language.match( CODE_LINE_NUMBER_REGEX )[1].trim();
lineNumbers = `data-line-numbers="${lineNumbers}"`;
language = language.replace( CODE_LINE_NUMBER_REGEX, '' ).trim();
}

// Escape before this gets injected into the DOM to
// avoid having the HTML parser alter our code before
// highlight.js is able to read it
code = escapeForHTML( code );
// Escape before this gets injected into the DOM to
// avoid having the HTML parser alter our code before
// highlight.js is able to read it
code = escapeForHTML( code );

return `<pre><code ${lineNumbers} class="${language}">${code}</code></pre>`;
};
return `<pre><code ${lineNumbers} class="${language}">${code}</code></pre>`;
};
}

if (animateLists) {
renderer.listitem = (text) => `<li class="fragment">${text}</li>`;
}

marked.setOptions( {
renderer,
...deck.getConfig().markdown
...markedOptions
} );

return processSlides( deck.getRevealElement() ).then( convertSlides );
Expand Down

0 comments on commit 2c115b8

Please sign in to comment.