fix-markdown-footnotes v0.0.1
Fix Markdown Footnotes
fmf is a CLI that will reorder foonotes chronologically.
# Before
Hello[^7] world[^3]. These[^2] are[^2b] unordered.[^hi]
# After
Hello[^1] world[^2]. These[^3] are[^4] unordered.[^5]Try without installing
npx fix-markdown-footnotes your-file.mdInstall
npm install -g fix-markdown-footnotesUse
fmf article.mdor to fix all Markdown documents in your directory:
fmf *If that fails, please try:
fmf '*'Algorithm
Using the /(\[\^[^\]]*])/g regex we detect all instances of footnotes and confirm there is an even number of matches. Then we generate replacement values (via mapping to intermediate unique hashes) starting with 1 in order of appearance. Finally we write the new file contents, replacing the old file.
Developing
Run npm start to test locally. Pass in a file: npm start test.md to run the script on the file.
To install a custom version of fmf, adjust the script to your liking by editing index.js and then run npm run global. Now when you execute fmf you'll be running your version of the script.
Notes
Read the MarkdownGuide.org details about footnotes.
- the CLI will ignore the node_modules folder
- the CLI will not change the order of the footnotes at the bottom of the document
- the CLI will not fix duplicate footnote numbers: having
Hi[^4] lol[^4]is not proper Markdown.
3 years ago