git.iko.soy/typeable/pandoc
on master help sign in
Removed superfluous sourceCode class on code blocks.

* These were added by the RST reader and, for literate Haskell, by the Markdown and LaTeX readers. There is no point to this class, and it is not applied consistently by all readers. See #5047. * Reverse order of `literate` and `haskell` classes on code blocks when parsing literate Haskell. Better if `haskell` comes first.

commit8673eb079bc389f340bafd4c191c642afc7e1603 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 8 Jan 2019, 11:36 (8 years ago) parent230e07d
12 files changed+25−29
src/Text/Pandoc/Readers/LaTeX.hs+1−2 src/Text/Pandoc/Readers/Markdown.hs+2−2 src/Text/Pandoc/Readers/RST.hs+4−7 test/Tests/Readers/Markdown.hs+2−2 test/Tests/Readers/RST.hs+6−6 test/command/4811.md+1−1 test/lhs-test-markdown.native+1−1 test/lhs-test.html+1−1 test/lhs-test.html+lhs+1−1 test/lhs-test.markdown+1−1 test/lhs-test.native+1−1 test/rst-reader.native+4−4
src/Text/Pandoc/Readers/LaTeX.hs+1−2
@@ -1823,8 +1823,7 @@ environments = M.fromList
18231823 , ("enumerate", orderedList')
18241824 , ("alltt", alltt <$> env "alltt" blocks)
18251825 , ("code", guardEnabled Ext_literate_haskell *>
1826− (codeBlockWith ("",["sourceCode","literate","haskell"],[]) <$>
1827− verbEnv "code"))
1826+ (codeBlockWith ("",["haskell","literate"],[]) <$> verbEnv "code"))
18281827 , ("comment", mempty <$ verbEnv "comment")
18291828 , ("verbatim", codeBlock <$> verbEnv "verbatim")
18301829 , ("Verbatim", fancyverbEnv "Verbatim")
src/Text/Pandoc/Readers/Markdown.hs+2−2
@@ -748,9 +748,9 @@ codeBlockIndented = do
748748lhsCodeBlock :: PandocMonad m => MarkdownParser m (F Blocks)
749749lhsCodeBlock = do
750750 guardEnabled Ext_literate_haskell
751− (return . B.codeBlockWith ("",["sourceCode","literate","haskell"],[]) <$>
751+ (return . B.codeBlockWith ("",["haskell","literate"],[]) <$>
752752 (lhsCodeBlockBird <|> lhsCodeBlockLaTeX))
753− <|> (return . B.codeBlockWith ("",["sourceCode","haskell"],[]) <$>
753+ <|> (return . B.codeBlockWith ("",["haskell"],[]) <$>
754754 lhsCodeBlockInverseBird)
755755
756756lhsCodeBlockLaTeX :: PandocMonad m => MarkdownParser m String
src/Text/Pandoc/Readers/RST.hs+4−7
@@ -39,7 +39,7 @@ import Control.Monad.Except (throwError)
3939import Control.Monad.Identity (Identity (..))
4040import Data.Char (isHexDigit, isSpace, toLower, toUpper, isAlphaNum)
4141import Data.List (deleteFirstsBy, elemIndex, intercalate, isInfixOf, isSuffixOf,
42− nub, sort, transpose, union)
42+ nub, sort, transpose)
4343import qualified Data.Map as M
4444import Data.Maybe (fromMaybe, isJust)
4545import Data.Sequence (ViewR (..), viewr)
@@ -421,7 +421,7 @@ lhsCodeBlock = try $ do
421421 optional codeBlockStart
422422 lns <- latexCodeBlock <|> birdCodeBlock
423423 blanklines
424− return $ B.codeBlockWith ("", ["sourceCode", "literate", "haskell"], [])
424+ return $ B.codeBlockWith ("", ["haskell","literate"], [])
425425 $ intercalate "\n" lns
426426
427427latexCodeBlock :: Monad m => ParserT [Char] st m [[Char]]
@@ -995,7 +995,7 @@ codeblock :: String -> [String] -> Maybe String -> String -> String
995995codeblock ident classes numberLines lang body =
996996 return $ B.codeBlockWith attribs $ stripTrailingNewlines body
997997 where attribs = (ident, classes', kvs)
998− classes' = "sourceCode" : lang
998+ classes' = lang
999999 : maybe [] (const ["numberLines"]) numberLines
10001000 ++ classes
10011001 kvs = case numberLines of
@@ -1414,7 +1414,7 @@ renderRole contents fmt role attr = case role of
14141414 "title-reference" -> titleRef contents
14151415 "title" -> titleRef contents
14161416 "t" -> titleRef contents
1417− "code" -> return $ B.codeWith (addClass "sourceCode" attr) contents
1417+ "code" -> return $ B.codeWith attr contents
14181418 "span" -> return $ B.spanWith attr $ treatAsText contents
14191419 "raw" -> return $ B.rawInline (fromMaybe "" fmt) contents
14201420 custom -> do
@@ -1438,9 +1438,6 @@ renderRole contents fmt role attr = case role of
14381438 handleEscapes ('\\':c:cs) = c : handleEscapes cs
14391439 handleEscapes (c:cs) = c : handleEscapes cs
14401440
1441−addClass :: String -> Attr -> Attr
1442−addClass c (ident, classes, keyValues) = (ident, classes `union` [c], keyValues)
1443−
14441441roleName :: PandocMonad m => RSTParser m String
14451442roleName = many1 (letter <|> char '-')
14461443
test/Tests/Readers/Markdown.hs+2−2
@@ -319,9 +319,9 @@ tests = [ testGroup "inline code"
319319 Ext_literate_haskell pandocExtensions })
320320 "inverse bird tracks and html" $
321321 "> a\n\n< b\n\n<div>\n"
322− =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
322+ =?> codeBlockWith ("",["haskell","literate"],[]) "a"
323323 <>
324− codeBlockWith ("",["sourceCode","haskell"],[]) "b"
324+ codeBlockWith ("",["haskell"],[]) "b"
325325 <>
326326 rawBlock "html" "<div>\n\n"
327327 ]
test/Tests/Readers/RST.hs+6−6
@@ -106,7 +106,7 @@ tests = [ "line block with blank line" =:
106106 ] =?>
107107 doc (codeBlockWith
108108 ( ""
109− , ["sourceCode", "python", "numberLines", "class1", "class2", "class3"]
109+ , ["python", "numberLines", "class1", "class2", "class3"]
110110 , [ ("startFrom", "34") ]
111111 )
112112 "def func(x):\n return y")
@@ -119,7 +119,7 @@ tests = [ "line block with blank line" =:
119119 ] =?>
120120 doc (codeBlockWith
121121 ( ""
122− , ["sourceCode", "python", "numberLines"]
122+ , ["python", "numberLines"]
123123 , [ ("startFrom", "") ]
124124 )
125125 "def func(x):\n return y")
@@ -164,18 +164,18 @@ tests = [ "line block with blank line" =:
164164 [ "literal role prefix" =: ":literal:`a`" =?> para (code "a")
165165 , "literal role postfix" =: "`a`:literal:" =?> para (code "a")
166166 , "literal text" =: "``text``" =?> para (code "text")
167− , "code role" =: ":code:`a`" =?> para (codeWith ("", ["sourceCode"], []) "a")
167+ , "code role" =: ":code:`a`" =?> para (codeWith ("", [], []) "a")
168168 , "inherited code role" =: ".. role:: codeLike(code)\n\n:codeLike:`a`"
169− =?> para (codeWith ("", ["codeLike", "sourceCode"], []) "a")
169+ =?> para (codeWith ("", ["codeLike"], []) "a")
170170 , "custom code role with language field"
171171 =: ".. role:: lhs(code)\n :language: haskell\n\n:lhs:`a`"
172− =?> para (codeWith ("", ["lhs", "haskell","sourceCode"], []) "a")
172+ =?> para (codeWith ("", ["lhs", "haskell"], []) "a")
173173 , "custom role with unspecified parent role"
174174 =: ".. role:: classy\n\n:classy:`text`"
175175 =?> para (spanWith ("", ["classy"], []) "text")
176176 , "role with recursive inheritance"
177177 =: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
178− =?> para (codeWith ("", ["lhs", "haskell", "sourceCode"], []) "text")
178+ =?> para (codeWith ("", ["lhs", "haskell"], []) "text")
179179 , "unknown role" =: ":unknown:`text`" =?>
180180 para (codeWith ("",["interpreted-text"],[("role","unknown")]) "text")
181181 ]
test/command/4811.md+1−1
@@ -19,7 +19,7 @@ Backslash escape behaves properly in interpreted roles:
1919`hi\ there`:code:
2020^D
2121[Para [Superscript [Str "hithere"]]
22−,Para [Code ("",["sourceCode"],[]) "hi\\ there"]]
22+,Para [Code ("",[],[]) "hi\\ there"]]
2323```
2424
2525Backtick followed by alphanumeric doesn't end the span:
test/lhs-test-markdown.native+1−1
@@ -1,6 +1,6 @@
11[Header 1 ("lhs-test",[],[]) [Str "lhs",Space,Str "test"]
22,Para [Code ("",[],[]) "unsplit",Space,Str "is",Space,Str "an",Space,Str "arrow",Space,Str "that",Space,Str "takes",Space,Str "a",Space,Str "pair",Space,Str "of",Space,Str "values",Space,Str "and",Space,Str "combines",Space,Str "them",Space,Str "to",SoftBreak,Str "return",Space,Str "a",Space,Str "single",Space,Str "value:"]
3−,CodeBlock ("",["sourceCode","literate","haskell"],[]) "unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d\nunsplit = arr . uncurry\n -- arr (\\op (x,y) -> x `op` y)"
3+,CodeBlock ("",["haskell","literate"],[]) "unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d\nunsplit = arr . uncurry\n -- arr (\\op (x,y) -> x `op` y)"
44,Para [Code ("",[],[]) "(***)",Space,Str "combines",Space,Str "two",Space,Str "arrows",Space,Str "into",Space,Str "a",Space,Str "new",Space,Str "arrow",Space,Str "by",Space,Str "running",Space,Str "the",Space,Str "two",Space,Str "arrows",Space,Str "on",Space,Str "a",SoftBreak,Str "pair",Space,Str "of",Space,Str "values",Space,Str "(one",Space,Str "arrow",Space,Str "on",Space,Str "the",Space,Str "first",Space,Str "item",Space,Str "of",Space,Str "the",Space,Str "pair",Space,Str "and",Space,Str "one",Space,Str "arrow",Space,Str "on",Space,Str "the",SoftBreak,Str "second",Space,Str "item",Space,Str "of",Space,Str "the",Space,Str "pair)."]
55,CodeBlock ("",[],[]) "f *** g = first f >>> second g"
66,Para [Str "Block",Space,Str "quote:"]
test/lhs-test.html+1−1
@@ -82,7 +82,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
8282<h1 id="lhs-test">lhs test</h1>
8383<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to
8484return a single value:</p>
85−<div class="sourceCode" id="cb1"><pre class="sourceCode literate haskell"><code class="sourceCode haskell"><a class="sourceLine" id="cb1-1" title="1"><span class="ot">unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d</a>
85+<div class="sourceCode" id="cb1"><pre class="sourceCode haskell literate"><code class="sourceCode haskell"><a class="sourceLine" id="cb1-1" title="1"><span class="ot">unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d</a>
8686<a class="sourceLine" id="cb1-2" title="2">unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span></a>
8787<a class="sourceLine" id="cb1-3" title="3"> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></a></code></pre></div>
8888<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a
test/lhs-test.html+lhs+1−1
@@ -82,7 +82,7 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
8282<h1 id="lhs-test">lhs test</h1>
8383<p><code>unsplit</code> is an arrow that takes a pair of values and combines them to
8484return a single value:</p>
85−<div class="sourceCode" id="cb1"><pre class="sourceCode literate literatehaskell"><code class="sourceCode literatehaskell"><a class="sourceLine" id="cb1-1" title="1"><span class="ot">&gt; unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d</a>
85+<div class="sourceCode" id="cb1"><pre class="sourceCode literatehaskell literate"><code class="sourceCode literatehaskell"><a class="sourceLine" id="cb1-1" title="1"><span class="ot">&gt; unsplit ::</span> (<span class="dt">Arrow</span> a) <span class="ot">=&gt;</span> (b <span class="ot">-&gt;</span> c <span class="ot">-&gt;</span> d) <span class="ot">-&gt;</span> a (b, c) d</a>
8686<a class="sourceLine" id="cb1-2" title="2"><span class="ot">&gt;</span> unsplit <span class="fu">=</span> arr <span class="fu">.</span> <span class="fu">uncurry</span></a>
8787<a class="sourceLine" id="cb1-3" title="3"><span class="ot">&gt;</span> <span class="co">-- arr (\op (x,y) -&gt; x `op` y)</span></a></code></pre></div>
8888<p><code>(***)</code> combines two arrows into a new arrow by running the two arrows on a
test/lhs-test.markdown+1−1
@@ -4,7 +4,7 @@ lhs test
44`unsplit` is an arrow that takes a pair of values and combines them to
55return a single value:
66
7−``` {.sourceCode .literate .haskell}
7+``` {.haskell .literate}
88unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
99unsplit = arr . uncurry
1010 -- arr (\op (x,y) -> x `op` y)
test/lhs-test.native+1−1
@@ -1,6 +1,6 @@
11[Header 1 ("lhs-test",[],[]) [Str "lhs",Space,Str "test"]
22,Para [Code ("",[],[]) "unsplit",Space,Str "is",Space,Str "an",Space,Str "arrow",Space,Str "that",Space,Str "takes",Space,Str "a",Space,Str "pair",Space,Str "of",Space,Str "values",Space,Str "and",Space,Str "combines",Space,Str "them",Space,Str "to",SoftBreak,Str "return",Space,Str "a",Space,Str "single",Space,Str "value:"]
3−,CodeBlock ("",["sourceCode","literate","haskell"],[]) "unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d\nunsplit = arr . uncurry\n -- arr (\\op (x,y) -> x `op` y)"
3+,CodeBlock ("",["haskell","literate"],[]) "unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d\nunsplit = arr . uncurry\n -- arr (\\op (x,y) -> x `op` y)"
44,Para [Code ("",[],[]) "(***)",Space,Str "combines",Space,Str "two",Space,Str "arrows",Space,Str "into",Space,Str "a",Space,Str "new",Space,Str "arrow",Space,Str "by",Space,Str "running",Space,Str "the",Space,Str "two",Space,Str "arrows",Space,Str "on",Space,Str "a",SoftBreak,Str "pair",Space,Str "of",Space,Str "values",Space,Str "(one",Space,Str "arrow",Space,Str "on",Space,Str "the",Space,Str "first",Space,Str "item",Space,Str "of",Space,Str "the",Space,Str "pair",Space,Str "and",Space,Str "one",Space,Str "arrow",Space,Str "on",Space,Str "the",SoftBreak,Str "second",Space,Str "item",Space,Str "of",Space,Str "the",Space,Str "pair)."]
55,CodeBlock ("",[],[]) "f *** g = first f >>> second g"
66,Para [Str "Block",Space,Str "quote:"]
test/rst-reader.native+4−4
@@ -38,7 +38,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
3838,Para [Str "And:"]
3939,CodeBlock ("",[],[]) "this block is indented by two tabs\n\nThese should not be escaped: \\$ \\\\ \\> \\[ \\{"
4040,Para [Str "And:"]
41−,CodeBlock ("",["sourceCode","python"],[]) "def my_function(x):\n return x + 1"
41+,CodeBlock ("",["python"],[]) "def my_function(x):\n return x + 1"
4242,Header 1 ("lists",[],[]) [Str "Lists"]
4343,Header 2 ("unordered",[],[]) [Str "Unordered"]
4444,Para [Str "Asterisks",Space,Str "tight:"]
@@ -328,8 +328,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
328328,Para [Str "Reset",Space,Str "default-role",Space,Str "to",Space,Str "the",Space,Str "default",Space,Str "default."]
329329,Para [Str "And",Space,Str "now",Space,Span ("",["title-ref"],[]) [Str "some-invalid-string-3231231"],Space,Str "is",Space,Str "nonsense."]
330330,Para [Str "And",Space,Str "now",Space,Str "with",Space,RawInline (Format "html") "<b>inline</b> <span id=\"test\">HTML</span>",Str "."]
331−,Para [Str "And",Space,Str "some",Space,Str "inline",Space,Str "haskell",Space,Code ("",["haskell","sourceCode"],[]) "fmap id [1,2..10]",Str "."]
332−,Para [Str "Indirect",Space,Str "python",Space,Str "role",Space,Code ("",["py","python","indirect","sourceCode"],[]) "[x*x for x in [1,2,3,4,5]]",Str "."]
333−,Para [Str "Different",Space,Str "indirect",Space,Str "C",Space,Code ("",["c","different-indirect","sourceCode"],[]) "int x = 15;",Str "."]
331+,Para [Str "And",Space,Str "some",Space,Str "inline",Space,Str "haskell",Space,Code ("",["haskell"],[]) "fmap id [1,2..10]",Str "."]
332+,Para [Str "Indirect",Space,Str "python",Space,Str "role",Space,Code ("",["py","python","indirect"],[]) "[x*x for x in [1,2,3,4,5]]",Str "."]
333+,Para [Str "Different",Space,Str "indirect",Space,Str "C",Space,Code ("",["c","different-indirect"],[]) "int x = 15;",Str "."]
334334,Header 2 ("literal-symbols",[],[]) [Str "Literal",Space,Str "symbols"]
335335,Para [Str "2*2",Space,Str "=",Space,Str "4*1"]]