Cleaned up handling of embedded quotes in link titles.

Now these are stored as a '"' character, not as '"'.
The function escapeLinkTitle in the Markdown writer is
unnecessary and was removed.  Tests modified accordingly.


git-svn-id: https://pandoc.googlecode.com/svn/trunk@517 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
fiddlosopher 2007-01-27 22:45:14 +00:00
parent 141affdb51
commit 8e0ad5a006
5 changed files with 13 additions and 18 deletions

View file

@ -894,8 +894,7 @@ titleWith startChar endChar = try (do
char endChar
skipSpaces
notFollowedBy (noneOf ")\n")))
let tit' = substitute "\"" """ tit
return tit')
return tit)
title = choice [ titleWith '(' ')',
titleWith '"' '"',

View file

@ -52,10 +52,6 @@ writeMarkdown options (Pandoc meta blocks) =
escapeString :: String -> String
escapeString = backslashEscape "`<\\*_^"
-- | Escape embedded \" in link title.
escapeLinkTitle :: String -> String
escapeLinkTitle = substitute "\"" "\\\""
-- | Take list of inline elements and return wrapped doc.
wrappedMarkdown :: [Inline] -> Doc
wrappedMarkdown lst =
@ -119,7 +115,7 @@ blockToMarkdown tabStop (Note ref lst) =
blockToMarkdown tabStop (Key txt (Src src tit)) =
text " " <> char '[' <> inlineListToMarkdown txt <> char ']' <>
text ": " <> text src <>
if tit /= "" then text (" \"" ++ (escapeLinkTitle tit) ++ "\"") else empty
if tit /= "" then text (" \"" ++ tit ++ "\"") else empty
blockToMarkdown tabStop (CodeBlock str) =
(nest tabStop $ vcat $ map text (lines str)) <> text "\n"
blockToMarkdown tabStop (RawHtml str) = text str
@ -185,7 +181,7 @@ inlineToMarkdown (Link txt (Src src tit)) =
else inlineListToMarkdown txt
linktitle = if null tit
then empty
else text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
else text (" \"" ++ tit ++ "\"")
srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src in
if (null tit) && (txt == [Str srcSuffix])
then char '<' <> text srcSuffix <> char '>'
@ -203,7 +199,7 @@ inlineToMarkdown (Image alternate (Src source tit)) =
else inlineListToMarkdown alternate in
char '!' <> char '[' <> alt <> char ']' <> char '(' <> text source <>
(if tit /= ""
then text (" \"" ++ (escapeLinkTitle tit) ++ "\"")
then text (" \"" ++ tit ++ "\"")
else empty) <> char ')'
inlineToMarkdown (Image alternate (Ref ref)) =
char '!' <> inlineToMarkdown (Link alternate (Ref ref))

View file

@ -268,7 +268,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title preceded by two spaces"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title preceded by a tab"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with &quot;quotes&quot; in it")]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with \"quotes\" in it")]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with single quotes")]
, Para [Link [Str "with",Str "_",Str "underscore"] (Src "/url/with_underscore" "")]
, Para [Link [Str "Email",Space,Str "link"] (Src "mailto:nobody@nowhere.net" "")]
@ -290,8 +290,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, CodeBlock "[not]: /url"
, Key [Str "b"] (Src "/url/" "")
, Para [Str "Foo",Space,Link [Str "bar"] (Ref [Str "bar"]),Str "."]
, Para [Str "Foo",Space,Link [Str "biz"] (Src "/url/" "Title with &quot;quote&quot; inside"),Str "."]
, Key [Str "bar"] (Src "/url/" "Title with &quot;quotes&quot; inside")
, Para [Str "Foo",Space,Link [Str "biz"] (Src "/url/" "Title with \"quote\" inside"),Str "."]
, Key [Str "bar"] (Src "/url/" "Title with \"quotes\" inside")
, Header 2 [Str "With",Space,Str "ampersands"]
, Para [Str "Here",Apostrophe,Str "s",Space,Str "a",Space,Link [Str "link",Space,Str "with",Space,Str "an",Space,Str "ampersand",Space,Str "in",Space,Str "the",Space,Str "URL"] (Ref [Str "1"]),Str "."]
, Para [Str "Here",Apostrophe,Str "s",Space,Str "a",Space,Str "link",Space,Str "with",Space,Str "an",Space,Str "amersand",Space,Str "in",Space,Str "the",Space,Str "link",Space,Str "text:",Space,Link [Str "AT",Str "&",Str "T"] (Ref [Str "2"]),Str "."]

View file

@ -510,7 +510,7 @@ Just a [URL](/url/).
[URL and title](/url/ "title preceded by a tab").
[URL and title](/url/ "title with &quot;quotes&quot; in it")
[URL and title](/url/ "title with "quotes" in it")
[URL and title](/url/ "title with single quotes")
@ -554,10 +554,10 @@ This should [not][] be a link.
Foo [bar][].
Foo [biz](/url/ "Title with &quot;quote&quot; inside").
Foo [biz](/url/ "Title with "quote" inside").
[bar]: /url/ "Title with &quot;quotes&quot; inside"
[bar]: /url/ "Title with "quotes" inside"
## With ampersands

View file

@ -268,7 +268,7 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title preceded by two spaces"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title preceded by a tab"),Str "."]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with &quot;quotes&quot; in it")]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with \"quotes\" in it")]
, Para [Link [Str "URL",Space,Str "and",Space,Str "title"] (Src "/url/" "title with single quotes")]
, Para [Link [Str "with",Str "_",Str "underscore"] (Src "/url/with_underscore" "")]
, Para [Link [Str "Email",Space,Str "link"] (Src "mailto:nobody@nowhere.net" "")]
@ -290,8 +290,8 @@ Pandoc (Meta [Str "Pandoc",Space,Str "Test",Space,Str "Suite"] ["John MacFarlane
, CodeBlock "[not]: /url"
, Key [Str "b"] (Src "/url/" "")
, Para [Str "Foo",Space,Link [Str "bar"] (Ref [Str "bar"]),Str "."]
, Para [Str "Foo",Space,Link [Str "biz"] (Src "/url/" "Title with &quot;quote&quot; inside"),Str "."]
, Key [Str "bar"] (Src "/url/" "Title with &quot;quotes&quot; inside")
, Para [Str "Foo",Space,Link [Str "biz"] (Src "/url/" "Title with \"quote\" inside"),Str "."]
, Key [Str "bar"] (Src "/url/" "Title with \"quotes\" inside")
, Header 2 [Str "With",Space,Str "ampersands"]
, Para [Str "Here",Apostrophe,Str "s",Space,Str "a",Space,Link [Str "link",Space,Str "with",Space,Str "an",Space,Str "ampersand",Space,Str "in",Space,Str "the",Space,Str "URL"] (Ref [Str "1"]),Str "."]
, Para [Str "Here",Apostrophe,Str "s",Space,Str "a",Space,Str "link",Space,Str "with",Space,Str "an",Space,Str "amersand",Space,Str "in",Space,Str "the",Space,Str "link",Space,Str "text:",Space,Link [Str "AT",Str "&",Str "T"] (Ref [Str "2"]),Str "."]