Skip to content

Commit

Permalink
add slide separator in case no separator is provided and heading indi…
Browse files Browse the repository at this point in the history
…cates the new slide
  • Loading branch information
PrajwolAmatya committed Jul 5, 2024
1 parent f895ea5 commit 8a62791
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin/awesoMD/awesoMD.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin/awesoMD/awesoMD.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions plugin/awesoMD/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const Plugin = () => {
options.separator = options.separator || markdownConfig?.separator || DEFAULT_SLIDE_SEPARATOR;
options.verticalSeparator = options.verticalSeparator || markdownConfig?.verticalSeparator || DEFAULT_VERTICAL_SEPARATOR;
options.notesSeparator = options.notesSeparator || markdownConfig?.notesSeparator || DEFAULT_NOTES_SEPARATOR;
options.separateByHeading = options.separateByHeading || markdownConfig?.separateByHeading || false;
options.attributes = options.attributes || '';

return options;
Expand Down Expand Up @@ -144,6 +145,11 @@ const Plugin = () => {

options = getSlidifyOptions( options );

// add slide separator in the case heading indicates the new slide
if (options.separateByHeading) {
markdown = addSlideSeparator(markdown);
}

const separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
horizontalSeparatorRegex = new RegExp( options.separator );

Expand Down Expand Up @@ -239,6 +245,7 @@ const Plugin = () => {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-separator-vertical' ),
notesSeparator: section.getAttribute( 'data-separator-notes' ),
separateByHeading: section.hasAttribute('data-separator-by-heading'),
attributes: getForwardedAttributes( section )
});
},
Expand All @@ -261,6 +268,7 @@ const Plugin = () => {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-separator-vertical' ),
notesSeparator: section.getAttribute( 'data-separator-notes' ),
separateByHeading: section.hasAttribute('data-separator-by-heading'),
attributes: getForwardedAttributes( section )
});

Expand Down Expand Up @@ -454,6 +462,34 @@ const Plugin = () => {
return [content, options];
}

/**
* Add slide separator in case where the heading indicates the start of new slide
*
* Returns the updated markdown file with added slide separator above every slide headings
*/
function addSlideSeparator(markdown) {
const defaultSlideSeparator = '---';
const lines = markdown.split('\n');
const result = [];
let isFirstHeading = false;

lines.forEach((line, index) => {
if (line.match(/^#+\s/)) {
if (!isFirstHeading) {
isFirstHeading = true;
} else {
const previousLine = lines[index - 1] || '';
if (previousLine !== defaultSlideSeparator) {
result.push(defaultSlideSeparator);
}
}
}
result.push(line);
})
markdown = result.join('\n');
return markdown;
}

/**
* Separates the inline metadata and content for each slide
*
Expand Down

0 comments on commit 8a62791

Please sign in to comment.