vmg / sundown

Standards compliant, fast, secure markdown processing library in C
1.99k stars 385 forks source link

Add MultiMarkdown footnotes extension #141

Open bdolman opened 11 years ago

bdolman commented 11 years ago

The footnote syntax and output basically follows what's outlined here: http://michelf.ca/projects/php-markdown/extra/#footnotes

The parsing of the footnote definition is very similar to a list item, per the direction in the footnotes reference above.

New extension flag called MKDEXT_FOOTNOTES.

Three new rendering callbacks:

The rest should be pretty self explanatory. I tried to follow the conventions in the current library. My buffer usage deserves some scrutiny to make sure I'm using the proper initial sizes.

I've done some basic testing, but nothing extensive. Would love to get some other people trying it and looking at it to see if I've missed something.

brief commented 11 years ago

Nice! I've run this again a dozen markdown files with footnotes. Haven't seen any errors yet.

bdolman commented 11 years ago

Thanks for doing that brief! Glad to know that it's working for you.

adamflorin commented 11 years ago

I impatiently made a fork of Redcarpet to play with these features, as a client of mine needs them this week. (Lucky timing for me!)

So far so good. The HTML markup gave me a bit of trouble, though; jQuery doesn't seem to like namespaced IDs (id='fn:1'). (I'm building some custom JS-based footnote-display code, too.)

Will post here if I see any other issues, but it looks great, thanks @bdolman !

adamflorin commented 11 years ago

Hmm, one thing I just noticed is that it fails to recognize multiple footnotes if the line delimiter is \r\n\ and not just \n. @bdolman, try feeding it this and you'll see that it picks up the first footnote but not the second:

"Footnote in body text[^1].\r\n\r\nAnd another[^2].\r\n\r\n[^1]: Defined below.\r\n\r\n[^2]: But not this time.\r\n"

I'll just preprocess for now, but thought I'd mention it, as \r\n hasn't given me any trouble in Sundown yet!

bdolman commented 11 years ago

@adamflorin Good catch! Give the latest a try.

bdolman commented 11 years ago

@adamflorin I'm also not really a huge fan of the fn:1 style namespacing. I noticed that peg-markdown eschews fn:1 and fnref:1 in favor of fn1 and fnref1. I think I actually prefer that, especially if it prevents issues with JQuery et. al.

microjo commented 11 years ago

+1 i'd like have this extension

mildsunrise commented 11 years ago

:+1: yeah, we'd like the extension to be merged! I have been waiting for this functionality in Sundown.

@vmg what do you think? Please consider adding it.

bootstraponline commented 11 years ago

+1

adamflorin commented 11 years ago

@bdolman, I confirmed that the \r\n issue is fixed by 511d6e973eefafb98f3a78cf831e53111ac81667. Many thanks!

vmg commented 11 years ago

Thanks for this PR, looks clean enough.

Unfortunately, Sundown is currently frozen as we're working with the Reddit, StackOverflow and Meteor developers to design a formal Markdown standard and parser that will supersede Sundown in all these websites (and in GitHub, of course). Our goal is to deprecate Sundown altogether before the end of the year. We're evaluating the possibility of adding a footnote extension to the new standard, but we're not quite there yet.

Sorry for the fuss. Stay tuned.

mildsunrise commented 11 years ago

estic preocupat. :crying_cat_face: @vmg Will it allow custom renderers and exts? Will it be as fast and secure as this has proven?

vmg commented 11 years ago

The only reason why we're deprecating Sundown is because we're 100% sure that we can come up with something faster, safer, and what's more important, more consistent than what we have now. I can assure you that the new parser will be an improvement in every sense -- and if it's not, you can always fork Sundown and continue developing it. Such is the magic of open source. :)

Just give me a couple weeks to get this thing going. I promise it'll be worth it. http://www.youtube.com/watch?v=FSJFTa2jvhk

FSX commented 11 years ago

Is there a place where we can follow the progress of this project, e.g. a mailinglist?

mildsunrise commented 11 years ago

@vmg Oh, lots of relaxed now. You can't imagine how much. Really. :)

bdolman commented 11 years ago

Thanks for the update @vmg, I'm thrilled that you are working with those developers to nail down a markdown standard and an even better markdown renderer.

In the meantime I just want to let everyone know that this footnotes extension is being used in at least two popular apps (and probably more) without any known issues, so please feel confident in using it until we get the new shiny.

devinus commented 10 years ago

@bdolman If you're interested, I have just released Hoedown 1.0.0, a revived fork of Sundown. It includes this pull request:

https://github.com/hoedown/hoedown

bdolman commented 10 years ago

@devinus Awesome, thanks for picking it back up. I'll definitely be checking out hoedown. I like the name too :)