Handling for footnotes to create unique IDs per document
I'm publishing a blog with Markdown, http://www.clearlytech.com/, and each article I process through Marked2 before putting the resulting HTML into Wordpress.
The handling of footnotes creates a problem, because each footnote block has the same ID, so index pages that show whole articles (or even just excerpts that happen to have footnotes in them) will have broken behavior (the first #fn1 will show for all [1] links)
Is there any way built-in, or through custom scripts, to have Marked add a per-document prefix to footnotes? Perhaps a timestamp when it was generated, for example?
Haven't customized Marked at all, would love pointers on how to go about that, if no one has solved it yet.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 07 Oct, 2013 02:16 PM
While I have scripts that will do exactly this, I would highly recommend getting a WordPress plugin called "Markdown on Save" for your blog. It lets you actually post Markdown, renders it immediately so that you're still serving HTML on the front end, but stores the Markdown for future editing in the database.
When I ran a WordPress blog, that's exactly how I handled this situation. As far as scripting, you could easily add a Custom Pre-processor script that replaced "[^" with "[^randomnumber" as needed, then passed the Markdown back to Marked 2 for handling.
-Brett
2 Posted by will on 07 Oct, 2013 02:32 PM
Thanks Brett. I'll take a look at both options. Originally, I went with an offline Markdown processing because I wanted more control over some of the details of inline images and a few other "post-production" things that were more natural to do in HTML. But I may be able to get away with what I need by co-mingling some HTML into my markdown and getting the best of both worlds. I'll play with it some.
Do you happen to know how markdown-on-save handle footnote IDs?
Good to know that a pre-processor script is doable, if I stick with my current method, I'll go that route.
Support Staff 3 Posted by Brett on 07 Oct, 2013 02:49 PM
Markdown on Save handles footnotes in the standard way, I guess. The trick is to use descriptive footnote names, now that I think about it. So either a pre-processor that adds timestamps/random numbers (just make sure you use the same number throughout the post by setting it as a variable before doing the search/replace), or use words (which is what I do) instead of "fn1" or "1", etc.
-Brett
4 Posted by will on 28 Oct, 2013 03:09 AM
I may be missing something here, Brett, but this is what I'm seeing. My Markdown (in this case, compiled by Scrivener), has footnote references like:
---------------------------
Line of text.[^cf1]
[^cf1]: Footnote1
----------------------------
I'm sending this through a sed script modeled on your service, which changes it to:
-------------------------------
Line of text.[^1382929562-cf1]
[^1382929562-cf1]: Footnote1
----------------------------------------
But when I process that in Marked2, I seem to get HTML that looks like:
---------------------------------------
Line of text.<a href="#fn:1" id="fnref:1" title="see footnote" class="footnote">[1]</a>
<li id="fn:1">
<p>Footnote1<a href="#fnref:1" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
------------------------------------------------
It seems that Marked2 is canonicalizing them, no matter what my references look like. Is that the expected behavior, or am I missing a step that with keep them unique?
Support Staff 5 Posted by Brett on 28 Oct, 2013 10:23 AM
It appears to be new behavior in MultiMarkdown 4. I’ll have to look into it and possibly work with Fletcher to add the option to change that. I understand the need for it.
-Brett
6 Posted by will on 28 Oct, 2013 02:22 PM
Thanks so much Brett for the reply and the willingness to help address it!
I just tested with peg-multimarkdown 3.7 binaries, and seems to exhibit the same behavior. I've created a test case so you can more easily play with it.
http://cl.ly/3b2J0x3A0v0P
That zip includes a simple input file, a pre-processor shell script, and the mmd 3.7 binaries. Also a log file of the commands I'm running with output.
What I'm expecting is that the custom-naming for the "cf" references will somehow carry through into the HTML output from the multimarkdown processor. What I'm seeing is that it matches the references, but then canonicalizes back to the "fn:1" format.
Support Staff 7 Posted by Brett on 28 Oct, 2013 02:28 PM
Thanks. I’ve contacted Fletcher Penney about an option to maintain the reference title in output the way Kramdown does. If he’s unable to implement that, I’ll probably write a processor within Marked that at least adds the timestamp hash to footnote ids when exporting/copying HTML as an optional feature.
8 Posted by will on 28 Oct, 2013 02:58 PM
Confirmed Brett, I just ran my test-case with kramdown, that's exactly the behavior I'm looking for.
I'll have to evaluate kramdown more before deciding whether I want to use it in the interim or wait. But I appreciate the pointer towards that, and the helpful support. Keep it up.
If you add the feature, you have my permission to call it "Marked3", and charge me again. ;-)
9 Posted by daveG on 28 Oct, 2013 10:04 PM
HI,
I have a similar request and I put it here because I think t can be (maybe) solved the same way.
I have a table with footnotes where there are about 5 distinct notes, reused many times.
This works fine in HTML. But in LaTeX export each footnote has been rendered in each location, so the list of footnotes has copies of the 5 footnotes, one for each location. There seems to be another way to mark a ote in LaTex that removes this issue, how can I make MD export it how I want?
Support Staff 10 Posted by Brett on 28 Oct, 2013 10:14 PM
I don’t understand. Which is correct, the HTML or the LaTeX export? I definitely can’t help with the LaTeX side of things...
Support Staff 11 Posted by Brett on 28 Oct, 2013 10:17 PM
By the way, after my request Fletcher added a "random" switch to the development version of MMD 4, so it can now generate a random number to make footnotes unique. That should solve this issue and I’ll add it as an option to Marked soon.
12 Posted by will on 28 Oct, 2013 10:27 PM
Very cool Brett (and Fletcher, rocking the continuous development cycle!)
I'm new enough to Marked as an app, can you explain the release cycles? How often does MMD4 release binaries, and how often are those re-packaged with Marked? Just opportunistically when new feature releases happen?
Should I just download MMD4, compile it myself, and use that as a custom processor in the meantime? Or is the cycle on these things pretty quick?
Support Staff 13 Posted by Brett on 28 Oct, 2013 10:30 PM
MMD4 updates fairly regularly, but Marked uses a compiled library version and only updates when I think there’s a need to rebuild it.
Compiling and using your own copy of MMD4 shouldn’t cause any issues, though there may be a minuscule speed hit. I should have an update with the new MMD4 version soon after the one that will be out in the next couple of days.
-Brett
14 Posted by will on 02 Dec, 2013 12:17 AM
I notice that Marked 2.2 ships with MMD 4.4, which supports the --random flag. Is there a way in Marked to use this flag yet?
Altneratively, what's the best path to use for the local MMD copy inside Marked? Happy to set the default as a custom processor, but just add --random to the args.
15 Posted by will on 02 Dec, 2013 12:19 AM
Also, for people watching this thread, note that "Markdown on Save" does appear to prepend a unique ID to different posts (as of fairly recently). Which makes it another option for solving this, if you want to skip Marked altogether for wordpress posts.
Finally, Wordpress itself recently added Markdown support, and their Jetpack plugin will inherit it soon. That may be another functional alternative to Markdown on Save.
Support Staff 16 Posted by Brett on 02 Dec, 2013 01:37 AM
No, I haven't incorporated the option yet (plan to, though). You can
install MMD and use /usr/local/bin/multimarkdown as your custom
processor.