Skip to content

Commit

Permalink
[zmarkdown] Fix too much randomness in footnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
StaloneLab committed Mar 8, 2021
1 parent 20e548e commit a3a398f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/zmarkdown/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ 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)
}))
}

parser.process(input, (err, vfile) => {
if (doRegenerate) regenerator()
if (err) return cb(err)

cb(null, vfile)
Expand Down
8 changes: 7 additions & 1 deletion packages/zmarkdown/config/html/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const shortid = require('shortid')

let currentFootnotePostfix = shortid.generate()

module.exports = {
autolinkHeadings: {
behaviour: 'append',
Expand All @@ -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'),
Expand Down

0 comments on commit a3a398f

Please sign in to comment.