From 1147983d6d045237037dceaa4fbceed62d9443f6 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 22 Aug 2021 10:35:40 +0200 Subject: [PATCH] resolves #309 add support for footnotes (#550) * resolves #511 upgrade to paged.js 0.2.0 * resolves #309 add support for footnotes --- css/document.css | 26 ++++++ lib/document/document-converter.js | 30 ++++--- package-lock.json | 123 +++++++++++++++-------------- package.json | 2 +- test/fixtures/footnotes.adoc | 13 +++ 5 files changed, 121 insertions(+), 73 deletions(-) create mode 100644 test/fixtures/footnotes.adoc diff --git a/css/document.css b/css/document.css index e6202d8d..1c4886a3 100644 --- a/css/document.css +++ b/css/document.css @@ -26,6 +26,7 @@ nested elements once that breaks across two pages. width: 100%; cursor: default; } + .admonitionblock > table td.icon .fa-layers { height: 100%; width: 100%; @@ -270,3 +271,28 @@ The leader works by filling the li with dots, and arranging for the and a::a #content { counter-reset: page 1; } + +/* footnotes */ +@page { + @footnote { + float: bottom; + /*border-top: solid black thin; + padding-top: 8pt;*/ + } +} + +span.footnote { + float: footnote; +} + +[data-footnote-call]::after { + content: "[" counter(footnote) "]"; +} + +.pagedjs_area a[data-footnote-call] { + cursor: pointer; +} + +[data-footnote-call]::after { + content: "[" counter(footnote) "]"; +} diff --git a/lib/document/document-converter.js b/lib/document/document-converter.js index 140f0c7a..8a23a479 100644 --- a/lib/document/document-converter.js +++ b/lib/document/document-converter.js @@ -106,7 +106,7 @@ ${this.docinfoContent(node, 'footer', '-pdf.html')} ` } - convert_outline(node, opts = {}) { + convert_outline (node, opts = {}) { if (!node.hasSections()) { return } @@ -125,7 +125,7 @@ ${this.docinfoContent(node, 'footer', '-pdf.html')} if (slevel < 2 && node.getDocument().getDoctype() === 'book') { if (section.getSectionName() === 'chapter') { const signifier = node.getDocument().getAttributes()['chapter-signifier'] - stitle = `${signifier ? `"${signifier} "` : ''}${section['$sectnum']()} ${section.getTitle()}` + stitle = `${signifier ? `"${signifier} "` : ''}${section['$sectnum']()} ${section.getTitle()}` } else if (section.getSectionName() === 'part') { const signifier = node.getDocument().getAttributes()['part-signifier'] stitle = `${signifier ? `"${signifier} "` : ''}${section['$sectnum'](Opal.nil, ':')} ${section.getTitle()}` @@ -318,6 +318,19 @@ ${node.getContent()} ` } + convert_inline_footnote (node) { + if (node.getDocument().isAttribute('nofootnotes')) { + return this.baseConverter.$convert_inline_footnote(node) + } + const index = node.getAttribute('index') + const text = node.getText() + if (index) { + return `${text}` + } + const idAttribute = node.getId() ? ` id="_footnote_${node.getId()}"` : '' + return `${text}` + } + resolveStylesheet (requirePath, cwd = process.cwd()) { // NOTE appending node_modules prevents require from looking elsewhere before looking in these paths const paths = [cwd, ospath.dirname(__dirname)].map((start) => ospath.join(start, 'node_modules')) @@ -404,15 +417,7 @@ ${this.documentTypeStyle(node)} return doc.getDoctype() === 'book' || doc.hasAttribute('title-page') } - footnotes (node) { - if (node.hasFootnotes() && !(node.isAttribute('nofootnotes'))) { - return `
-
- ${node.getFootnotes().map((footnote) => `
- ${footnote.getIndex()}. ${footnote.getText()} -
`).join('')} -
` - } + footnotes (_) { return '' } @@ -425,7 +430,7 @@ ${faDom.css()} return '' } - docinfoContent(node, docinfoLocation, suffix) { + docinfoContent (node, docinfoLocation, suffix) { const docinfoContent = node.getDocinfo(docinfoLocation, suffix) if (docinfoContent) { return docinfoContent @@ -530,6 +535,7 @@ module.exports.templates = { admonition: node => instance.convert_admonition(node), inline_callout: node => instance.convert_inline_callout(node), inline_image: node => instance.convert_inline_image(node), + inline_footnote: node => instance.convert_inline_footnote(node), colist: node => instance.convert_colist(node), page_break: node => instance.convert_page_break(node), preamble: node => instance.convert_preamble(node) diff --git a/package-lock.json b/package-lock.json index ab93016d..174bfa6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@fortawesome/free-brands-svg-icons": "5.15.4", "@fortawesome/free-regular-svg-icons": "5.15.4", "@fortawesome/free-solid-svg-icons": "5.15.4", - "@ggrossetie/pagedjs": "0.1.43-next.1613141153", + "@ggrossetie/pagedjs": "0.2.0-next.1623590414", "chokidar": "3.5.2", "file-url": "3.0.0", "fs-extra": "9.1.0", @@ -177,11 +177,14 @@ } }, "node_modules/@babel/runtime": { - "version": "7.13.10", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.10.tgz", - "integrity": "sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==", + "version": "7.15.3", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.15.3.tgz", + "integrity": "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==", "dependencies": { "regenerator-runtime": "^0.13.4" + }, + "engines": { + "node": ">=6.9.0" } }, "node_modules/@babel/types": { @@ -305,14 +308,14 @@ } }, "node_modules/@ggrossetie/pagedjs": { - "version": "0.1.43-next.1613141153", - "resolved": "https://registry.npmjs.org/@ggrossetie/pagedjs/-/pagedjs-0.1.43-next.1613141153.tgz", - "integrity": "sha512-dQxotx1rKyLWmgt2Skv+QreI7fTOCAkuLjTLPT1l3VA29jeiaCK00vp4q/ckzOQiwto+VD8gB1JcM+/y1kgBeQ==", + "version": "0.2.0-next.1623590414", + "resolved": "https://registry.npmjs.org/@ggrossetie/pagedjs/-/pagedjs-0.2.0-next.1623590414.tgz", + "integrity": "sha512-zECa0Q8/DlvpuDkk/3+EJ1OTWZMiEX4ue5ipSx+TImI/SPnUVwVHaaPOA1MaUA6asSl7MUg2T1hVptYibb2KQQ==", "dependencies": { "@babel/polyfill": "^7.10.1", - "@babel/runtime": "^7.10.2", + "@babel/runtime": "^7.14.0", "clear-cut": "^2.0.2", - "css-tree": "1.0.0-alpha.39", + "css-tree": "^1.1.3", "event-emitter": "^0.3.5" } }, @@ -336,18 +339,6 @@ "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==", "hasInstallScript": true }, - "node_modules/@ggrossetie/pagedjs/node_modules/css-tree": { - "version": "1.0.0-alpha.39", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.39.tgz", - "integrity": "sha512-7UvkEYgBAHRG9Nt980lYxjsTrCyHFN53ky3wVsDkiMdVqylqRt+Zc+jm5qw7/qyOvN2dHSYtX0e4MbCCExSvnA==", - "dependencies": { - "mdn-data": "2.0.6", - "source-map": "^0.6.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/@ggrossetie/pagedjs/node_modules/d": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", @@ -394,11 +385,6 @@ "es5-ext": "~0.10.14" } }, - "node_modules/@ggrossetie/pagedjs/node_modules/mdn-data": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.6.tgz", - "integrity": "sha512-rQvjv71olwNHgiTbfPZFkJtjNMciWgswYeciZhtvWLO8bmX3TnhyA62I6sTWOyZssWHJJjY6/KiWwqQsWWsqOA==" - }, "node_modules/@ggrossetie/pagedjs/node_modules/next-tick": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", @@ -1541,6 +1527,18 @@ "url": "https://github.com/sponsors/fb55" } }, + "node_modules/css-tree": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.1.3.tgz", + "integrity": "sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==", + "dependencies": { + "mdn-data": "2.0.14", + "source-map": "^0.6.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/css-what": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/css-what/-/css-what-5.0.1.tgz", @@ -3841,6 +3839,11 @@ "resolved": "https://registry.npmjs.org/mathjax/-/mathjax-3.2.0.tgz", "integrity": "sha512-PL+rdYRK4Wxif+SQ94zP/L0sv6/oW/1WdQiIx0Jvn9FZaU5W9E6nlIv8liYAXBNPL2Fw/i+o/mZ1212eSzn0Cw==" }, + "node_modules/mdn-data": { + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz", + "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==" + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -4981,9 +4984,9 @@ } }, "node_modules/path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "node_modules/path-to-regexp": { @@ -6335,9 +6338,9 @@ } }, "node_modules/tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.8.tgz", + "integrity": "sha512-sb9b0cp855NbkMJcskdSYA7b11Q8JsX4qe4pyUAfHp+Y6jBjJeek2ZVlwEfWayshEIwlIzXx0Fain3QG9JPm2A==", "dev": true, "dependencies": { "chownr": "^2.0.0", @@ -7023,9 +7026,9 @@ "dev": true }, "@babel/runtime": { - "version": "7.13.10", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.13.10.tgz", - "integrity": "sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==", + "version": "7.15.3", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.15.3.tgz", + "integrity": "sha512-OvwMLqNXkCXSz1kSm58sEsNuhqOx/fKpnUnKnFB5v8uDda5bLNEHNgKPvhDN6IU0LDcnHQ90LlJ0Q6jnyBSIBA==", "requires": { "regenerator-runtime": "^0.13.4" } @@ -7124,14 +7127,14 @@ } }, "@ggrossetie/pagedjs": { - "version": "0.1.43-next.1613141153", - "resolved": "https://registry.npmjs.org/@ggrossetie/pagedjs/-/pagedjs-0.1.43-next.1613141153.tgz", - "integrity": "sha512-dQxotx1rKyLWmgt2Skv+QreI7fTOCAkuLjTLPT1l3VA29jeiaCK00vp4q/ckzOQiwto+VD8gB1JcM+/y1kgBeQ==", + "version": "0.2.0-next.1623590414", + "resolved": "https://registry.npmjs.org/@ggrossetie/pagedjs/-/pagedjs-0.2.0-next.1623590414.tgz", + "integrity": "sha512-zECa0Q8/DlvpuDkk/3+EJ1OTWZMiEX4ue5ipSx+TImI/SPnUVwVHaaPOA1MaUA6asSl7MUg2T1hVptYibb2KQQ==", "requires": { "@babel/polyfill": "^7.10.1", - "@babel/runtime": "^7.10.2", + "@babel/runtime": "^7.14.0", "clear-cut": "^2.0.2", - "css-tree": "1.0.0-alpha.39", + "css-tree": "^1.1.3", "event-emitter": "^0.3.5" }, "dependencies": { @@ -7154,15 +7157,6 @@ "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.11.tgz", "integrity": "sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg==" }, - "css-tree": { - "version": "1.0.0-alpha.39", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.39.tgz", - "integrity": "sha512-7UvkEYgBAHRG9Nt980lYxjsTrCyHFN53ky3wVsDkiMdVqylqRt+Zc+jm5qw7/qyOvN2dHSYtX0e4MbCCExSvnA==", - "requires": { - "mdn-data": "2.0.6", - "source-map": "^0.6.1" - } - }, "d": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz", @@ -7209,11 +7203,6 @@ "es5-ext": "~0.10.14" } }, - "mdn-data": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.6.tgz", - "integrity": "sha512-rQvjv71olwNHgiTbfPZFkJtjNMciWgswYeciZhtvWLO8bmX3TnhyA62I6sTWOyZssWHJJjY6/KiWwqQsWWsqOA==" - }, "next-tick": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", @@ -8139,6 +8128,15 @@ "nth-check": "^2.0.0" } }, + "css-tree": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.1.3.tgz", + "integrity": "sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==", + "requires": { + "mdn-data": "2.0.14", + "source-map": "^0.6.1" + } + }, "css-what": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/css-what/-/css-what-5.0.1.tgz", @@ -9906,6 +9904,11 @@ "resolved": "https://registry.npmjs.org/mathjax/-/mathjax-3.2.0.tgz", "integrity": "sha512-PL+rdYRK4Wxif+SQ94zP/L0sv6/oW/1WdQiIx0Jvn9FZaU5W9E6nlIv8liYAXBNPL2Fw/i+o/mZ1212eSzn0Cw==" }, + "mdn-data": { + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.14.tgz", + "integrity": "sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==" + }, "merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -10763,9 +10766,9 @@ "dev": true }, "path-parse": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", - "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, "path-to-regexp": { @@ -11799,9 +11802,9 @@ } }, "tar": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", - "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.8.tgz", + "integrity": "sha512-sb9b0cp855NbkMJcskdSYA7b11Q8JsX4qe4pyUAfHp+Y6jBjJeek2ZVlwEfWayshEIwlIzXx0Fain3QG9JPm2A==", "dev": true, "requires": { "chownr": "^2.0.0", diff --git a/package.json b/package.json index fc2294ef..323f5720 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@fortawesome/free-brands-svg-icons": "5.15.4", "@fortawesome/free-regular-svg-icons": "5.15.4", "@fortawesome/free-solid-svg-icons": "5.15.4", - "@ggrossetie/pagedjs": "0.1.43-next.1613141153", + "@ggrossetie/pagedjs": "0.2.0-next.1623590414", "chokidar": "3.5.2", "file-url": "3.0.0", "fs-extra": "9.1.0", diff --git a/test/fixtures/footnotes.adoc b/test/fixtures/footnotes.adoc new file mode 100644 index 00000000..172e10c9 --- /dev/null +++ b/test/fixtures/footnotes.adoc @@ -0,0 +1,13 @@ += Footnotes + +The hail-and-rainbow protocol can be initiated at five levels: + +. doublefootnote:[The double hail-and-rainbow level makes my toes tingle.] +. tertiary +. supernumerary +. supermassive +. apocalyptic + +A bold statement!footnote:disclaimer[Opinions are my own.] + +Another outrageous statement.footnote:disclaimer[]