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.
This commit is contained in:
Vytautas Šaltenis 2014-09-21 16:29:24 +03:00
parent 64fbfbbadf
commit 3a99461662
2 changed files with 30 additions and 18 deletions

View File

@ -42,6 +42,7 @@ func doLinkTestsInline(t *testing.T, tests []string) {
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) {
@ -354,6 +355,12 @@ func TestInlineLink(t *testing.T) {
"![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",

View File

@ -212,6 +212,27 @@ func MarkdownBasic(input []byte) []byte {
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 @@ func MarkdownBasic(input []byte) []byte {
// * 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.