1
0
Fork 0

Support multiple aside notes elements per slide

So far, multiple notes per slide are only supported if they are
attached to fragments (without fragments, only the first aside notes
element on a slide is displayed).  With this commit, the contents of
all notes on a slide are displayed (except for fragments with notes,
for which, as before, only each fragment's first/single note is
displayed).
This commit is contained in:
Jens Lechtenbörger 2021-09-16 11:56:52 +02:00
parent 90bbe8be4f
commit f9ce61e34a
2 changed files with 25 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/** /**
* Handles the showing and * Handles the showing of speaker notes
*/ */
export default class Notes { export default class Notes {
@ -89,7 +89,7 @@ export default class Notes {
* Retrieves the speaker notes from a slide. Notes can be * Retrieves the speaker notes from a slide. Notes can be
* defined in two ways: * defined in two ways:
* 1. As a data-notes attribute on the slide <section> * 1. As a data-notes attribute on the slide <section>
* 2. As an <aside class="notes"> inside of the slide * 2. With <aside class="notes"> elements inside the slide
* *
* @param {HTMLElement} [slide=currentSlide] * @param {HTMLElement} [slide=currentSlide]
* @return {(string|null)} * @return {(string|null)}
@ -101,10 +101,14 @@ export default class Notes {
return slide.getAttribute( 'data-notes' ); return slide.getAttribute( 'data-notes' );
} }
// ... or using an <aside class="notes"> element // ... or using <aside class="notes"> elements
let notesElement = slide.querySelector( 'aside.notes' ); let notesElements = slide.querySelectorAll( 'aside.notes' );
if( notesElement ) { if( notesElements ) {
return notesElement.innerHTML; let notes = "";
for (let i = 0; i < notesElements.length; i++) {
notes += notesElements[i].innerHTML + "\n";
}
return notes;
} }
return null; return null;

View File

@ -86,7 +86,7 @@ const Plugin = () => {
function post( event ) { function post( event ) {
let slideElement = deck.getCurrentSlide(), let slideElement = deck.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' ), notesElements = slideElement.querySelectorAll( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' ); fragmentElement = slideElement.querySelector( '.current-fragment' );
let messageData = { let messageData = {
@ -108,21 +108,29 @@ const Plugin = () => {
if( fragmentElement ) { if( fragmentElement ) {
let fragmentNotes = fragmentElement.querySelector( 'aside.notes' ); let fragmentNotes = fragmentElement.querySelector( 'aside.notes' );
if( fragmentNotes ) { if( fragmentNotes ) {
notesElement = fragmentNotes; messageData.notes = fragmentNotes.innerHTML;
messageData.markdown = typeof fragmentNotes.getAttribute( 'data-markdown' ) === 'string';
// Ignore other slide notes
notesElements = null;
} }
else if( fragmentElement.hasAttribute( 'data-notes' ) ) { else if( fragmentElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = fragmentElement.getAttribute( 'data-notes' ); messageData.notes = fragmentElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap'; messageData.whitespace = 'pre-wrap';
// In case there are slide notes // In case there are slide notes
notesElement = null; notesElements = null;
} }
} }
// Look for notes defined in an aside element // Look for notes defined in aside elements
if( notesElement ) { if( notesElements ) {
messageData.notes = notesElement.innerHTML; let notes = "";
messageData.markdown = typeof notesElement.getAttribute( 'data-markdown' ) === 'string'; for (let i = 0; i < notesElements.length; i++) {
notes += notesElements[i].innerHTML + "\n";
}
messageData.notes = notes;
messageData.markdown = typeof notesElements[0].getAttribute( 'data-markdown' ) === 'string';
} }
popup.postMessage( JSON.stringify( messageData ), '*' ); popup.postMessage( JSON.stringify( messageData ), '*' );