mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-08-06 06:38:08 +02:00
add ln-start-from for code sections to markdown
This commit is contained in:
@@ -99,6 +99,25 @@
|
|||||||
</script>
|
</script>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- add optional line count offset, in this case 287 -->
|
||||||
|
<section data-markdown>
|
||||||
|
<script type="text/template">
|
||||||
|
## echo.c
|
||||||
|
|
||||||
|
```c [287: 2|4,6]
|
||||||
|
/* All of the options in this arg are valid, so handle them. */
|
||||||
|
p = arg + 1;
|
||||||
|
do {
|
||||||
|
if (*p == 'n')
|
||||||
|
nflag = 0;
|
||||||
|
if (*p == 'e')
|
||||||
|
eflag = '\\';
|
||||||
|
} while (*++p);
|
||||||
|
```
|
||||||
|
[source](https://git.busybox.net/busybox/tree/coreutils/echo.c?h=1_36_stable#n287)
|
||||||
|
</script>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Images -->
|
<!-- Images -->
|
||||||
<section data-markdown>
|
<section data-markdown>
|
||||||
<script type="text/template">
|
<script type="text/template">
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -13,7 +13,9 @@ const DEFAULT_SLIDE_SEPARATOR = '\r?\n---\r?\n',
|
|||||||
|
|
||||||
const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
const SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
|
||||||
|
|
||||||
const CODE_LINE_NUMBER_REGEX = /\[([\s\d,|-]*)\]/;
|
// match an optional line number offset and highlight line numbers
|
||||||
|
// [<line numbers>] or [<offset>: <line numbers>]
|
||||||
|
const CODE_LINE_NUMBER_REGEX = /\[\s*((\d*):)?\s*([\s\d,|-]*)\]/;
|
||||||
|
|
||||||
const HTML_ESCAPE_MAP = {
|
const HTML_ESCAPE_MAP = {
|
||||||
'&': '&',
|
'&': '&',
|
||||||
@@ -429,14 +431,23 @@ const Plugin = () => {
|
|||||||
renderer.code = ( code, language ) => {
|
renderer.code = ( code, language ) => {
|
||||||
|
|
||||||
// Off by default
|
// Off by default
|
||||||
|
let lineNumberOffset = '';
|
||||||
let lineNumbers = '';
|
let lineNumbers = '';
|
||||||
|
|
||||||
// Users can opt in to show line numbers and highlight
|
// Users can opt in to show line numbers and highlight
|
||||||
// specific lines.
|
// specific lines.
|
||||||
// ```javascript [] show line numbers
|
// ```javascript [] show line numbers
|
||||||
// ```javascript [1,4-8] highlights lines 1 and 4-8
|
// ```javascript [1,4-8] highlights lines 1 and 4-8
|
||||||
|
// optional line number offset:
|
||||||
|
// ```javascript [25: 1,4-8] start line numbering at 25,
|
||||||
|
// highlights lines 1 (numbered as 25) and 4-8 (numbered as 28-32)
|
||||||
if( CODE_LINE_NUMBER_REGEX.test( language ) ) {
|
if( CODE_LINE_NUMBER_REGEX.test( language ) ) {
|
||||||
lineNumbers = language.match( CODE_LINE_NUMBER_REGEX )[1].trim();
|
let lineNumberOffsetMatch = language.match( CODE_LINE_NUMBER_REGEX )[2];
|
||||||
|
if (lineNumberOffsetMatch){
|
||||||
|
lineNumberOffset = `data-ln-start-from="${lineNumberOffsetMatch.trim()}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
lineNumbers = language.match( CODE_LINE_NUMBER_REGEX )[3].trim();
|
||||||
lineNumbers = `data-line-numbers="${lineNumbers}"`;
|
lineNumbers = `data-line-numbers="${lineNumbers}"`;
|
||||||
language = language.replace( CODE_LINE_NUMBER_REGEX, '' ).trim();
|
language = language.replace( CODE_LINE_NUMBER_REGEX, '' ).trim();
|
||||||
}
|
}
|
||||||
@@ -446,7 +457,9 @@ const Plugin = () => {
|
|||||||
// highlight.js is able to read it
|
// highlight.js is able to read it
|
||||||
code = escapeForHTML( code );
|
code = escapeForHTML( code );
|
||||||
|
|
||||||
return `<pre><code ${lineNumbers} class="${language}">${code}</code></pre>`;
|
// return `<pre><code ${lineNumbers} class="${language}">${code}</code></pre>`;
|
||||||
|
|
||||||
|
return `<pre><code ${lineNumbers} ${lineNumberOffset} class="${language}">${code}</code></pre>`;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user