From 45479114e88a351fc63bb8eff142bb10cfd2c661 Mon Sep 17 00:00:00 2001 From: Ole Martin Ruud Date: Fri, 25 Oct 2019 07:27:49 +0200 Subject: HTML reader/writer: Better handling of with cite attribute (#5837) * HTML reader: Handle cite attribute for quotes. If a `` tag has a `cite` attribute, we interpret it as a Quoted element with an inner Span. Closes #5798 * Refactor url canonicalization into a helper function * Modify HTML writer to handle quote with cite. [0]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q --- test/Tests/Writers/HTML.hs | 17 +++++++++++++++++ test/html-reader.html | 4 ++++ test/html-reader.native | 4 ++++ 3 files changed, 25 insertions(+) (limited to 'test') diff --git a/test/Tests/Writers/HTML.hs b/test/Tests/Writers/HTML.hs index de8b1ef17..94549e0d8 100644 --- a/test/Tests/Writers/HTML.hs +++ b/test/Tests/Writers/HTML.hs @@ -13,6 +13,11 @@ import Text.Pandoc.Builder html :: (ToPandoc a) => a -> String html = unpack . purely (writeHtml4String def{ writerWrapText = WrapNone }) . toPandoc +htmlQTags :: (ToPandoc a) => a -> String +htmlQTags = unpack + . purely (writeHtml4String def{ writerWrapText = WrapNone, writerHtmlQTags = True }) + . toPandoc + {- "my test" =: X =?> Y @@ -48,4 +53,16 @@ tests = [ testGroup "inline code" definitionList [(mempty, [para $ text "foo bar"])] =?> "

foo bar

" ] + , testGroup "quotes" + [ "quote with cite attribute (without q-tags)" =: + doubleQuoted (spanWith ("", [], [("cite", "http://example.org")]) (str "examples")) + =?> "“examples”" + , tQ "quote with cite attribute (with q-tags)" $ + doubleQuoted (spanWith ("", [], [("cite", "http://example.org")]) (str "examples")) + =?> "examples" + ] ] + where + tQ :: (ToString a, ToPandoc a) + => String -> (a, String) -> TestTree + tQ = test htmlQTags diff --git a/test/html-reader.html b/test/html-reader.html index a2bca5d2c..ae937af82 100644 --- a/test/html-reader.html +++ b/test/html-reader.html @@ -81,6 +81,10 @@ span.pandocNoteMarker { }

And a following paragraph.


+

Inline quotes

+

Normal text but then a inline quote.

+

Missing a cite attribute means its just normal text

+

Code Blocks

Code:

---- (should be four hyphens)
diff --git a/test/html-reader.native b/test/html-reader.native
index acd0087ef..5643fb73f 100644
--- a/test/html-reader.native
+++ b/test/html-reader.native
@@ -51,6 +51,10 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
   [Para [Str "Don't",Space,Str "quote",Space,Str "me."]]]
 ,Para [Str "And",Space,Str "a",Space,Str "following",Space,Str "paragraph."]
 ,HorizontalRule
+,Header 1 ("inline-quotes",[],[]) [Str "Inline",Space,Str "quotes"]
+,Para [Str "Normal",Space,Str "text",Space,Str "but",Space,Str "then",Space,Str "a",Space,Quoted DoubleQuote [Span ("",[],[("cite","https://www.imdb.com/title/tt0062622/quotes/qt0396921")]) [Str "inline",Space,Str "quote"]],Str "."]
+,Para [Quoted DoubleQuote [Str "Missing",Space,Str "a",Space,Str "cite",Space,Str "attribute",Space,Str "means",Space,Str "its",Space,Str "just",Space,Str "normal",Space,Str "text"]]
+,HorizontalRule
 ,Header 1 ("code-blocks",[],[]) [Str "Code",Space,Str "Blocks"]
 ,Para [Str "Code:"]
 ,CodeBlock ("",[],[]) "---- (should be four hyphens)\n\nsub status {\n    print \"working\";\n}\n\nthis code block is indented by one tab"
-- 
cgit v1.2.3