Skip to content

Commit

Permalink
Merge branch 'hakimel:master' into theme
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusTiede authored Aug 14, 2023
2 parents c804fd0 + e1c1805 commit f47bb25
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions examples/markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@
</script>
</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 -->
<section data-markdown>
<script type="text/template">
Expand Down
16 changes: 10 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ function compileSass() {

sass.render({
data: transformedFile.contents.toString(),
includePaths: ['css/', 'css/theme/template']
file: transformedFile.path,
}, ( err, result ) => {
if( err ) {
console.log( vinylFile.path );
console.log( err.formatted );
callback(err);
}
else {
transformedFile.extname = '.css';
Expand Down Expand Up @@ -286,7 +285,7 @@ gulp.task('package', gulp.series(() =>

))

gulp.task('reload', () => gulp.src(['**/*.html', '**/*.md'])
gulp.task('reload', () => gulp.src(['index.html'])
.pipe(connect.reload()));

gulp.task('serve', () => {
Expand All @@ -298,14 +297,19 @@ gulp.task('serve', () => {
livereload: true
})

gulp.watch(['**/*.html', '**/*.md'], gulp.series('reload'))
const slidesRoot = root.endsWith('/') ? root : root + '/'
gulp.watch([
slidesRoot + '**/*.html',
slidesRoot + '**/*.md',
`!${slidesRoot}**/node_modules/**`, // ignore node_modules
], gulp.series('reload'))

gulp.watch(['js/**'], gulp.series('js', 'reload', 'eslint'))

gulp.watch(['plugin/**/plugin.js', 'plugin/**/*.html'], gulp.series('plugins', 'reload'))

gulp.watch([
'css/theme/source/*.{sass,scss}',
'css/theme/source/**/*.{sass,scss}',
'css/theme/template/*.{sass,scss}',
], gulp.series('css-themes', 'reload'))

Expand Down
2 changes: 1 addition & 1 deletion js/controllers/autoanimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export default class AutoAnimate {
} );

// Line numbers
this.findAutoAnimateMatches( pairs, pair.from, pair.to, '.hljs .hljs-ln-line[data-line-number]', node => {
this.findAutoAnimateMatches( pairs, pair.from, pair.to, '.hljs .hljs-ln-numbers[data-line-number]', node => {
return node.getAttribute( 'data-line-number' );
}, {
scale: false,
Expand Down
10 changes: 6 additions & 4 deletions js/controllers/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class Location {
// If the first bit is not fully numeric and there is a name we
// can assume that this is a named link
if( !/^[0-9]*$/.test( bits[0] ) && name.length ) {
let element;
let slide;

let f;

Expand All @@ -62,12 +62,14 @@ export default class Location {

// Ensure the named link is a valid HTML ID attribute
try {
element = document.getElementById( decodeURIComponent( name ) );
slide = document
.getElementById( decodeURIComponent( name ) )
.closest('.slides>section, .slides>section>section');
}
catch ( error ) { }

if( element ) {
return { ...this.Reveal.getIndices( element ), f };
if( slide ) {
return { ...this.Reveal.getIndices( slide ), f };
}
}
else {
Expand Down
6 changes: 1 addition & 5 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2203,11 +2203,7 @@ export default function( revealElement, options ) {

if( currentSlide && config.autoSlide !== false ) {

let fragment = currentSlide.querySelector( '.current-fragment' );

// When the slide first appears there is no "current" fragment so
// we look for a data-autoslide timing on the first fragment
if( !fragment ) fragment = currentSlide.querySelector( '.fragment' );
let fragment = currentSlide.querySelector( '.current-fragment[data-autoslide]' );

let fragmentAutoSlide = fragment ? fragment.getAttribute( 'data-autoslide' ) : null;
let parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
Expand Down
4 changes: 2 additions & 2 deletions plugin/markdown/markdown.esm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugin/markdown/markdown.js

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions plugin/markdown/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import { marked } from 'marked';

const DEFAULT_SLIDE_SEPARATOR = '\r?\n---\r?\n',
DEFAULT_NOTES_SEPARATOR = 'notes?:',
DEFAULT_VERTICAL_SEPARATOR = null,
DEFAULT_NOTES_SEPARATOR = '^\s*notes?:',
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$',
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$';

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 = {
'&': '&amp;',
Expand Down Expand Up @@ -92,10 +95,12 @@ const Plugin = () => {
* values for what's not defined.
*/
function getSlidifyOptions( options ) {
const markdownConfig = deck.getConfig().markdown;

options = options || {};
options.separator = options.separator || DEFAULT_SLIDE_SEPARATOR;
options.notesSeparator = options.notesSeparator || DEFAULT_NOTES_SEPARATOR;
options.separator = options.separator || markdownConfig?.separator || DEFAULT_SLIDE_SEPARATOR;
options.verticalSeparator = options.verticalSeparator || markdownConfig?.verticalSeparator || DEFAULT_VERTICAL_SEPARATOR;
options.notesSeparator = options.notesSeparator || markdownConfig?.notesSeparator || DEFAULT_NOTES_SEPARATOR;
options.attributes = options.attributes || '';

return options;
Expand Down Expand Up @@ -429,14 +434,23 @@ const Plugin = () => {
renderer.code = ( code, language ) => {

// Off by default
let lineNumberOffset = '';
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
// 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 ) ) {
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}"`;
language = language.replace( CODE_LINE_NUMBER_REGEX, '' ).trim();
}
Expand All @@ -446,7 +460,9 @@ const Plugin = () => {
// 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>`;

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

Expand Down
34 changes: 34 additions & 0 deletions test/test-markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,34 @@
```
</script>
</section>
<section data-markdown class="with-offset">
<script type="text/template">
```[123:]
code
```
</script>
</section>
<section data-markdown class="with-line-highlights-and-lanugage">
<script type="text/template">
```javascript [1,2,3]
code
```
</script>
</section>
<section data-markdown class="with-line-highlights-offset-and-lanugage">
<script type="text/template">
```javascript [456: 3,4,5]
code
```
</script>
</section>
<section data-markdown class="with-line-offset-and-lanugage">
<script type="text/template">
```javascript [756:]
code
```
</script>
</section>
<section data-markdown class="with-code-in-fragment">
<script type="text/template">
```js
Expand Down Expand Up @@ -460,9 +481,22 @@
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-line-highlights .hljs[data-line-numbers="1,2,3"]' ).length, 1 );
});

QUnit.test( '```[234: ] line offset only', function( assert ) {
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-offset .hljs[data-ln-start-from="123"]' ).length, 1 );
});

QUnit.test( '```javascript [1,2,3] enables line highlights and sets language', function( assert ) {
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-line-highlights-and-lanugage .hljs.javascript[data-line-numbers="1,2,3"]' ).length, 1 );
});

QUnit.test( '```javascript [123: 3,4,5] add line offset and enables line highlights and sets language', function( assert ) {
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-line-highlights-offset-and-lanugage .hljs.javascript[data-line-numbers="3,4,5"]' ).length, 1 );
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-line-highlights-offset-and-lanugage .hljs.javascript[data-ln-start-from="456"]' ).length, 1 );
});

QUnit.test( '```javascript [756:] add line offset and sets no line highlights and sets language', function( assert ) {
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-line-offset-and-lanugage .hljs.javascript[data-ln-start-from="756"]' ).length, 1 );
});

QUnit.test( '```block should allow custom fragment', function( assert ) {
assert.strictEqual( deck6.getRevealElement().querySelectorAll( '.with-code-in-fragment pre.fragment' ).length, 1 );
Expand Down

0 comments on commit f47bb25

Please sign in to comment.