1
0
Fork 0

Merge pull request #2956 from ryzokuken/plugin-markdown

markdown plugin improvements
This commit is contained in:
Hakim El Hattab 2021-05-17 09:54:24 +02:00 committed by GitHub
commit 2c115b887a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 20 deletions

View File

@ -421,34 +421,42 @@ const Plugin = () => {
deck = reveal; 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 renderer.code = ( code, language ) => {
let lineNumbers = '';
// Users can opt in to show line numbers and highlight // Off by default
// specific lines. let lineNumbers = '';
// ```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 // Users can opt in to show line numbers and highlight
// avoid having the HTML parser alter our code before // specific lines.
// highlight.js is able to read it // ```javascript [] show line numbers
code = escapeForHTML( code ); // ```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();
}
return `<pre><code ${lineNumbers} class="${language}">${code}</code></pre>`; // 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>`;
};
}
if (animateLists) {
renderer.listitem = (text) => `<li class="fragment">${text}</li>`;
}
marked.setOptions( { marked.setOptions( {
renderer, renderer,
...deck.getConfig().markdown ...markedOptions
} ); } );
return processSlides( deck.getRevealElement() ).then( convertSlides ); return processSlides( deck.getRevealElement() ).then( convertSlides );