From 5a049c48b82c6c1dd59f49270f5b4e73cced4d85 Mon Sep 17 00:00:00 2001 From: David Russell Date: Wed, 6 Sep 2017 09:14:13 +0700 Subject: [PATCH] Updated code presenting fragment syntax sophistication. --- .../9.12.0/reveal-code-focus-1.0.0-mod.js | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/public/libs/highlight.js/9.12.0/reveal-code-focus-1.0.0-mod.js b/public/libs/highlight.js/9.12.0/reveal-code-focus-1.0.0-mod.js index 44fbd8f..3c4bbe0 100644 --- a/public/libs/highlight.js/9.12.0/reveal-code-focus-1.0.0-mod.js +++ b/public/libs/highlight.js/9.12.0/reveal-code-focus-1.0.0-mod.js @@ -200,20 +200,42 @@ var topLineNumber, bottomLineNumber; forEach(lines.split(','), function(line) { - lines = line.split('-'); - if (lines.length == 1) { - focusLine(lines[0]); - } else { - var i = lines[0] - 1, j = lines[1]; - - while (++i <= j) { - focusLine(i); - } - } + var parsed = parseDataCodeFocus(line); + forEach(parsed, function(line) { + focusLine(line); + }); }); updateCodeOpacity(); + function parseDataCodeFocus(dataCodeFocus) { + // + // Parse data-code-focus attribute data: + // + // Examples: + // [1], [1, 2], [1-2], [1-3, 5], [6, 9-11] + // + var parsed = new Array(); + try { + var dcfParts = dataCodeFocus.split(","); + forEach(dcfParts, function(dcfPart) { + var frag = dcfPart.split('-'); + if(frag.length == 1) { + parsed.push(frag); + } else { + var i = frag[0] - 1, j = frag[1]; + while (++i <= j) { + parsed.push(i); + } + } + }); + } catch(ex) { + // Ignore bad data-code-focus syntax + } + + return parsed; + } + function focusLine(lineNumber) { // Convert from 1-based index to 0-based index. lineNumber -= 1;