@farberg/reveal-template 1.1.27 → 1.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farberg/reveal-template",
3
- "version": "1.1.27",
3
+ "version": "1.1.29",
4
4
  "homepage": "https://github.com/pfisterer/reveal-template",
5
5
  "description": "Reveal.js template for Dennis' lectures",
6
6
  "main": "index.js",
@@ -21,10 +21,10 @@
21
21
  "fflate": "^0.8.3",
22
22
  "mermaid": "^11.15.0",
23
23
  "pdf-merger-js": "^5.1.2",
24
- "puppeteer": "^25.0.2",
24
+ "puppeteer": "^25.1.0",
25
25
  "qr-creator": "^1.0.0",
26
26
  "reveal.js": "^6.0.1",
27
- "reveal.js-mermaid-plugin": "^11.12.3",
27
+ "reveal.js-mermaid-plugin": "^11.15.0",
28
28
  "reveal.js-plugins": "^4.6.0",
29
29
  "reveal.js-simplemenu": "^2.0.3",
30
30
  "serve-static": "^2.2.1"
@@ -3,7 +3,8 @@ Shows a code snippet after loading it from a file.
3
3
 
4
4
  Parameters:
5
5
  - data-code: Language
6
- - data-begin: Begin indicator in the file (optional)
6
+ - data-begin: Begin indicator in the file (optional; substring match, first occurrence)
7
+ - data-begin-nth: Start after the Nth occurrence of data-begin instead of the first (optional, 1-based)
7
8
  - data-end: End indicator in the file (optional)
8
9
  - data-link: Show a link to the file (optional)
9
10
 
@@ -45,17 +46,25 @@ function showCode(el, language, code, link, outdent) {
45
46
  return newEl
46
47
  }
47
48
 
48
- function extractBeginEndSnippet(code, beginMarker, endMarker) {
49
+ function extractBeginEndSnippet(code, beginMarker, endMarker, beginNth) {
49
50
  let lines = code.split('\n');
50
51
  let out = "";
51
- let beginFound = beginMarker ? false : true
52
52
  beginMarker = beginMarker ? beginMarker.trim() : null
53
+ // Trim and null-guard endMarker: otherwise indexOf(null) below coerces to
54
+ // indexOf("null"), so a line containing "null" would end the snippet early.
55
+ endMarker = endMarker ? endMarker.trim() : null
56
+ // Markers are substring-matched. By default the snippet starts after the
57
+ // first line containing beginMarker; data-begin-nth selects a later one.
58
+ let nth = beginNth && beginNth > 0 ? beginNth : 1
59
+ let seen = 0
60
+ let beginFound = beginMarker ? false : true
53
61
 
54
62
  for (let line of lines) {
55
63
  if (!beginFound && line.indexOf(beginMarker) >= 0) {
56
- beginFound = true;
64
+ if (++seen >= nth)
65
+ beginFound = true;
57
66
  continue;
58
- } else if (beginFound && line.indexOf(endMarker) >= 0) {
67
+ } else if (beginFound && endMarker && line.indexOf(endMarker) >= 0) {
59
68
  break;
60
69
  } else if (!beginFound) {
61
70
  continue;
@@ -179,6 +188,7 @@ export default () => {
179
188
  let language = el.getAttribute("data-code");
180
189
  let url = el.getAttribute("href");
181
190
  let beginMarker = el.getAttribute("data-begin")
191
+ let beginNth = parseInt(el.getAttribute("data-begin-nth"), 10) || 1
182
192
  let endMarker = el.getAttribute("data-end")
183
193
  let showLink = el.hasAttribute("data-link")
184
194
  let outdentCode = el.hasAttribute("data-outdent")
@@ -203,7 +213,7 @@ export default () => {
203
213
  continue
204
214
  }
205
215
  const text = await response.text()
206
- let code = extractBeginEndSnippet(text, beginMarker, endMarker)
216
+ let code = extractBeginEndSnippet(text, beginMarker, endMarker, beginNth)
207
217
 
208
218
  if (!code) {
209
219
  showError(el, `No content extracted from ${url} (begin=${beginMarker}, end=${endMarker})`)