From 886eff3a2134b629df093f6775d3f7474ad09226 Mon Sep 17 00:00:00 2001 From: Julien Moutinho <julm+hdoc@autogeree.net> Date: Sun, 25 Feb 2018 04:14:48 +0100 Subject: [PATCH] Fix HeaderDotSlash rendering. --- Language/TCT/Write/HTML5.hs | 3 +- Language/TCT/Write/Plain.hs | 2 +- exe/cli/Main.hs | 39 +++++++++--------- test/Golden/TCT/HeaderDotHash/0001.tct.html5 | 2 +- test/Golden/TCT/HeaderDotHash/0001.tct.plain | 2 +- test/Golden/TCT/HeaderDotHash/0002.tct.html5 | 2 +- test/Golden/TCT/HeaderDotHash/0002.tct.plain | 2 +- test/Golden/TCT/HeaderDotHash/0003.tct.html5 | 6 +-- test/Golden/TCT/HeaderDotHash/0003.tct.plain | 6 +-- test/Golden/TCT/HeaderDotHash/0005.tct.html5 | 2 +- test/Golden/TCT/HeaderDotHash/0005.tct.plain | 2 +- test/Golden/TCT/HeaderDotHash/0010.tct | 2 + test/Golden/TCT/HeaderDotHash/0010.tct.ast | 9 +++++ .../HeaderDotHash/0010.tct.dtc.en_US.html5 | 40 +++++++++++++++++++ .../TCT/HeaderDotHash/0010.tct.dtc.en_US.xml | 19 +++++++++ test/Golden/TCT/HeaderDotHash/0010.tct.dump | 10 +++++ test/Golden/TCT/HeaderDotHash/0010.tct.html5 | 3 ++ test/Golden/TCT/HeaderDotHash/0010.tct.plain | 2 + test/Golden/TCT/HeaderDotHash/0010.tct.xml | 8 ++++ test/Golden/TCT/HeaderDotHash/0010.txt | 2 + 20 files changed, 127 insertions(+), 36 deletions(-) create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.ast create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.html5 create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.xml create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.dump create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.html5 create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.plain create mode 100644 test/Golden/TCT/HeaderDotHash/0010.tct.xml create mode 100644 test/Golden/TCT/HeaderDotHash/0010.txt diff --git a/Language/TCT/Write/HTML5.hs b/Language/TCT/Write/HTML5.hs index e0ce43d..bf093b7 100644 --- a/Language/TCT/Write/HTML5.hs +++ b/Language/TCT/Write/HTML5.hs @@ -194,7 +194,7 @@ instance Html5ify Root where h 6 = H.h6 h n | n > 6 = H.span ! HA.class_ ("h h"<>attrify n) h _ = undefined - HeaderDotSlash n -> do + HeaderDotSlash file -> do ext <- liftStateMarkup $ S.gets state_ext_html if null ext then html5ify file @@ -202,7 +202,6 @@ instance Html5ify Root where H.a ! HA.class_ "header-dotslash" ! HA.href (attrify $ file<>ext) $$ html5ify file - where file = "./"<>n where html5Head :: Name -> White -> Name -> White -> TL.Text -> White -> H.AttributeValue -> Html5 html5Head markBegin whmb name whn markEnd whme cl = do diff --git a/Language/TCT/Write/Plain.hs b/Language/TCT/Write/Plain.hs index 41ec352..8df524e 100644 --- a/Language/TCT/Write/Plain.hs +++ b/Language/TCT/Write/Plain.hs @@ -207,7 +207,7 @@ instance Plainify Header where HeaderDash -> "- " HeaderDashDash -> "-- " HeaderSection lvl -> plainify (List.replicate lvl '#') - HeaderDotSlash n -> "./" <> plainify n + HeaderDotSlash n -> plainify n instance Plainify Token where plainify = \case TokenText t -> plainify t diff --git a/exe/cli/Main.hs b/exe/cli/Main.hs index 3281833..22af132 100644 --- a/exe/cli/Main.hs +++ b/exe/cli/Main.hs @@ -84,27 +84,24 @@ main = do mainWithCommand :: Command -> IO () mainWithCommand (CommandTCT ArgsTCT{..}) = do - TCT.readFile input >>= \case - Left err -> IO.hPrint IO.stderr err - Right txt -> - case TCT.readTCTWithoutIncludes input txt of - Left err -> error $ show err - Right tct -> do - when (DumpTCT_TCT`elem`dump) $ - writeFile (output`FilePath.replaceExtension`".tct.dump") $ - TL.pack $ Tree.prettyTrees tct - when (DumpTCT_XML`elem`dump) $ - let xml = TCT.Write.XML.document tct in - writeFile (output`FilePath.replaceExtension`".xml.dump") $ - TL.pack $ Tree.prettyTrees xml - case format of - FormatTCT_Plain -> - writeFile output $ - TCT.Write.Plain.document tct - FormatTCT_HTML5 -> - withFile output IO.WriteMode $ \h -> - Blaze.renderMarkupToByteStringIO (BS.hPutStr h) $ - TCT.Write.HTML5.document tct + TCT.readTCT input >>= \case + Left err -> error $ show err + Right tct -> do + when (DumpTCT_TCT`elem`dump) $ + writeFile (output`FilePath.replaceExtension`".tct.dump") $ + TL.pack $ Tree.prettyTrees tct + when (DumpTCT_XML`elem`dump) $ + let xml = TCT.Write.XML.document tct in + writeFile (output`FilePath.replaceExtension`".xml.dump") $ + TL.pack $ Tree.prettyTrees xml + case format of + FormatTCT_Plain -> + writeFile output $ + TCT.Write.Plain.document tct + FormatTCT_HTML5 -> + withFile output IO.WriteMode $ \h -> + Blaze.renderMarkupToByteStringIO (BS.hPutStr h) $ + TCT.Write.HTML5.document tct mainWithCommand (CommandDTC ArgsDTC{..}) = TCT.readTCT input >>= \case Left err -> error $ show err diff --git a/test/Golden/TCT/HeaderDotHash/0001.tct.html5 b/test/Golden/TCT/HeaderDotHash/0001.tct.html5 index 3c84770..e10f368 100644 --- a/test/Golden/TCT/HeaderDotHash/0001.tct.html5 +++ b/test/Golden/TCT/HeaderDotHash/0001.tct.html5 @@ -1,2 +1,2 @@ <!DOCTYPE HTML> -<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="././../HeaderColon/0004.tct.html">././../HeaderColon/0004.tct</a></body></html> \ No newline at end of file +<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="./../HeaderColon/0004.tct.html">./../HeaderColon/0004.tct</a></body></html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0001.tct.plain b/test/Golden/TCT/HeaderDotHash/0001.tct.plain index 68dd5ae..9733cc5 100644 --- a/test/Golden/TCT/HeaderDotHash/0001.tct.plain +++ b/test/Golden/TCT/HeaderDotHash/0001.tct.plain @@ -1 +1 @@ -././../HeaderColon/0004.tct +./../HeaderColon/0004.tct diff --git a/test/Golden/TCT/HeaderDotHash/0002.tct.html5 b/test/Golden/TCT/HeaderDotHash/0002.tct.html5 index b0ae7a6..f52a256 100644 --- a/test/Golden/TCT/HeaderDotHash/0002.tct.html5 +++ b/test/Golden/TCT/HeaderDotHash/0002.tct.html5 @@ -1,2 +1,2 @@ <!DOCTYPE HTML> -<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="././0001.tct.html">././0001.tct</a></body></html> \ No newline at end of file +<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="./0001.tct.html">./0001.tct</a></body></html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0002.tct.plain b/test/Golden/TCT/HeaderDotHash/0002.tct.plain index 8d506d6..4000dd5 100644 --- a/test/Golden/TCT/HeaderDotHash/0002.tct.plain +++ b/test/Golden/TCT/HeaderDotHash/0002.tct.plain @@ -1 +1 @@ -././0001.tct +./0001.tct diff --git a/test/Golden/TCT/HeaderDotHash/0003.tct.html5 b/test/Golden/TCT/HeaderDotHash/0003.tct.html5 index 9636682..2f2e6b6 100644 --- a/test/Golden/TCT/HeaderDotHash/0003.tct.html5 +++ b/test/Golden/TCT/HeaderDotHash/0003.tct.html5 @@ -1,4 +1,4 @@ <!DOCTYPE HTML> -<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="././../HeaderColon/0004.tct.html">././../HeaderColon/0004.tct</a></span> -<a id="line-2"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="././../HeaderColon/0005.tct.html">././../HeaderColon/0005.tct</a></span> -<a id="line-3"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="././../HeaderColon/0006.tct.html">././../HeaderColon/0006.tct</a></span></body></html> \ No newline at end of file +<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="./../HeaderColon/0004.tct.html">./../HeaderColon/0004.tct</a></span> +<a id="line-2"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="./../HeaderColon/0005.tct.html">./../HeaderColon/0005.tct</a></span> +<a id="line-3"></a><span class="header header-dash"><span class="header-mark">-</span> </span><span class="header-value"><a class="header-dotslash" href="./../HeaderColon/0006.tct.html">./../HeaderColon/0006.tct</a></span></body></html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0003.tct.plain b/test/Golden/TCT/HeaderDotHash/0003.tct.plain index 7038d48..43bfa98 100644 --- a/test/Golden/TCT/HeaderDotHash/0003.tct.plain +++ b/test/Golden/TCT/HeaderDotHash/0003.tct.plain @@ -1,3 +1,3 @@ -- ././../HeaderColon/0004.tct -- ././../HeaderColon/0005.tct -- ././../HeaderColon/0006.tct +- ./../HeaderColon/0004.tct +- ./../HeaderColon/0005.tct +- ./../HeaderColon/0006.tct diff --git a/test/Golden/TCT/HeaderDotHash/0005.tct.html5 b/test/Golden/TCT/HeaderDotHash/0005.tct.html5 index b36cd70..5b47f4f 100644 --- a/test/Golden/TCT/HeaderDotHash/0005.tct.html5 +++ b/test/Golden/TCT/HeaderDotHash/0005.tct.html5 @@ -1,2 +1,2 @@ <!DOCTYPE HTML> -<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="././0004.tct.html">././0004.tct</a></body></html> \ No newline at end of file +<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><a class="header-dotslash" href="./0004.tct.html">./0004.tct</a></body></html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0005.tct.plain b/test/Golden/TCT/HeaderDotHash/0005.tct.plain index 1cf1c03..2703b06 100644 --- a/test/Golden/TCT/HeaderDotHash/0005.tct.plain +++ b/test/Golden/TCT/HeaderDotHash/0005.tct.plain @@ -1 +1 @@ -././0004.tct +./0004.tct diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct b/test/Golden/TCT/HeaderDotHash/0010.tct new file mode 100644 index 0000000..5a1e1cf --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct @@ -0,0 +1,2 @@ +# text0 +./../HeaderColon/0001.tct diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.ast b/test/Golden/TCT/HeaderDotHash/0010.tct.ast new file mode 100644 index 0000000..8004d15 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.ast @@ -0,0 +1,9 @@ +[ Tree (Cell (NodeHeader (HeaderSection 1)) [test/Golden/TCT/HeaderDotHash/0010.tct#1:1-2:26]) + [ Tree (Cell NodePara [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8]) + [ Tree (Cell (NodeToken (TokenText "text0")) [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8]) [] + ] + , Tree (Cell (NodeHeader (HeaderDotSlash "./../HeaderColon/0001.tct")) [test/Golden/TCT/HeaderDotHash/0010.tct#2:1-2:26]) + [ Tree (Cell (NodeHeader (HeaderColon "code" "")) [test/Golden/TCT/HeaderColon/0001.tct#1:1-1:6,test/Golden/TCT/HeaderDotHash/0010.tct#2:1-2:26]) [] + ] + ] +] \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.html5 b/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.html5 new file mode 100644 index 0000000..814dc56 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.html5 @@ -0,0 +1,40 @@ +<!DOCTYPE HTML> + +<html lang="en"> + <head> + <meta http-equiv="Content-Type" + content="text/html; charset=UTF-8"> + <title>text0</title> + <meta name="generator" + content="https://hackage.haskell.org/package/hdoc"> + <link rel="stylesheet" + type="text/css" + href="style/dtc-html5.css"> + </head> + <body> + <div class="document-head"> + <table> + <tbody> + <tr> + <td class="left"> + <table class="document-headers"> + <tbody> + </tbody> + </table> + </td> + <td class="right"> + <table class="document-authors"> + <tbody> + </tbody> + </table> + </td> + </tr> + </tbody> + </table> + </div> + <div class="title"> + <h1>text0</h1> + </div> + <p class="para"><code></code></p> + </body> +</html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.xml b/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.xml new file mode 100644 index 0000000..26d4ada --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.dtc.en_US.xml @@ -0,0 +1,19 @@ + +<?xml-model type="application/relax-ng-compact-syntax" + href="./schema/dtc.rnc"?> + +<?xml-stylesheet type="text/xsl" + href="./xsl/document.html5.en.xsl"?> + +<?html5-stylesheet type="text/xsl" + href="./xsl/document.html5.en.xsl"?> + +<?atom-stylesheet type="text/xsl" + href="./xsl/document.atom.en.xsl"?> + +<document> + <about> + <title>text0</title> + </about> + <p><code></code></p> +</document> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.dump b/test/Golden/TCT/HeaderDotHash/0010.tct.dump new file mode 100644 index 0000000..24f76a0 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.dump @@ -0,0 +1,10 @@ +Cell (NodeHeader (HeaderSection 1)) [test/Golden/TCT/HeaderDotHash/0010.tct#1:1-2:26] +| ++- Cell NodePara [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8] +| | +| `- Cell (NodeToken (TokenText "text0")) [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8] +| +`- Cell (NodeHeader (HeaderDotSlash "./../HeaderColon/0001.tct")) [test/Golden/TCT/HeaderDotHash/0010.tct#2:1-2:26] + | + `- Cell (NodeHeader (HeaderColon "code" "")) [test/Golden/TCT/HeaderColon/0001.tct#1:1-1:6,test/Golden/TCT/HeaderDotHash/0010.tct#2:1-2:26] + diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.html5 b/test/Golden/TCT/HeaderDotHash/0010.tct.html5 new file mode 100644 index 0000000..d385081 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.html5 @@ -0,0 +1,3 @@ +<!DOCTYPE HTML> +<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title> text0</title><link rel="stylesheet" type="text/css" href="style/tct-html5.css"></head><body><a id="line-1"></a><section><span class="section-title"><span class="section-mark">#</span><h1> text0</h1></span> +<a id="line-2"></a><a class="header-dotslash" href="./../HeaderColon/0001.tct.html">./../HeaderColon/0001.tct</a></section></body></html> \ No newline at end of file diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.plain b/test/Golden/TCT/HeaderDotHash/0010.tct.plain new file mode 100644 index 0000000..5a1e1cf --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.plain @@ -0,0 +1,2 @@ +# text0 +./../HeaderColon/0001.tct diff --git a/test/Golden/TCT/HeaderDotHash/0010.tct.xml b/test/Golden/TCT/HeaderDotHash/0010.tct.xml new file mode 100644 index 0000000..1dd32a7 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.tct.xml @@ -0,0 +1,8 @@ +Cell (XmlElem about) [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8] +| +`- Cell (XmlElem title) [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8] + | + `- Cell (XmlText "text0") [test/Golden/TCT/HeaderDotHash/0010.tct#1:3-1:8] + +Cell (XmlElem code) [test/Golden/TCT/HeaderColon/0001.tct#1:1-1:6,test/Golden/TCT/HeaderDotHash/0010.tct#2:1-2:26] + diff --git a/test/Golden/TCT/HeaderDotHash/0010.txt b/test/Golden/TCT/HeaderDotHash/0010.txt new file mode 100644 index 0000000..163b344 --- /dev/null +++ b/test/Golden/TCT/HeaderDotHash/0010.txt @@ -0,0 +1,2 @@ +# text0 +./../HeaderColon/0001.tct \ No newline at end of file -- 2.47.2