git.iko.soy/typeable/pandoc
on master help sign in
Fixed highlighting for inline code.

highlightHtml in Highlighting now has a boolean argument that selects between inline and block content. Revised tests for new highlighting-kate.

commit9f28acba9dc43a63172e771b57f8a51b6b738d71 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 29 Jan 2011, 16:04 (16 years ago) parent9e89047
5 files changed+42−34
changelog+4 src/Text/Pandoc/Highlighting.hs+6−2 src/Text/Pandoc/Writers/HTML.hs+2−2 tests/lhs-test.html+15−15 tests/lhs-test.html+lhs+15−15
changelog+4
@@ -169,6 +169,10 @@ pandoc (1.8)
169169 * Added support for `lang` in `html` tag in the HTML template,
170170 so you can do `pandoc -s -V lang=es`, for example.
171171
172+ * `highlightHtml` in `Text.Pandoc.Highlighting` now takes
173+ a boolean argument that selects between "inline" and
174+ "block" HTML.
175+
172176 * `Text.Pandoc.Writers.RTF` now exports `rtfEmbedImage`.
173177 Images are embedded in RTF output when possible (png, jpeg).
174178 Resolves Issue #275.
src/Text/Pandoc/Highlighting.hs+6−2
@@ -37,10 +37,14 @@ import Data.List (find)
3737import Data.Maybe (fromMaybe)
3838import Data.Char (toLower)
3939
40−highlightHtml :: Attr -> String -> Either String Html
41−highlightHtml (_, classes, keyvals) rawCode =
40+highlightHtml :: Bool -- ^ True if inline HTML
41+ -> Attr -- ^ Attributes of the Code or CodeBlock
42+ -> String -- ^ Raw contents of the Code or CodeBlock
43+ -> Either String Html -- ^ An error or the formatted Html
44+highlightHtml inline (_, classes, keyvals) rawCode =
4245 let firstNum = read $ fromMaybe "1" $ lookup "startFrom" keyvals
4346 fmtOpts = [OptNumberFrom firstNum] ++
47+ [OptInline | inline] ++
4448 case find (`elem` ["number","numberLines","number-lines"]) classes of
4549 Nothing -> []
4650 Just _ -> [OptNumberLines]
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -324,7 +324,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do
324324 let classes' = if writerLiterateHaskell opts
325325 then classes
326326 else filter (/= "literate") classes
327− case highlightHtml (id',classes',keyvals) rawCode of
327+ case highlightHtml False (id',classes',keyvals) rawCode of
328328 Left _ -> -- change leading newlines into <br /> tags, because some
329329 -- browsers ignore leading newlines in pre blocks
330330 let (leadingBreaks, rawCode') = span (=='\n') rawCode
@@ -484,7 +484,7 @@ inlineToHtml opts inline =
484484 (Emph lst) -> inlineListToHtml opts lst >>= return . emphasize
485485 (Strong lst) -> inlineListToHtml opts lst >>= return . strong
486486 (Code attr str) -> return $ thecode ! (attrsToHtml opts attr) << str'
487− where str' = case highlightHtml attr str of
487+ where str' = case highlightHtml True attr str of
488488 Left _ -> stringToHtml str
489489 Right h -> h
490490 (Strikeout lst) -> inlineListToHtml opts lst >>=
tests/lhs-test.html+15−15
@@ -9,19 +9,19 @@ table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode
99 { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
1010td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
1111td.sourceCode { padding-left: 5px; }
12−pre.sourceCode span.kw { color: #007020; font-weight: bold; }
13−pre.sourceCode span.dt { color: #902000; }
14−pre.sourceCode span.dv { color: #40a070; }
15−pre.sourceCode span.bn { color: #40a070; }
16−pre.sourceCode span.fl { color: #40a070; }
17−pre.sourceCode span.ch { color: #4070a0; }
18−pre.sourceCode span.st { color: #4070a0; }
19−pre.sourceCode span.co { color: #60a0b0; font-style: italic; }
20−pre.sourceCode span.ot { color: #007020; }
21−pre.sourceCode span.al { color: red; font-weight: bold; }
22−pre.sourceCode span.fu { color: #06287e; }
23−pre.sourceCode span.re { }
24−pre.sourceCode span.er { color: red; font-weight: bold; }
12+code.sourceCode span.kw { color: #007020; font-weight: bold; }
13+code.sourceCode span.dt { color: #902000; }
14+code.sourceCode span.dv { color: #40a070; }
15+code.sourceCode span.bn { color: #40a070; }
16+code.sourceCode span.fl { color: #40a070; }
17+code.sourceCode span.ch { color: #4070a0; }
18+code.sourceCode span.st { color: #4070a0; }
19+code.sourceCode span.co { color: #60a0b0; font-style: italic; }
20+code.sourceCode span.ot { color: #007020; }
21+code.sourceCode span.al { color: red; font-weight: bold; }
22+code.sourceCode span.fu { color: #06287e; }
23+code.sourceCode span.re { }
24+code.sourceCode span.er { color: red; font-weight: bold; }
2525 </style>
2626</head>
2727<body>
@@ -31,8 +31,8 @@ pre.sourceCode span.er { color: red; font-weight: bold; }
3131><code
3232 >unsplit</code
3333 > is an arrow that takes a pair of values and combines them to return a single value:</p
34−><pre class="sourceCode haskell"
35−><code
34+><pre class="sourceCode"
35+><code class="sourceCode haskell"
3636 ><span class="ot"
3737 >unsplit </span
3838 ><span class="ot"
tests/lhs-test.html+lhs+15−15
@@ -9,19 +9,19 @@ table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode, table.sourceCode
99 { margin: 0; padding: 0; border: 0; vertical-align: baseline; border: none; }
1010td.lineNumbers { border-right: 1px solid #AAAAAA; text-align: right; color: #AAAAAA; padding-right: 5px; padding-left: 5px; }
1111td.sourceCode { padding-left: 5px; }
12−pre.sourceCode span.kw { color: #007020; font-weight: bold; }
13−pre.sourceCode span.dt { color: #902000; }
14−pre.sourceCode span.dv { color: #40a070; }
15−pre.sourceCode span.bn { color: #40a070; }
16−pre.sourceCode span.fl { color: #40a070; }
17−pre.sourceCode span.ch { color: #4070a0; }
18−pre.sourceCode span.st { color: #4070a0; }
19−pre.sourceCode span.co { color: #60a0b0; font-style: italic; }
20−pre.sourceCode span.ot { color: #007020; }
21−pre.sourceCode span.al { color: red; font-weight: bold; }
22−pre.sourceCode span.fu { color: #06287e; }
23−pre.sourceCode span.re { }
24−pre.sourceCode span.er { color: red; font-weight: bold; }
12+code.sourceCode span.kw { color: #007020; font-weight: bold; }
13+code.sourceCode span.dt { color: #902000; }
14+code.sourceCode span.dv { color: #40a070; }
15+code.sourceCode span.bn { color: #40a070; }
16+code.sourceCode span.fl { color: #40a070; }
17+code.sourceCode span.ch { color: #4070a0; }
18+code.sourceCode span.st { color: #4070a0; }
19+code.sourceCode span.co { color: #60a0b0; font-style: italic; }
20+code.sourceCode span.ot { color: #007020; }
21+code.sourceCode span.al { color: red; font-weight: bold; }
22+code.sourceCode span.fu { color: #06287e; }
23+code.sourceCode span.re { }
24+code.sourceCode span.er { color: red; font-weight: bold; }
2525 </style>
2626</head>
2727<body>
@@ -31,8 +31,8 @@ pre.sourceCode span.er { color: red; font-weight: bold; }
3131><code
3232 >unsplit</code
3333 > is an arrow that takes a pair of values and combines them to return a single value:</p
34−><pre class="sourceCode haskell"
35−><code
34+><pre class="sourceCode"
35+><code class="sourceCode haskell"
3636 >&gt; <span class="ot"
3737 >unsplit </span
3838 ><span class="ot"