Skip to content

Commit

Permalink
[rebber-plugins] Fix footnotes (related to zestedesavoir#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
StaloneLab committed Mar 27, 2022
1 parent 226e39e commit 629ca4c
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 398 deletions.
118 changes: 59 additions & 59 deletions packages/rebber-plugins/__tests__/__snapshots__/rebber.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -308,189 +308,189 @@ Mathilde & 35 \\\\\\\\ \\\\hline
`;
exports[`footnotes 1`] = `
"\\\\part{International Radiotelephony Spelling Alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wiki}}}
"\\\\part{International Radiotelephony Spelling Alphabet\\\\textsuperscript{\\\\footnotemark[wiki]}}
Here's the NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wiki}}: Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliet, Kilo, Lima, Mike, November, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Uniform, Victor\\\\textsuperscript{\\\\footnotemark{footnote:name}}\\\\textsuperscript{\\\\footnotemark{footnote:consecutive}}, Whiskey, X-ray, Yankee, and Zulu.
Here's the NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark[wiki]}: Alfa, Bravo, Charlie, Delta, Echo, Foxtrot, Golf, Hotel, India, Juliet, Kilo, Lima, Mike, November, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Uniform, Victor\\\\textsuperscript{\\\\footnotemark[name]}\\\\textsuperscript{\\\\footnotemark[consecutive]}, Whiskey, X-ray, Yankee, and Zulu.
And here's some more text.
\\\\footnotetext[wiki]{\\\\footnotemark{footnote:wiki} Read more about it here.}
\\\\footnotetext[wiki]{Read more about it here.}
\\\\footnotetext[wiki]{\\\\footnotemark{footnote:wiki} And here.}
\\\\footnotetext[wiki]{And here.}
\\\\footnotetext[wiki2]{\\\\footnotemark{footnote:wiki2} Here's another good article on the subject.}
\\\\footnotetext[wiki2]{Here's another good article on the subject.}
\\\\footnotetext[name]{\\\\footnotemark{footnote:name} A great first name.}
\\\\footnotetext[name]{A great first name.}
\\\\footnotetext[consecutive]{\\\\footnotemark{footnote:consecutive} I know.}
\\\\footnotetext[consecutive]{I know.}
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wi\\\\-ki}}.
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark[wi\\\\-ki]}.
\\\\footnotetext[wi\\\\-ki]{\\\\footnotemark{footnote:wi\\\\-ki} Read more about it somewhere else.}
\\\\footnotetext[wi\\\\-ki]{Read more about it somewhere else.}
This example checks that \\\\footnote[l17c26o614]{\\\\footnotemark{footnote:l17c26o614} the generated} IDs do not overwrite the user's IDs\\\\textsuperscript{\\\\footnotemark{footnote:1}}.
This example checks that \\\\footnote[l17c26o614]{the generated} IDs do not overwrite the user's IDs\\\\textsuperscript{\\\\footnotemark[1]}.
\\\\footnotetext[1]{\\\\footnotemark{footnote:1} Old behavior would, for \\"generated\\", generate a footnote with an ID set to \\\\texttt{1}, thus overwriting this footnote.}
\\\\footnotetext[1]{Old behavior would, for \\"generated\\", generate a footnote with an ID set to \\\\texttt{1}, thus overwriting this footnote.}
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wiki3}}.
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark[wiki3]}.
\\\\footnotetext[wiki3]{\\\\footnotemark{footnote:wiki3} Read more about it somewhere else.}
\\\\footnotetext[wiki3]{Read more about it somewhere else.}
This is an example of an inline footnote.\\\\footnote[l25c42o918]{\\\\footnotemark{footnote:l25c42o918} This is the \\\\textit{actual} footnote.}
This is an example of an inline footnote.\\\\footnote[l25c42o918]{This is the \\\\textit{actual} footnote.}
This one isn't even [defined].
\\\\textsuperscript{\\\\footnotemark{footnote:both}}[invalid], \\\\footnote[l29c19o1015]{\\\\footnotemark{footnote:l29c19o1015} this too}[].
\\\\textsuperscript{\\\\footnotemark[both]}[invalid], \\\\footnote[l29c19o1015]{this too}[].
\\\\begin{enumerate}
\\\\item\\\\relax \\\\hyperref[bar]{foo}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}\\\\hyperref[bar]{bar}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark[foo]}\\\\hyperref[bar]{bar}
\\\\item\\\\relax [foo]
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}\\\\textsuperscript{\\\\footnotemark{footnote:bar}}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark[foo]}\\\\textsuperscript{\\\\footnotemark[bar]}
\\\\end{enumerate}
A footnote\\\\textsuperscript{\\\\footnotemark{footnote:2}}.
A footnote\\\\textsuperscript{\\\\footnotemark[2]}.
\\\\footnotetext[2]{\\\\footnotemark{footnote:2} Including \\\\footnote[l38c17o1125]{\\\\footnotemark{footnote:l38c17o1125} another \\\\textbf{footnote}}}
\\\\footnotetext[2]{Including \\\\footnote[l38c17o1125]{another \\\\textbf{footnote}}}
A footnote\\\\textsuperscript{\\\\footnotemark{footnote:tostring}} and \\\\textsuperscript{\\\\footnotemark{footnote:__proto__}} and \\\\textsuperscript{\\\\footnotemark{footnote:constructor}}.
A footnote\\\\textsuperscript{\\\\footnotemark[tostring]} and \\\\textsuperscript{\\\\footnotemark[__proto__]} and \\\\textsuperscript{\\\\footnotemark[constructor]}.
\\\\footnotetext[tostring]{\\\\footnotemark{footnote:tostring} See \\\\texttt{Object.prototype.toString()}.}
\\\\footnotetext[tostring]{See \\\\texttt{Object.prototype.toString()}.}
\\\\footnotetext[constructor]{\\\\footnotemark{footnote:constructor} See \\\\texttt{Object.prototype.valueOf()}.}
\\\\footnotetext[constructor]{See \\\\texttt{Object.prototype.valueOf()}.}
\\\\footnotetext[__proto__]{\\\\footnotemark{footnote:__proto__} See \\\\texttt{Object.prototype.\\\\_\\\\_proto\\\\_\\\\_()}.}
\\\\footnotetext[__proto__]{See \\\\texttt{Object.prototype.\\\\_\\\\_proto\\\\_\\\\_()}.}
foo\\\\textsuperscript{\\\\footnotemark{footnote:abc}} bar. foo\\\\textsuperscript{\\\\footnotemark{footnote:xyz}} bar
foo\\\\textsuperscript{\\\\footnotemark[abc]} bar. foo\\\\textsuperscript{\\\\footnotemark[xyz]} bar
\\\\footnotetext[abc]{\\\\footnotemark{footnote:abc} Baz baz}
\\\\footnotetext[abc]{Baz baz}
\\\\footnotetext[xyz]{\\\\footnotemark{footnote:xyz} Baz}
\\\\footnotetext[xyz]{Baz}
Lorem ipsum dolor sit amet\\\\textsuperscript{\\\\footnotemark{footnote:3}}.
Lorem ipsum dolor sit amet\\\\textsuperscript{\\\\footnotemark[3]}.
Nulla finibus\\\\textsuperscript{\\\\footnotemark{footnote:4}} neque et diam rhoncus convallis.
Nulla finibus\\\\textsuperscript{\\\\footnotemark[4]} neque et diam rhoncus convallis.
\\\\footnotetext[3]{\\\\footnotemark{footnote:3} Consectetur \\\\textbf{adipiscing} elit. Praesent dictum purus ullamcorper ligula semper pellentesque\\\\textsuperscript{\\\\footnotemark{footnote:3}}.
\\\\footnotetext[3]{Consectetur \\\\textbf{adipiscing} elit. Praesent dictum purus ullamcorper ligula semper pellentesque\\\\textsuperscript{\\\\footnotemark[3]}.
\\\\begin{itemize}
\\\\item\\\\relax Containing a list.
\\\\end{itemize}}
\\\\footnotetext[4]{\\\\footnotemark{footnote:4} Nam dictum sapien nec sem ultrices fermentum. Nulla \\\\textbf{facilisi}. In et feugiat massa.}
\\\\footnotetext[4]{Nam dictum sapien nec sem ultrices fermentum. Nulla \\\\textbf{facilisi}. In et feugiat massa.}
\\\\footnotetext[5]{\\\\footnotemark{footnote:5} Nunc dapibus ipsum ut mi \\\\textit{ultrices}, non euismod velit pretium.}
\\\\footnotetext[5]{Nunc dapibus ipsum ut mi \\\\textit{ultrices}, non euismod velit pretium.}
Here is some text containing a footnote\\\\textsuperscript{\\\\footnotemark{footnote:somesamplefootnote}}. You can then continue your thought...
Here is some text containing a footnote\\\\textsuperscript{\\\\footnotemark[somesamplefootnote]}. You can then continue your thought...
\\\\footnotetext[somesamplefootnote]{\\\\footnotemark{footnote:somesamplefootnote} Here is the text of the footnote itself.}
\\\\footnotetext[somesamplefootnote]{Here is the text of the footnote itself.}
Even go to a new \\\\hyperref[paragraph]{paragraph} and the footnotes will go to the bottom of the document\\\\textsuperscript{\\\\footnotemark{footnote:documentdetails}}.
Even go to a new \\\\hyperref[paragraph]{paragraph} and the footnotes will go to the bottom of the document\\\\textsuperscript{\\\\footnotemark[documentdetails]}.
\\\\footnotetext[documentdetails]{\\\\footnotemark{footnote:documentdetails} Depending on the \\\\textbf{final} form of your document, of course. See the documentation and experiment.
\\\\footnotetext[documentdetails]{Depending on the \\\\textbf{final} form of your document, of course. See the documentation and experiment.
This footnote has a second \\\\hyperref[paragraph]{paragraph}.}
\\\\footnote{\\\\label{paragraph}\\\\externalLink{http://example.com}{http://example.com}}
\\\\part{my heading\\\\footnote[l76c13o2284]{\\\\footnotemark{footnote:l76c13o2284} ref def}\\\\protect}
\\\\part{my heading\\\\protect\\\\footnote[l76c13o2284]{ref def}}
or
\\\\part{my heading\\\\textsuperscript{\\\\footnotemark{footnote:ref}}}
\\\\part{my heading\\\\textsuperscript{\\\\footnotemark[ref]}}
\\\\footnotetext[ref]{\\\\footnotemark{footnote:ref} def}
\\\\footnotetext[ref]{def}
First\\\\footnote[l84c6o2338]{\\\\footnotemark{footnote:l84c6o2338} the generated} and then a manual numbered def\\\\textsuperscript{\\\\footnotemark{footnote:def}}.
First\\\\footnote[l84c6o2338]{the generated} and then a manual numbered def\\\\textsuperscript{\\\\footnotemark[def]}.
\\\\footnotetext[def]{\\\\footnotemark{footnote:def} hello}
\\\\footnotetext[def]{hello}
\\\\begin{itemize}
\\\\item\\\\relax one\\\\footnote[l89c6o2415]{\\\\footnotemark{footnote:l89c6o2415} the first}
\\\\item\\\\relax two\\\\textsuperscript{\\\\footnotemark{footnote:2nd}}
\\\\item\\\\relax three\\\\textsuperscript{\\\\footnotemark{footnote:3rd}}
\\\\item\\\\relax four\\\\footnote[l92c7o2460]{\\\\footnotemark{footnote:l92c7o2460} the last}
\\\\item\\\\relax one\\\\footnote[l89c6o2415]{the first}
\\\\item\\\\relax two\\\\textsuperscript{\\\\footnotemark[2nd]}
\\\\item\\\\relax three\\\\textsuperscript{\\\\footnotemark[3rd]}
\\\\item\\\\relax four\\\\footnote[l92c7o2460]{the last}
\\\\end{itemize}
\\\\footnotetext[2nd]{\\\\footnotemark{footnote:2nd} second}
\\\\footnotetext[2nd]{second}
\\\\footnotetext[3rd]{\\\\footnotemark{footnote:3rd} third}
\\\\footnotetext[3rd]{third}
This nested footnote would not work:
\\\\hyperref[baz]{\\\\textsuperscript{\\\\footnotemark{footnote:foo2}}}
\\\\hyperref[baz]{\\\\textsuperscript{\\\\footnotemark[foo2]}}
\\\\footnote{\\\\label{bar}\\\\externalLink{https://bar.com}{https://bar.com}}
\\\\footnote{\\\\label{baz}\\\\externalLink{https://baz.com}{https://baz.com}}
\\\\footnotetext[foo2]{\\\\footnotemark{footnote:foo2} A footnote.}
\\\\footnotetext[foo2]{A footnote.}
\\\\chapter{New list continuation}
\\\\begin{enumerate}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark[foo]}
\\\\end{enumerate}
\\\\footnotetext[foo]{\\\\footnotemark{footnote:foo} bar baz.}
\\\\footnotetext[foo]{bar baz.}
\\\\part{mytitle A\\\\textsuperscript{\\\\footnotemark{footnote:footnoteref}}}
\\\\part{mytitle A\\\\textsuperscript{\\\\footnotemark[footnoteref]}}
\\\\footnotetext[footnoteref]{\\\\footnotemark{footnote:footnoteref} reference in title}
\\\\footnotetext[footnoteref]{reference in title}
\\\\part{mytitle B\\\\footnote[l117c12o2768]{\\\\footnotemark{footnote:l117c12o2768} footnoterawhead inner}\\\\protect}
\\\\part{mytitle B\\\\protect\\\\footnote[l117c12o2768]{footnoterawhead inner}}
\\\\part{myti\\\\textit{tle C\\\\footnote[l119c13o2806]{\\\\footnotemark{footnote:l119c13o2806} foo inner}\\\\protect}}
\\\\part{myti\\\\textit{tle C\\\\protect\\\\footnote[l119c13o2806]{foo inner}}}
a paragraph\\\\footnote[l121c12o2832]{\\\\footnotemark{footnote:l121c12o2832} footnoteRawPar inner}
a paragraph\\\\footnote[l121c12o2832]{footnoteRawPar inner}
"
`;
Expand Down Expand Up @@ -1019,11 +1019,11 @@ Sub & Headings & \\\\abbr{ABBR}{abbreviation} \\\\\\\\ \\\\hline
& normal & cell \\\\\\\\ \\\\hline
multi \\\\endgraf line \\\\endgraf \\\\endgraf cells \\\\endgraf too & \\\\multicolumn{2}{|m{\\\\dimexpr(\\\\linewidth) * 2 / 3 - 2 * \\\\tabcolsep}|}{\\\\parbox{\\\\linewidth}{cells can be \\\\endgraf \\\\textit{formatted} \\\\endgraf \\\\textbf{paragraphs}}} \\\\\\\\ \\\\hline
\\\\end{longtabu}
\\\\captionof{table}{The new table \\\\abbr{ABBR}{abbreviation} \\\\textsuperscript{\\\\footnotemark{footnote:foot}} with \\\\keys{CTRL} + \\\\keys{S}}
\\\\captionof{table}{The new table \\\\abbr{ABBR}{abbreviation} \\\\textsuperscript{\\\\footnotemark[foot]} with \\\\keys{CTRL} + \\\\keys{S}}
\\\\footnotetext[foot]{\\\\footnotemark{footnote:foot} a foot}
\\\\footnotetext[foot]{a foot}
\\\\begin{longtabu}{|m{\\\\dimexpr(\\\\linewidth) / 2 - 2 * \\\\tabcolsep}|m{\\\\dimexpr(\\\\linewidth) / 2 - 2 * \\\\tabcolsep}|} \\\\hline
\\\\rowfont[c]{\\\\bfseries}
Expand Down Expand Up @@ -1165,10 +1165,10 @@ print('bla')
`;
exports[`mix-5 1`] = `
"\\\\image{http://www.numerama.com/content/uploads/2016/07/espace.jpg}[espace\\\\textsuperscript{\\\\footnotemark{footnote:node}}]
"\\\\image{http://www.numerama.com/content/uploads/2016/07/espace.jpg}[espace\\\\textsuperscript{\\\\footnotemark[node]}]
\\\\footnotetext[node]{\\\\footnotemark{footnote:node} Two things are infinite: the universe and human stupidity.}"
\\\\footnotetext[node]{Two things are infinite: the universe and human stupidity.}"
`;
exports[`mix-6 1`] = `
Expand Down
9 changes: 2 additions & 7 deletions packages/rebber-plugins/dist/type/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ var all = require('rebber/dist/all');
module.exports = notes;

var defaultMacro = function defaultMacro(identifier, text, protect) {
var footnote = "\\footnote[".concat(identifier, "]{\\footnotemark{footnote:").concat(identifier, "} ").concat(text, "}");

if (protect) {
return "".concat(footnote, "\\protect");
}

var footnote = "".concat(protect ? '\\protect' : '', "\\footnote[").concat(identifier, "]{").concat(text, "}");
return footnote;
};

Expand All @@ -29,7 +24,7 @@ function autoId(node) {

function notes(ctx, node) {
var macro = ctx.footnote || defaultMacro;
var protect = !!node.inHeading;
var protect = Boolean(node.inHeading);
var identifier = autoId(node);
return macro(identifier, all(ctx, node).trim(), protect);
}
2 changes: 1 addition & 1 deletion packages/rebber-plugins/dist/type/footnoteDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = notes;

var defaultMacro = function defaultMacro(identifier, text, protect) {
return (// eslint-disable-next-line max-len
"".concat(protect ? '\\protect' : '', "\\footnotetext[").concat(identifier, "]{\\footnotemark{footnote:").concat(identifier, "} ").concat(text, "}")
"".concat(protect ? '\\protect' : '', "\\footnotetext[").concat(identifier, "]{").concat(text, "}")
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/rebber-plugins/dist/type/footnoteReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = notes;

var defaultMacro = function defaultMacro(identifier) {
return "\\textsuperscript{\\footnotemark{footnote:".concat(identifier, "}}");
return "\\textsuperscript{\\footnotemark[".concat(identifier, "]}");
};

function notes(ctx, node) {
Expand Down
8 changes: 3 additions & 5 deletions packages/rebber-plugins/src/type/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ const all = require('rebber/dist/all')
module.exports = notes

const defaultMacro = (identifier, text, protect) => {
const footnote = `\\footnote[${identifier}]{\\footnotemark{footnote:${identifier}} ${text}}`
if (protect) {
return `${footnote}\\protect`
}
const footnote = `${protect ? '\\protect' : ''}\\footnote[${identifier}]{${text}}`

return footnote
}

Expand All @@ -20,7 +18,7 @@ function autoId (node) {
/* Stringify a footnote `node`. */
function notes (ctx, node) {
const macro = ctx.footnote || defaultMacro
const protect = !!node.inHeading
const protect = Boolean(node.inHeading)

const identifier = autoId(node)

Expand Down
2 changes: 1 addition & 1 deletion packages/rebber-plugins/src/type/footnoteDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = notes

const defaultMacro = (identifier, text, protect) =>
// eslint-disable-next-line max-len
`${protect ? '\\protect' : ''}\\footnotetext[${identifier}]{\\footnotemark{footnote:${identifier}} ${text}}`
`${protect ? '\\protect' : ''}\\footnotetext[${identifier}]{${text}}`

function notes (ctx, node) {
const macro = ctx.footnoteDefinition || defaultMacro
Expand Down
2 changes: 1 addition & 1 deletion packages/rebber-plugins/src/type/footnoteReference.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = notes

const defaultMacro = (identifier) => `\\textsuperscript{\\footnotemark{footnote:${identifier}}}`
const defaultMacro = identifier => `\\textsuperscript{\\footnotemark[${identifier}]}`

function notes (ctx, node) {
const macro = ctx.footnoteReference || defaultMacro
Expand Down
Loading

0 comments on commit 629ca4c

Please sign in to comment.