From 352a34f73d66d64f3386569cb510ee56b1f37457 Mon Sep 17 00:00:00 2001 From: TitiAlone Date: Mon, 8 Mar 2021 22:31:04 +0100 Subject: [PATCH] [zmarkdown] Fix too much randomness in footnotes --- packages/zmarkdown/common.js | 6 ++++++ packages/zmarkdown/config/html/index.js | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/zmarkdown/common.js b/packages/zmarkdown/common.js index b252d4a6d..5b625ba73 100644 --- a/packages/zmarkdown/common.js +++ b/packages/zmarkdown/common.js @@ -33,10 +33,15 @@ module.exports = ( parser.use(processor, processorConfig) } + // Regenerate footnotes postfix on extracts + const doRegenerate = (processor === 'html' && processorConfig._regenerateFootnotePostfix) + const regenerator = processorConfig._regenerateFootnotePostfix + return (input, cb) => { if (typeof cb !== 'function') { return new Promise((resolve, reject) => parser.process(input, (err, vfile) => { + if (doRegenerate) regenerator() if (err) return reject(err) resolve(vfile) @@ -44,6 +49,7 @@ module.exports = ( } parser.process(input, (err, vfile) => { + if (doRegenerate) regenerator() if (err) return cb(err) cb(null, vfile) diff --git a/packages/zmarkdown/config/html/index.js b/packages/zmarkdown/config/html/index.js index 268d7d4c0..9108c7c93 100644 --- a/packages/zmarkdown/config/html/index.js +++ b/packages/zmarkdown/config/html/index.js @@ -1,5 +1,7 @@ const shortid = require('shortid') +let currentFootnotePostfix = shortid.generate() + module.exports = { autolinkHeadings: { behaviour: 'append', @@ -22,7 +24,11 @@ module.exports = { sanitize: require('../sanitize'), - postfixFootnotes: (agg) => `${agg}-${shortid.generate()}`, + postfixFootnotes: (agg) => `${agg}-${currentFootnotePostfix}`, + + _regenerateFootnotePostfix: () => { + currentFootnotePostfix = shortid.generate() + }, postProcessors: { iframeWrappers: require('./iframe-wrappers'),