rezozero / commonmark-ext-footnotes

Footnotes CommonMark extension
3 stars 2 forks source link

Footnotes don't show up in order #1

Closed nonoesp closed 4 years ago

nonoesp commented 4 years ago

Hey! First of all, Thanks so much for doing this. I've been waiting for this extension for a long time.

I'm using CommonMark but have to rely on michelf/php-markdown for posts with footnotes.

I just tested your extension and it works great.

I see a few differences on the output (in comparison with michelf/php-markdown) but the only one that bothered me was that footnotes don't show up ordered as they appear on the text, and that makes the numbering of the citation not match with the <sup>s in the text.

Is this behavior intended, or something that you haven't got around implementing yet?

Anyway, this is super helpful.

Cheers, Nono


Here is a sample Markdown text and its corresponding footnotes as rendered by michelf/php-markdown and this CommonMark footnotes extension. Note that the "correct" order according to the appearances of the footnotes in the text is as rendered by michelf/php-markdown, as citation one matches item number one of the footnotes' list.

Markdown rendered as HTML

200305_coronavirus

michelf/php-markdown

200305_michelf-php-markdown-citations

commonmark-ext-footnotes

200305_commonmark-ext-footnotes-citations

Markdown

<!-- ## We are out of face masks -->

Four days before the Chinese New Year, Dr. Guan Yi went to Wuhan among billions of Chinese people on their way to celebrate the year of the Rat, but the reason for his trip was different.[^nyt-200124]

The Chinese took 3 billion trips in a forty-day period surrounding January 25[^coronavirus-france-24], the Chinese New Year and, last time I checked, China had locked down five different cities amounting to twenty-something million people (which is half the population of Spain).[^coronavirus-cnn-live-dbb28e326d6cbd83bae222932be7d1df]

***

A few days later, on January 27, Sanjay sat next to me on a flight from Paris to Toronto. Coming all the way from India to spend four weeks in Canada with his son, Sanjay was wearing a face mask for prevention, and I spotted two other people wearing face masks as I changed flights in Charles de Gaulle that same day.

***

Coming back to Dr. Guan Yi, he traveled with his team to identify the germ that originated Coronavirus' outbreak[^nyt-200124]. They had successfully identified the Coronavirus that caused 2002–2003's SARS epidemic. This time, when Dr. Guan and his team arrived to the market where many infections had been traced back to, he found no trace of the virus. The government had disinfected it getting rid of any evidence. 

***

At the moment of this writing, there are seventy-six thousand confirmed cases[^COVID-19]. I wonder if there have been any previous viruses tracked so closely. <!-- 9 deaths out of 2247 --> Yet, only 0.004% of the reported deaths have occurred outside of China.

China quickly ran out of face masks, and I gave up searching for face masks in Brooklyn. While the media does its job to keep us alert, rumors say that China has been playing down its numbers. I have no idea.

What's true is that Coronavirus is (or has been) in your mind. It's not only a virus that spreads but viral news.

[^nyt-200124]: At the moment of my visit to [Coronavirus Death Toll Climbs in China, and a Lockdown Widens](https://www.nytimes.com/2020/01/23/world/asia/china-coronavirus.html) (2020) on *The New York Times*, the alarming headline said "25 people [had] died and more than 800 [had] been sickened by the mysterious illness."

[^coronavirus-france-24]: [More Chinese cities shut down, New Year events cancelled as deadly virus spreads](https://www.france24.com/en/20200123-beijing-cancels-major-lunar-new-year-events-in-effort-to-contain-coronavirus-spread) (2020). *France 24*.

[^coronavirus-cnn-live-dbb28e326d6cbd83bae222932be7d1df]: [CNN Live news](https://edition.cnn.com/asia/live-news/coronavirus-outbreak-hnk-intl-01-24-20/h_c43d502480f91875babacc06b679a3d5) (Jan 24, 2020). *CNN*.

[^COVID-19]: You can [check the reported cases live](https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6). Coronavirus COVID-19 Global Cases by Johns Hopkins CSSE.
ambroisemaupate commented 4 years ago

Hello !

That’s weird because I wrote a test case to check that order is preserve using footnotes references ordering.

https://github.com/rezozero/commonmark-ext-footnotes/blob/master/tests/Functional/data/regular.md

But I think this could come from the fact your using twice a footnote reference. I did not support that in the first place.

Could you try to remove the second [^nyt-200124] reference and see if the order is preserved. If yes, this must be the main issue.

nonoesp commented 4 years ago

Ha! Interesting. Thanks for the swift reply.

That gets rid of the issue (as you can see on the image). (1) Haven't looked at the code, is support to multiple references to one footnote (e.g. [^nyt-200124]) something you could add?

Screenshot 2020-03-05 22 25 47

The only difference now is that michelf/php-markdown adds a space before the backref ↩. (2) Is that a standard you're following or is this something that we could change? The following animation shows the difference (the one with just one reference on the first footnote is with this extension).

Screenshot 2020-03-05 22 25 47
ambroisemaupate commented 4 years ago

Ok this should be fixed now.

nonoesp commented 4 years ago

Thanks so much, Ambroise.