Skip to content

Commit 6041c38

Browse files
Version 2.0.3
• Allow Unicode characters
1 parent 4601571 commit 6041c38

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [2.0.3] - 2025-01-31
4+
### Changed
5+
- Changed regex to allow for Unicode characters in the `data-name` attribute.
6+
37
## [2.0.2] - 2025-01-29
48
### Changed
59
- Removed (version 4) peer dependency on Reveal.js.

demo-custom.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
transition: "slide",
4242
slideNumber: "c/t",
4343
simplemenu: {
44+
debug: true,
4445
barhtml: {
4546
header: "<div class='menubar'><a class='logo' href='#'><img src='img/logo.svg'></a><ul class='menu'></ul><div class='slide-number'></div></div>"
4647
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reveal.js-simplemenu",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"main": "plugin/simplemenu/simplemenu.js",
55
"module": "plugin/simplemenu/simplemenu.esm.js",
66
"description": "A simple Reveal.js plugin for a menubar or a header or footer with an auto-generated menu.",

plugin/simplemenu/plugin-src.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Plugin = () => {
6363
const isStack = (section) => {
6464
let isStack = false;
6565
for (let i = 0; i < section.childNodes.length; i++) {
66-
if (section.childNodes[i].tagName == "SECTION") {
66+
if (section.childNodes[i].tagName === "SECTION") {
6767
isStack = true
6868
break;
6969
}
@@ -154,7 +154,10 @@ const Plugin = () => {
154154
}
155155

156156
function copyDataAttributes(source, target) {
157-
[...source.attributes].filter( attr => attr.nodeName.indexOf('data') > -1 ).forEach( attr => { target.setAttribute(attr.nodeName, attr.nodeValue) })
157+
const filteredAttrs = [...source.attributes].filter(attr => attr.nodeName.indexOf('data') > -1);
158+
for (const attr of filteredAttrs) {
159+
target.setAttribute(attr.nodeName, attr.nodeValue);
160+
}
158161
}
159162

160163

@@ -198,7 +201,7 @@ const Plugin = () => {
198201
// If the (named) section is not a stack and does not have an ID, we need to give it one.
199202
if (!isStack(namedsection) && !namedsection.id) {
200203
// Note: Quarto will already have assigned an ID, but it may also have been done manually.
201-
namedsection.id = match.toLowerCase().replace(/\W/g, '');
204+
namedsection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
202205
} else if (isStack(namedsection)) {
203206

204207
// Find the first (visible) section inside a stack.
@@ -207,7 +210,7 @@ const Plugin = () => {
207210
let firstChildSection = allVisibleSects[0];
208211

209212
if ( firstChildSection && !firstChildSection.id ) {
210-
firstChildSection.id = match.toLowerCase().replace(/\W/g, '');
213+
firstChildSection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
211214
if (namedsection.id == firstChildSection.id) {
212215
namedsection.removeAttribute('id');
213216
}
@@ -318,7 +321,7 @@ const Plugin = () => {
318321
let match = section.dataset[vars.matchString];
319322

320323
let name = section.dataset.name || section.getAttribute(`name`) || section.id;
321-
let id = section.id || name.toLowerCase().replace(/\W/g, '');
324+
let id = section.id || name.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
322325

323326
idArray.push(id);
324327

@@ -361,7 +364,7 @@ const Plugin = () => {
361364
let linkhref = linker.getAttribute('href');
362365

363366
if (linkhref === "#") {
364-
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\W/g, '');
367+
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
365368
linker.href = `#/${newLink}`;
366369
}
367370
})
@@ -545,11 +548,11 @@ const Plugin = () => {
545548
deck.configure({ hash: true });
546549

547550
vars.deck = deck;
548-
vars.viewport = (deck.getRevealElement()).tagName == "BODY" ? document : deck.getRevealElement();
551+
vars.viewport = (deck.getRevealElement()).tagName === "BODY" ? document : deck.getRevealElement();
549552
vars.slides = deck.getSlidesElement();
550553
vars.langattribute = deck.getConfig().internation ? deck.getConfig().internation.langattribute ? deck.getConfig().internation.langattribute : "data-i18n" : false;
551554
vars.rtl = deck.getConfig().rtl;
552-
vars.quarto = (document.querySelector('[name=generator]') && (document.querySelector('[name=generator]')).content.includes("quarto")) ? true : false;
555+
vars.quarto = !!(document.querySelector('[name=generator]') && (document.querySelector('[name=generator]')).content.includes("quarto"));
553556
vars.matchString = "sm";
554557
vars.userScale = options.scale;
555558

plugin/simplemenu/simplemenu.esm.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* https://github.com/Martinomagnifico
55
*
66
* Simplemenu.js for Reveal.js
7-
* Version 2.0.2
7+
* Version 2.0.3
88
*
99
* @license
1010
* MIT licensed
@@ -74,7 +74,7 @@ const Plugin = () => {
7474
const isStack = section => {
7575
let isStack = false;
7676
for (let i = 0; i < section.childNodes.length; i++) {
77-
if (section.childNodes[i].tagName == "SECTION") {
77+
if (section.childNodes[i].tagName === "SECTION") {
7878
isStack = true;
7979
break;
8080
}
@@ -164,9 +164,10 @@ const Plugin = () => {
164164
});
165165
};
166166
function copyDataAttributes(source, target) {
167-
[...source.attributes].filter(attr => attr.nodeName.indexOf('data') > -1).forEach(attr => {
167+
const filteredAttrs = [...source.attributes].filter(attr => attr.nodeName.indexOf('data') > -1);
168+
for (const attr of filteredAttrs) {
168169
target.setAttribute(attr.nodeName, attr.nodeValue);
169-
});
170+
}
170171
}
171172
const prepareSlides = () => {
172173
debugLog("Preparing slides");
@@ -205,14 +206,14 @@ const Plugin = () => {
205206
// If the (named) section is not a stack and does not have an ID, we need to give it one.
206207
if (!isStack(namedsection) && !namedsection.id) {
207208
// Note: Quarto will already have assigned an ID, but it may also have been done manually.
208-
namedsection.id = match.toLowerCase().replace(/\W/g, '');
209+
namedsection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
209210
} else if (isStack(namedsection)) {
210211
// Find the first (visible) section inside a stack.
211212
let allsects = selectionArray(namedsection, `section`);
212213
let allVisibleSects = allsects.filter(section => section.dataset.visibility != "hidden");
213214
let firstChildSection = allVisibleSects[0];
214215
if (firstChildSection && !firstChildSection.id) {
215-
firstChildSection.id = match.toLowerCase().replace(/\W/g, '');
216+
firstChildSection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
216217
if (namedsection.id == firstChildSection.id) {
217218
namedsection.removeAttribute('id');
218219
}
@@ -325,7 +326,7 @@ const Plugin = () => {
325326
const autoMenuLinks = sections.namedvisible.map(section => {
326327
let match = section.dataset[vars.matchString];
327328
let name = section.dataset.name || section.getAttribute(`name`) || section.id;
328-
let id = section.id || name.toLowerCase().replace(/\W/g, '');
329+
let id = section.id || name.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
329330
idArray.push(id);
330331
if (vars.quarto) {
331332
id = mainArray.find(item => item.match === match).id;
@@ -355,7 +356,7 @@ const Plugin = () => {
355356
let linker = listItem.tagName == "a" ? listItem : listItem.querySelector('a');
356357
let linkhref = linker.getAttribute('href');
357358
if (linkhref === "#") {
358-
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\W/g, '');
359+
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
359360
linker.href = `#/${newLink}`;
360361
}
361362
});
@@ -502,11 +503,11 @@ const Plugin = () => {
502503
hash: true
503504
});
504505
vars.deck = deck;
505-
vars.viewport = deck.getRevealElement().tagName == "BODY" ? document : deck.getRevealElement();
506+
vars.viewport = deck.getRevealElement().tagName === "BODY" ? document : deck.getRevealElement();
506507
vars.slides = deck.getSlidesElement();
507508
vars.langattribute = deck.getConfig().internation ? deck.getConfig().internation.langattribute ? deck.getConfig().internation.langattribute : "data-i18n" : false;
508509
vars.rtl = deck.getConfig().rtl;
509-
vars.quarto = document.querySelector('[name=generator]') && document.querySelector('[name=generator]').content.includes("quarto") ? true : false;
510+
vars.quarto = !!(document.querySelector('[name=generator]') && document.querySelector('[name=generator]').content.includes("quarto"));
510511
vars.matchString = "sm";
511512
vars.userScale = options.scale;
512513
deck.addEventListener('ready', chapterize, false);

plugin/simplemenu/simplemenu.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* https://github.com/Martinomagnifico
55
*
66
* Simplemenu.js for Reveal.js
7-
* Version 2.0.2
7+
* Version 2.0.3
88
*
99
* @license
1010
* MIT licensed
@@ -80,7 +80,7 @@
8080
const isStack = section => {
8181
let isStack = false;
8282
for (let i = 0; i < section.childNodes.length; i++) {
83-
if (section.childNodes[i].tagName == "SECTION") {
83+
if (section.childNodes[i].tagName === "SECTION") {
8484
isStack = true;
8585
break;
8686
}
@@ -170,9 +170,10 @@
170170
});
171171
};
172172
function copyDataAttributes(source, target) {
173-
[...source.attributes].filter(attr => attr.nodeName.indexOf('data') > -1).forEach(attr => {
173+
const filteredAttrs = [...source.attributes].filter(attr => attr.nodeName.indexOf('data') > -1);
174+
for (const attr of filteredAttrs) {
174175
target.setAttribute(attr.nodeName, attr.nodeValue);
175-
});
176+
}
176177
}
177178
const prepareSlides = () => {
178179
debugLog("Preparing slides");
@@ -211,14 +212,14 @@
211212
// If the (named) section is not a stack and does not have an ID, we need to give it one.
212213
if (!isStack(namedsection) && !namedsection.id) {
213214
// Note: Quarto will already have assigned an ID, but it may also have been done manually.
214-
namedsection.id = match.toLowerCase().replace(/\W/g, '');
215+
namedsection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
215216
} else if (isStack(namedsection)) {
216217
// Find the first (visible) section inside a stack.
217218
let allsects = selectionArray(namedsection, `section`);
218219
let allVisibleSects = allsects.filter(section => section.dataset.visibility != "hidden");
219220
let firstChildSection = allVisibleSects[0];
220221
if (firstChildSection && !firstChildSection.id) {
221-
firstChildSection.id = match.toLowerCase().replace(/\W/g, '');
222+
firstChildSection.id = match.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
222223
if (namedsection.id == firstChildSection.id) {
223224
namedsection.removeAttribute('id');
224225
}
@@ -331,7 +332,7 @@
331332
const autoMenuLinks = sections.namedvisible.map(section => {
332333
let match = section.dataset[vars.matchString];
333334
let name = section.dataset.name || section.getAttribute(`name`) || section.id;
334-
let id = section.id || name.toLowerCase().replace(/\W/g, '');
335+
let id = section.id || name.toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
335336
idArray.push(id);
336337
if (vars.quarto) {
337338
id = mainArray.find(item => item.match === match).id;
@@ -361,7 +362,7 @@
361362
let linker = listItem.tagName == "a" ? listItem : listItem.querySelector('a');
362363
let linkhref = linker.getAttribute('href');
363364
if (linkhref === "#") {
364-
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\W/g, '');
365+
let newLink = listItem.dataset[vars.matchString].toLowerCase().replace(/\s+/g, '').replace(/[^\p{L}\p{N}-]/gu, '');
365366
linker.href = `#/${newLink}`;
366367
}
367368
});
@@ -508,11 +509,11 @@
508509
hash: true
509510
});
510511
vars.deck = deck;
511-
vars.viewport = deck.getRevealElement().tagName == "BODY" ? document : deck.getRevealElement();
512+
vars.viewport = deck.getRevealElement().tagName === "BODY" ? document : deck.getRevealElement();
512513
vars.slides = deck.getSlidesElement();
513514
vars.langattribute = deck.getConfig().internation ? deck.getConfig().internation.langattribute ? deck.getConfig().internation.langattribute : "data-i18n" : false;
514515
vars.rtl = deck.getConfig().rtl;
515-
vars.quarto = document.querySelector('[name=generator]') && document.querySelector('[name=generator]').content.includes("quarto") ? true : false;
516+
vars.quarto = !!(document.querySelector('[name=generator]') && document.querySelector('[name=generator]').content.includes("quarto"));
516517
vars.matchString = "sm";
517518
vars.userScale = options.scale;
518519
deck.addEventListener('ready', chapterize, false);

0 commit comments

Comments
 (0)