yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.93k stars 326 forks source link

[Feature Request] Automatic Endnote Ordering #391

Open AllanWang opened 5 years ago

AllanWang commented 5 years ago

I'm willing to help with the implementation!

Endnotes are additional bits of explanations added at the end of documents. Typically, you'd tag the relevant sentence with an index:

sentence to be expanded [1]

and have it linked to the information:

1. explanation.

Indices should be in order, which gets annoying when done manually. I was wondering if we could add a feature similar to TOC, where we can automatically organize and number endnotes.


Currently, my example is like so:

A tagged sentence ends with something of the format [[1](#cite-tag)]

and the end of my document contains something like:

# Endnote

| | |
|---|---|
| <a id="cite-tag">1</a> | explanation |

Formatting would basically involve finding all instances of \[\[([0-9]+)\]\(\#cite-([a-zA-Z]+)\)\] as well as the table, and ordering based on the #cite-* occurrences.

To prevent unwanted endnote formatting, perhaps the table can have a comment such as <!-- endnote -->, much like TOC.

There are also other constraints such as the ability to use superscripts for endnotes or to display endnotes as a list vs a table.


Would you be interested in adding such a feature to this plugin? If so, how do you feel about the customization, and in ensuring that people have a way to disable it if they have their own #cite-* ids?

yzhang-gh commented 5 years ago

I feel like there are already many different kinds of similar Markdown dialects. (e.g. Markdown Footnotes).

Personally, I would like not to "invent" a dialect again.

But if some of them are really popular/widely accepted (e.g. GitHub Flavored Markdown), I am happy to support them.

AllanWang commented 5 years ago

Yeah this isn't meant to be a new dialect. It's meant to support stuff like github flavoured markdown

yzhang-gh commented 5 years ago

For your case, a better way is to implement a markdown-it extension. (VSCode uses markdown-it to render Markdown)

AllanWang commented 5 years ago

I wonder if this is related to rendering, since the goal is to avoid supporting any new notations. Would this not be similar to TOC where we just parse and update the file?

yzhang-gh commented 5 years ago

Alright, I was misled by the title "endnote support". So what you expect is essentially "endnote sorting/organizing", right?

The problem is I don't think there are many people using this, even with the above footnote extension. It is annoying to write endnotes/footnotes with Markdown, not only because of manual sorting.

AllanWang commented 5 years ago

Yeah my mistake. It's certainly annoying to organize manually, which is exactly why a script would help. I could also write a general python script for my personal use, but given that I use this extension, I figured it would be a useful addition to others.

In terms of interest, there are some posts about it:

https://github.com/github/markup/issues/498 https://stackoverflow.com/questions/25579868/how-to-add-footnotes-to-github-flavoured-markdown

Ultimately it's still up to you whether or not you'd like to add the feature to this extension

yzhang-gh commented 5 years ago

Thanks for the suggestion. I will leave this open to see what other people think of.