Skip to content

Commit

Permalink
Fix issue #400 & label -> footnotemark
Browse files Browse the repository at this point in the history
  • Loading branch information
StaloneLab committed Aug 31, 2020
1 parent 04fdbd9 commit 7fb2b10
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 408 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 @@ -339,189 +339,189 @@ Mathilde & 35 \\\\\\\\ \\\\hline
`;

exports[`footnotes 1`] = `
"\\\\part{International Radiotelephony Spelling Alphabet\\\\textsuperscript{\\\\ref{footnote:wiki}}}
"\\\\part{International Radiotelephony Spelling Alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wiki}}}
Here's the NATO phonetic alphabet\\\\textsuperscript{\\\\ref{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{\\\\ref{footnote:name}}\\\\textsuperscript{\\\\ref{footnote:consecutive}}, Whiskey, X-ray, Yankee, and Zulu.
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.
And here's some more text.
\\\\footnotetext[wiki]{\\\\label{footnote:wiki} Read more about it here.}
\\\\footnotetext[wiki]{\\\\footnotemark{footnote:wiki} Read more about it here.}
\\\\footnotetext[wiki]{\\\\label{footnote:wiki} And here.}
\\\\footnotetext[wiki]{\\\\footnotemark{footnote:wiki} And here.}
\\\\footnotetext[wiki2]{\\\\label{footnote:wiki2} Here's another good article on the subject.}
\\\\footnotetext[wiki2]{\\\\footnotemark{footnote:wiki2} Here's another good article on the subject.}
\\\\footnotetext[name]{\\\\label{footnote:name} A great first name.}
\\\\footnotetext[name]{\\\\footnotemark{footnote:name} A great first name.}
\\\\footnotetext[consecutive]{\\\\label{footnote:consecutive} I know.}
\\\\footnotetext[consecutive]{\\\\footnotemark{footnote:consecutive} I know.}
The NATO phonetic alphabet\\\\textsuperscript{\\\\ref{footnote:wi\\\\-ki}}.
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wi\\\\-ki}}.
\\\\footnotetext[wi\\\\-ki]{\\\\label{footnote:wi\\\\-ki} Read more about it somewhere else.}
\\\\footnotetext[wi\\\\-ki]{\\\\footnotemark{footnote:wi\\\\-ki} Read more about it somewhere else.}
This example checks that \\\\footnote[l17c26o614]{\\\\label{footnote:l17c26o614} the generated} IDs do not overwrite the user's IDs\\\\textsuperscript{\\\\ref{footnote:1}}.
This example checks that \\\\footnote[l17c26o614]{\\\\footnotemark{footnote:l17c26o614} the generated} IDs do not overwrite the user's IDs\\\\textsuperscript{\\\\footnotemark{footnote:1}}.
\\\\footnotetext[1]{\\\\label{footnote:1} Old behavior would, for \\"generated\\", generate a footnote with an ID set to \\\\texttt{1}, thus overwriting this footnote.}
\\\\footnotetext[1]{\\\\footnotemark{footnote: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{\\\\ref{footnote:wiki3}}.
The NATO phonetic alphabet\\\\textsuperscript{\\\\footnotemark{footnote:wiki3}}.
\\\\footnotetext[wiki3]{\\\\label{footnote:wiki3} Read more about it somewhere else.}
\\\\footnotetext[wiki3]{\\\\footnotemark{footnote:wiki3} Read more about it somewhere else.}
This is an example of an inline footnote.\\\\footnote[l25c42o918]{\\\\label{footnote:l25c42o918} This is the \\\\textit{actual} footnote.}
This is an example of an inline footnote.\\\\footnote[l25c42o918]{\\\\footnotemark{footnote:l25c42o918} This is the \\\\textit{actual} footnote.}
This one isn't even [defined].
\\\\textsuperscript{\\\\ref{footnote:both}}[invalid], \\\\footnote[l29c19o1015]{\\\\label{footnote:l29c19o1015} this too}[].
\\\\textsuperscript{\\\\footnotemark{footnote:both}}[invalid], \\\\footnote[l29c19o1015]{\\\\footnotemark{footnote:l29c19o1015} this too}[].
\\\\begin{enumerate}
\\\\item\\\\relax \\\\hyperref[bar]{foo}
\\\\item\\\\relax \\\\textsuperscript{\\\\ref{footnote:foo}}\\\\hyperref[bar]{bar}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}\\\\hyperref[bar]{bar}
\\\\item\\\\relax [foo]
\\\\item\\\\relax \\\\textsuperscript{\\\\ref{footnote:foo}}\\\\textsuperscript{\\\\ref{footnote:bar}}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}\\\\textsuperscript{\\\\footnotemark{footnote:bar}}
\\\\end{enumerate}
A footnote\\\\textsuperscript{\\\\ref{footnote:2}}.
A footnote\\\\textsuperscript{\\\\footnotemark{footnote:2}}.
\\\\footnotetext[2]{\\\\label{footnote:2} Including \\\\footnote[l38c17o1125]{\\\\label{footnote:l38c17o1125} another \\\\textbf{footnote}}}
\\\\footnotetext[2]{\\\\footnotemark{footnote:2} Including \\\\footnote[l38c17o1125]{\\\\footnotemark{footnote:l38c17o1125} another \\\\textbf{footnote}}}
A footnote\\\\textsuperscript{\\\\ref{footnote:tostring}} and \\\\textsuperscript{\\\\ref{footnote:__proto__}} and \\\\textsuperscript{\\\\ref{footnote:constructor}}.
A footnote\\\\textsuperscript{\\\\footnotemark{footnote:tostring}} and \\\\textsuperscript{\\\\footnotemark{footnote:__proto__}} and \\\\textsuperscript{\\\\footnotemark{footnote:constructor}}.
\\\\footnotetext[tostring]{\\\\label{footnote:tostring} See \\\\texttt{Object.prototype.toString()}.}
\\\\footnotetext[tostring]{\\\\footnotemark{footnote:tostring} See \\\\texttt{Object.prototype.toString()}.}
\\\\footnotetext[constructor]{\\\\label{footnote:constructor} See \\\\texttt{Object.prototype.valueOf()}.}
\\\\footnotetext[constructor]{\\\\footnotemark{footnote:constructor} See \\\\texttt{Object.prototype.valueOf()}.}
\\\\footnotetext[__proto__]{\\\\label{footnote:__proto__} See \\\\texttt{Object.prototype.\\\\_\\\\_proto\\\\_\\\\_()}.}
\\\\footnotetext[__proto__]{\\\\footnotemark{footnote:__proto__} See \\\\texttt{Object.prototype.\\\\_\\\\_proto\\\\_\\\\_()}.}
foo\\\\textsuperscript{\\\\ref{footnote:abc}} bar. foo\\\\textsuperscript{\\\\ref{footnote:xyz}} bar
foo\\\\textsuperscript{\\\\footnotemark{footnote:abc}} bar. foo\\\\textsuperscript{\\\\footnotemark{footnote:xyz}} bar
\\\\footnotetext[abc]{\\\\label{footnote:abc} Baz baz}
\\\\footnotetext[abc]{\\\\footnotemark{footnote:abc} Baz baz}
\\\\footnotetext[xyz]{\\\\label{footnote:xyz} Baz}
\\\\footnotetext[xyz]{\\\\footnotemark{footnote:xyz} Baz}
Lorem ipsum dolor sit amet\\\\textsuperscript{\\\\ref{footnote:3}}.
Lorem ipsum dolor sit amet\\\\textsuperscript{\\\\footnotemark{footnote:3}}.
Nulla finibus\\\\textsuperscript{\\\\ref{footnote:4}} neque et diam rhoncus convallis.
Nulla finibus\\\\textsuperscript{\\\\footnotemark{footnote:4}} neque et diam rhoncus convallis.
\\\\footnotetext[3]{\\\\label{footnote:3} Consectetur \\\\textbf{adipiscing} elit. Praesent dictum purus ullamcorper ligula semper pellentesque\\\\textsuperscript{\\\\ref{footnote:3}}.
\\\\footnotetext[3]{\\\\footnotemark{footnote:3} Consectetur \\\\textbf{adipiscing} elit. Praesent dictum purus ullamcorper ligula semper pellentesque\\\\textsuperscript{\\\\footnotemark{footnote:3}}.
\\\\begin{itemize}
\\\\item\\\\relax Containing a list.
\\\\end{itemize}}
\\\\footnotetext[4]{\\\\label{footnote:4} Nam dictum sapien nec sem ultrices fermentum. Nulla \\\\textbf{facilisi}. In et feugiat massa.}
\\\\footnotetext[4]{\\\\footnotemark{footnote:4} Nam dictum sapien nec sem ultrices fermentum. Nulla \\\\textbf{facilisi}. In et feugiat massa.}
\\\\footnotetext[5]{\\\\label{footnote:5} Nunc dapibus ipsum ut mi \\\\textit{ultrices}, non euismod velit pretium.}
\\\\footnotetext[5]{\\\\footnotemark{footnote:5} Nunc dapibus ipsum ut mi \\\\textit{ultrices}, non euismod velit pretium.}
Here is some text containing a footnote\\\\textsuperscript{\\\\ref{footnote:somesamplefootnote}}. You can then continue your thought...
Here is some text containing a footnote\\\\textsuperscript{\\\\footnotemark{footnote:somesamplefootnote}}. You can then continue your thought...
\\\\footnotetext[somesamplefootnote]{\\\\label{footnote:somesamplefootnote} Here is the text of the footnote itself.}
\\\\footnotetext[somesamplefootnote]{\\\\footnotemark{footnote: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{\\\\ref{footnote:documentdetails}}.
Even go to a new \\\\hyperref[paragraph]{paragraph} and the footnotes will go to the bottom of the document\\\\textsuperscript{\\\\footnotemark{footnote:documentdetails}}.
\\\\footnotetext[documentdetails]{\\\\label{footnote:documentdetails} Depending on the \\\\textbf{final} form of your document, of course. See the documentation and experiment.
\\\\footnotetext[documentdetails]{\\\\footnotemark{footnote: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]{\\\\label{footnote:l76c13o2284} ref def}\\\\protect}
\\\\part{my heading\\\\footnote[l76c13o2284]{\\\\footnotemark{footnote:l76c13o2284} ref def}\\\\protect}
or
\\\\part{my heading\\\\textsuperscript{\\\\ref{footnote:ref}}}
\\\\part{my heading\\\\textsuperscript{\\\\footnotemark{footnote:ref}}}
\\\\footnotetext[ref]{\\\\label{footnote:ref} def}
\\\\footnotetext[ref]{\\\\footnotemark{footnote:ref} def}
First\\\\footnote[l84c6o2338]{\\\\label{footnote:l84c6o2338} the generated} and then a manual numbered def\\\\textsuperscript{\\\\ref{footnote:def}}.
First\\\\footnote[l84c6o2338]{\\\\footnotemark{footnote:l84c6o2338} the generated} and then a manual numbered def\\\\textsuperscript{\\\\footnotemark{footnote:def}}.
\\\\footnotetext[def]{\\\\label{footnote:def} hello}
\\\\footnotetext[def]{\\\\footnotemark{footnote:def} hello}
\\\\begin{itemize}
\\\\item\\\\relax one\\\\footnote[l89c6o2415]{\\\\label{footnote:l89c6o2415} the first}
\\\\item\\\\relax two\\\\textsuperscript{\\\\ref{footnote:2nd}}
\\\\item\\\\relax three\\\\textsuperscript{\\\\ref{footnote:3rd}}
\\\\item\\\\relax four\\\\footnote[l92c7o2460]{\\\\label{footnote:l92c7o2460} the last}
\\\\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}
\\\\end{itemize}
\\\\footnotetext[2nd]{\\\\label{footnote:2nd} second}
\\\\footnotetext[2nd]{\\\\footnotemark{footnote:2nd} second}
\\\\footnotetext[3rd]{\\\\label{footnote:3rd} third}
\\\\footnotetext[3rd]{\\\\footnotemark{footnote:3rd} third}
This nested footnote would not work:
\\\\hyperref[baz]{\\\\textsuperscript{\\\\ref{footnote:foo2}}}
\\\\hyperref[baz]{\\\\textsuperscript{\\\\footnotemark{footnote:foo2}}}
\\\\footnote{\\\\label{bar}\\\\externalLink{https://bar.com}{https://bar.com}}
\\\\footnote{\\\\label{baz}\\\\externalLink{https://baz.com}{https://baz.com}}
\\\\footnotetext[foo2]{\\\\label{footnote:foo2} A footnote.}
\\\\footnotetext[foo2]{\\\\footnotemark{footnote:foo2} A footnote.}
\\\\chapter{New list continuation}
\\\\begin{enumerate}
\\\\item\\\\relax \\\\textsuperscript{\\\\ref{footnote:foo}}
\\\\item\\\\relax \\\\textsuperscript{\\\\footnotemark{footnote:foo}}
\\\\end{enumerate}
\\\\footnotetext[foo]{\\\\label{footnote:foo} bar baz.}
\\\\footnotetext[foo]{\\\\footnotemark{footnote:foo} bar baz.}
\\\\part{mytitle A\\\\textsuperscript{\\\\ref{footnote:footnoteref}}}
\\\\part{mytitle A\\\\textsuperscript{\\\\footnotemark{footnote:footnoteref}}}
\\\\footnotetext[footnoteref]{\\\\label{footnote:footnoteref} reference in title}
\\\\footnotetext[footnoteref]{\\\\footnotemark{footnote:footnoteref} reference in title}
\\\\part{mytitle B\\\\footnote[l117c12o2768]{\\\\label{footnote:l117c12o2768} footnoterawhead inner}\\\\protect}
\\\\part{mytitle B\\\\footnote[l117c12o2768]{\\\\footnotemark{footnote:l117c12o2768} footnoterawhead inner}\\\\protect}
\\\\part{myti\\\\textit{tle C\\\\footnote[l119c13o2806]{\\\\label{footnote:l119c13o2806} foo inner}\\\\protect}}
\\\\part{myti\\\\textit{tle C\\\\footnote[l119c13o2806]{\\\\footnotemark{footnote:l119c13o2806} foo inner}\\\\protect}}
a paragraph\\\\footnote[l121c12o2832]{\\\\label{footnote:l121c12o2832} footnoteRawPar inner}
a paragraph\\\\footnote[l121c12o2832]{\\\\footnotemark{footnote:l121c12o2832} footnoteRawPar inner}
"
`;
Expand Down Expand Up @@ -1050,11 +1050,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}|}{\\\\parbox{\\\\linewidth}{cells can be \\\\endgraf \\\\textit{formatted} \\\\endgraf \\\\textbf{paragraphs}}} \\\\\\\\ \\\\hline
\\\\end{longtabu}
\\\\captionof{table}{The new table \\\\abbr{ABBR}{abbreviation} \\\\textsuperscript{\\\\ref{footnote:foot}} with \\\\keys{CTRL} + \\\\keys{S}}
\\\\captionof{table}{The new table \\\\abbr{ABBR}{abbreviation} \\\\textsuperscript{\\\\footnotemark{footnote:foot}} with \\\\keys{CTRL} + \\\\keys{S}}
\\\\footnotetext[foot]{\\\\label{footnote:foot} a foot}
\\\\footnotetext[foot]{\\\\footnotemark{footnote:foot} a foot}
\\\\begin{longtabu}{|m{\\\\dimexpr(\\\\linewidth) / 2}|m{\\\\dimexpr(\\\\linewidth) / 2}|} \\\\hline
\\\\rowfont[c]{\\\\bfseries}
Expand Down Expand Up @@ -1196,10 +1196,10 @@ print('bla')
`;
exports[`mix-5 1`] = `
"\\\\image{http://www.numerama.com/content/uploads/2016/07/espace.jpg}[espace\\\\textsuperscript{\\\\ref{footnote:node}}]
"\\\\image{http://www.numerama.com/content/uploads/2016/07/espace.jpg}[espace\\\\textsuperscript{\\\\footnotemark{footnote:node}}]
\\\\footnotetext[node]{\\\\label{footnote:node} Two things are infinite: the universe and human stupidity.}"
\\\\footnotetext[node]{\\\\footnotemark{footnote:node} Two things are infinite: the universe and human stupidity.}"
`;
exports[`mix-6 1`] = `
Expand Down
5 changes: 0 additions & 5 deletions packages/rebber-plugins/dist/preprocessors/expandFootnotes.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/rebber-plugins/dist/type/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var all = require('rebber/dist/all');
module.exports = notes;

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

if (protect) {
return "".concat(footnote, "\\protect");
Expand Down
14 changes: 5 additions & 9 deletions packages/rebber-plugins/dist/type/footnoteDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ var all = require('rebber/dist/all');
module.exports = notes;

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

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

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

function notes(ctx, node) {
var macro = ctx.footnoteDefinition || defaultMacro;
var protect = !!node.inHeading;
return macro(node.identifier, all(ctx, node, protect).trim());
var protect = Boolean(node.inHeading);
return macro(node.identifier, all(ctx, node).trim(), protect);
}
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{\\ref{footnote:".concat(identifier, "}}");
return "\\textsuperscript{\\footnotemark{footnote:".concat(identifier, "}}");
};

function notes(ctx, node) {
Expand Down
3 changes: 0 additions & 3 deletions packages/rebber-plugins/src/preprocessors/expandFootnotes.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/rebber-plugins/src/type/footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const all = require('rebber/dist/all')
module.exports = notes

const defaultMacro = (identifier, text, protect) => {
const footnote = `\\footnote[${identifier}]{\\label{footnote:${identifier}} ${text}}`
const footnote = `\\footnote[${identifier}]{\\footnotemark{footnote:${identifier}} ${text}}`
if (protect) {
return `${footnote}\\protect`
}
Expand Down
14 changes: 5 additions & 9 deletions packages/rebber-plugins/src/type/footnoteDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ const all = require('rebber/dist/all')
/* Expose. */
module.exports = notes

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

function notes (ctx, node) {
const macro = ctx.footnoteDefinition || defaultMacro
const protect = !!node.inHeading
const protect = Boolean(node.inHeading)

return macro(node.identifier, all(ctx, node, protect).trim())
return macro(node.identifier, all(ctx, node).trim(), protect)
}
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{\\ref{footnote:${identifier}}}`
const defaultMacro = (identifier) => `\\textsuperscript{\\footnotemark{footnote:${identifier}}}`

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

0 comments on commit 7fb2b10

Please sign in to comment.