Skip to content

Commit

Permalink
bugfix: Footnotes not rendered properly in tables (MSzturc#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzturc committed Mar 25, 2022
1 parent 61015a2 commit 1bea9aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
66 changes: 33 additions & 33 deletions src/processors/footNoteProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ export class FootnoteProcessor {

private regex = /\[\^([^\]]*)]/gmi;

process(markdown: string, options: Options){
process(markdown: string, options: Options) {

let output = markdown;

markdown
.split(new RegExp(options.separator, 'gmi'))
.map((slidegroup, index) => {
return slidegroup
.split(new RegExp(options.verticalSeparator, 'gmi'))
.map((slide, index) => {
if (this.regex.test(slide)) {
const newSlide = this.transformFootNotes(slide);
output = output.replace(slide, newSlide);
return newSlide;
}
return slide;
})
.join(options.verticalSeparator);
})
.join(options.separator);
return output;
.split(new RegExp(options.separator, 'gmi'))
.map((slidegroup, index) => {
return slidegroup
.split(new RegExp(options.verticalSeparator, 'gmi'))
.map((slide, index) => {
if (this.regex.test(slide)) {
const newSlide = this.transformFootNotes(slide);
output = output.replace(slide, newSlide);
return newSlide;
}
return slide;
})
.join(options.verticalSeparator);
})
.join(options.separator);
return output;
}

transformFootNotes(markdown: string) {

let input = markdown;
let noteIdx = 1;

const footNotes = new Map();
let reResult : RegExpExecArray;

let reResult: RegExpExecArray;
while (reResult = this.regex.exec(input)) {

input = input
.split('\n')
.map((line, index) => {
Expand All @@ -48,36 +48,36 @@ export class FootnoteProcessor {
return "";
} else {
const split = line.split(reResult[0]);

let result = split[0].trim();
result += '<sup id="fnref:' + reResult[1] + '" role="doc-noteref">' + noteIdx + '</sup>';
result += '\n' + split[1].trim();
result += split[1].trim();

noteIdx = noteIdx + 1;

return result;

}
}
return line;
})
.join('\n');


}

let footNotesBlock = '';
footNotesBlock += '<div class="footnotes" role="doc-endnotes">\n';
footNotesBlock += '<ol>\n';

footNotes.forEach((value, key) => {
footNotesBlock += '<li id="fn:' + key + '" role="doc-endnote"><p>' + value + '&nbsp;</p></li>';
});


footNotesBlock += '</ol>\n';
footNotesBlock += '</div>\n';

return input + '\n' + footNotesBlock;
}

Expand Down
1 change: 0 additions & 1 deletion test/__snapshots__/basicSyntax.unit.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ exports[`Basic Markdown Syntax > Footnotes 1`] = `
<div class=\\"footnotes\\" role=\\"doc-endnotes\\">
<ol>
<li id=\\"fn:1\\" role=\\"doc-endnote\\"><p>meaningful!&nbsp;</p></li></ol>
Expand Down

0 comments on commit 1bea9aa

Please sign in to comment.