all repos — grayfriday @ 3a9946166285b0dbfe632f15d44191e7f9c0776c

blackfriday fork with a few changes

Make sure relative URLs are preserved

Add tests to make sure we don't break relative URLs again.
Extracted common html flags and common extensions for easy access from
tests.

Closes issue #104, which was fixed as a side effect of cf6bfc9.
Vytautas Ĺ altenis vytas@rtfb.lt
Sun, 21 Sep 2014 16:29:24 +0300
commit

3a9946166285b0dbfe632f15d44191e7f9c0776c

parent

64fbfbbadf651c943c4dec8e28c9ac20d973fad7

2 files changed, 30 insertions(+), 18 deletions(-)

jump to
M inline_test.goinline_test.go

@@ -42,6 +42,7 @@ prefix := "http://localhost"

params := HtmlRendererParameters{AbsolutePrefix: prefix} transformTests := transformLinks(tests, prefix) doTestsInlineParam(t, transformTests, 0, 0, params) + doTestsInlineParam(t, transformTests, 0, commonHtmlFlags(), params) } func doSafeTestsInline(t *testing.T, tests []string) {

@@ -353,6 +354,12 @@ "<p><img src=\"/bar/\" alt=\"foo with a title\" title=\"title\" />\n</p>\n",

"![foo with a title](/bar/ title with no quotes)\n", "<p><img src=\"/bar/ title with no quotes\" alt=\"foo with a title\" />\n</p>\n", + + "![](img.jpg)\n", + "<p><img src=\"img.jpg\" alt=\"\" />\n</p>\n", + + "[link](url)\n", + "<p><a href=\"url\">link</a></p>\n", "![foo]()\n", "<p>![foo]()</p>\n",
M markdown.gomarkdown.go

@@ -212,6 +212,27 @@

return Markdown(input, renderer, extensions) } +func commonHtmlFlags() int { + htmlFlags := 0 + htmlFlags |= HTML_USE_XHTML + htmlFlags |= HTML_USE_SMARTYPANTS + htmlFlags |= HTML_SMARTYPANTS_FRACTIONS + htmlFlags |= HTML_SMARTYPANTS_LATEX_DASHES + return htmlFlags +} + +func commonExtensions() int { + extensions := 0 + extensions |= EXTENSION_NO_INTRA_EMPHASIS + extensions |= EXTENSION_TABLES + extensions |= EXTENSION_FENCED_CODE + extensions |= EXTENSION_AUTOLINK + extensions |= EXTENSION_STRIKETHROUGH + extensions |= EXTENSION_SPACE_HEADERS + extensions |= EXTENSION_HEADER_IDS + return extensions +} + // Call Markdown with most useful extensions enabled // MarkdownCommon is a convenience function for simple rendering. // It processes markdown input with common extensions enabled, including:

@@ -233,24 +254,8 @@ //

// * Custom Header IDs func MarkdownCommon(input []byte) []byte { // set up the HTML renderer - htmlFlags := 0 - htmlFlags |= HTML_USE_XHTML - htmlFlags |= HTML_USE_SMARTYPANTS - htmlFlags |= HTML_SMARTYPANTS_FRACTIONS - htmlFlags |= HTML_SMARTYPANTS_LATEX_DASHES - renderer := HtmlRenderer(htmlFlags, "", "") - - // set up the parser - extensions := 0 - extensions |= EXTENSION_NO_INTRA_EMPHASIS - extensions |= EXTENSION_TABLES - extensions |= EXTENSION_FENCED_CODE - extensions |= EXTENSION_AUTOLINK - extensions |= EXTENSION_STRIKETHROUGH - extensions |= EXTENSION_SPACE_HEADERS - extensions |= EXTENSION_HEADER_IDS - - return Markdown(input, renderer, extensions) + renderer := HtmlRenderer(commonHtmlFlags(), "", "") + return Markdown(input, renderer, commonExtensions()) } // Markdown is the main rendering function.