'Creating anchors for footnotes in markdown

I help publish articles on history, archeology, toponymy, etc. The texts are scientific and they always have a lot of references to the literature used (anchors). The engine is jekyll, so I make everything through markdown. Link text might look like this:

[12]
[5, 7, 13]

After processing, I bring them to this form:

[[12]](#t53-[12])
[[5, 7, 13]](#t53-[5])

To do this, I put together the following regular expression (I use atom.io, but it's not important):

find:

(\[[0-9, ]+\])

replace:

[$1](#t53-$1)

that is, in "complex" footnotes, I manually correct the link (but not its text). t53 is an arbitrary text, chapter number, for example

What should be added to the regular expression so that after the replacement the link leads to the first source of literature?



Solution 1:[1]

It's hard to provide a precise answer without a sample page that describes exactly what you want to achieve. To link to an internal anchor the syntax is something like <a href="#t1-blah">link text</a>. I am not sure how this would work in markdown, but you have the option of using straight HTML so try this:

<a href="#t53-$1">$1</a>

If it doesn't work or this is not what you want, I suggest you provide us with a short sample of your page and how you want it to change

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1