@@ -16,8 +16,8 @@ import DOMPurify from "dompurify";
1616
1717const DEFAULT_SLIDE_SEPARATOR = "\r?\n---\r?\n" ,
1818 DEFAULT_NOTES_SEPARATOR = "notes?:" ,
19- DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = "\\\.element\\\s*? (.+?)$" ,
20- DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = "\\\.slide:\\\s*? (\\\S.+?)$" ;
19+ DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = "\\\s\\\ .element: \\\s*(.+?)$" ,
20+ DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = "\\\s\\\ .slide:\\\s*(\\\S.+?)$" ;
2121
2222const SCRIPT_END_PLACEHOLDER = "__SCRIPT_END__" ;
2323
@@ -63,7 +63,7 @@ const SANITIZE = (string) =>
6363 * http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development/7000899#answer-11786277
6464 */
6565function addAttributeInElement ( node , elementTarget , separator ) {
66- const attrsInNode = new RegExp ( separator , "mg " ) ;
66+ const attrsInNode = new RegExp ( separator , "gm " ) ;
6767 const attrsRegex = new RegExp (
6868 // attributes are limited to prevent code injection
6969 "(?:^|\s)(?<attr>class|style|data-[a-z-]+)=(?:\"(?<dval>[^\"]+?)\"|'(?<sval>[^']+?)')" ,
@@ -72,10 +72,8 @@ function addAttributeInElement(node, elementTarget, separator) {
7272 let matches ,
7373 matchesAttrs ;
7474 if ( ( matches = attrsInNode . exec ( node . nodeValue ) ) !== null ) {
75- const classes = matches [ 1 ] ;
76- node . nodeValue = node . nodeValue . substring ( 0 , matches . index ) +
77- node . nodeValue . substring ( attrsInNode . lastIndex ) ;
78- while ( ( matchesAttrs = attrsRegex . exec ( classes ) ) !== null ) {
75+ const attrs = matches [ 1 ] ;
76+ while ( ( matchesAttrs = attrsRegex . exec ( attrs ) ) !== null ) {
7977 elementTarget . setAttribute (
8078 matchesAttrs . groups . attr ,
8179 matchesAttrs . groups . dval || matchesAttrs . groups . sval || "" ,
@@ -87,8 +85,8 @@ function addAttributeInElement(node, elementTarget, separator) {
8785}
8886
8987/**
90- * Add attributes to the parent element of a text node,
91- * or the element of an attribute node .
88+ * Recursively add attributes to the parent element of a text node,
89+ * or the section element, depending on the selector .
9290 */
9391function addAttributes (
9492 section ,
@@ -97,10 +95,11 @@ function addAttributes(
9795 separatorElementAttributes ,
9896 separatorSectionAttributes ,
9997) {
100- if ( element ?. childNodes && element . childNodes . length > 0 ) {
98+ if ( element ?. childNodes ?. length ) {
10199 let previousParentElement = element ;
102100 for ( let i = 0 ; i < element . childNodes . length ; i ++ ) {
103101 const childElement = element . childNodes [ i ] ;
102+ // if an element has multiple children, search for the one that can receive the attributes
104103 if ( i > 0 ) {
105104 let j = i - 1 ;
106105 while ( j >= 0 ) {
@@ -135,16 +134,14 @@ function addAttributes(
135134 }
136135 }
137136 if ( element . nodeType == Node . COMMENT_NODE ) {
138- if (
137+ if ( previousElement !== section ) {
139138 addAttributeInElement (
140139 element ,
141140 previousElement ,
142141 separatorElementAttributes ,
143- ) ===
144- false
145- ) {
146- addAttributeInElement ( element , section , separatorSectionAttributes ) ;
142+ ) ;
147143 }
144+ addAttributeInElement ( element , section , separatorSectionAttributes ) ;
148145 }
149146}
150147
@@ -300,13 +297,15 @@ export function convertMarkdownToSlides(startElement, marked) {
300297 const markdown = getMarkdownFromSlide ( section ) ;
301298 // convert markdown to HTML
302299 section . innerHTML = SANITIZE ( await marked . parse ( markdown ) ) ;
300+ // set ID on section elements and remove it from headings so revealjs can navigate to the slides via URL fragments
303301 const firstChild = section . firstElementChild ;
304302 if ( firstChild && firstChild . id !== "" ) {
305303 section . id = firstChild . id ;
306304 firstChild . removeAttribute ( "id" ) ;
307305 } else {
308306 section . id = `${ sectionNumber } ` ;
309307 }
308+ // search for comment nodes and add the attributes to respective parent nodes
310309 addAttributes (
311310 section ,
312311 section ,
@@ -721,8 +720,6 @@ const Plugin = () => {
721720 "theme" : "white" ,
722721 "highlight-theme" : "monokai" ,
723722 "favicon" : "/favicon.svg" ,
724- "fontawesomePro" : false ,
725- "fontawesomeFree" : false ,
726723 // changed revealjs defaults
727724 "hash" : true ,
728725 } ;
@@ -809,14 +806,6 @@ const Plugin = () => {
809806 "topic" : addMeta ( "topic" ) ,
810807 "url" : ( url ) =>
811808 S . map ( ( fn ) => fn ( url ) ) ( [ addMeta ( "url" ) , addMeta ( "og:url" ) ] ) ,
812- "fontawesomePro" : loadScript (
813- "https://kit.fontawesome.com/fec85b2437.js" ,
814- "anonymous" ,
815- ) ,
816- "fontawesomeFree" : loadScript (
817- "https://kit.fontawesome.com/ce15cd202d.js" ,
818- "anonymous" ,
819- ) ,
820809 "_customcontrols" : ( ) => {
821810 // ignore the _customcontrols visibility setting
822811 } ,
@@ -865,12 +854,6 @@ const Plugin = () => {
865854 . map ( ( k ) => {
866855 mergedMetadata [ k ] = parseType ( _mergedMetadata [ k ] ) ;
867856 } ) ;
868- if ( mergedMetadata . fontawesomePro ) {
869- mergedMetadata . fontawesomeFree = false ;
870- }
871- if ( mergedMetadata . fontawesomeFree ) {
872- mergedMetadata . fontawesomePro = false ;
873- }
874857 if (
875858 // since revealjsConfig.controls is true by default, only decktape and
876859 // similar tools are able to override it .. so prefer whatever these tools
0 commit comments