diff --git a/pandoc.cabal b/pandoc.cabal index a52f89492ca2..322a6bcaa465 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -320,7 +320,7 @@ library tagsoup >= 0.13.7 && < 0.15, base64-bytestring >= 0.1 && < 1.1, zlib >= 0.5 && < 0.7, - skylighting >= 0.4.2 && <0.5, + skylighting >= 0.4.3 && <0.5, data-default >= 0.4 && < 0.8, temporary >= 1.1 && < 1.3, blaze-html >= 0.5 && < 0.10, diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs index cc72967e4410..cd8c5fd4bfc3 100644 --- a/src/Text/Pandoc/Highlighting.hs +++ b/src/Text/Pandoc/Highlighting.hs @@ -81,12 +81,15 @@ highlight :: SyntaxMap -> Attr -- ^ Attributes of the CodeBlock -> String -- ^ Raw contents of the CodeBlock -> Either String a -highlight syntaxmap formatter (_, classes, keyvals) rawCode = +highlight syntaxmap formatter (ident, classes, keyvals) rawCode = let firstNum = fromMaybe 1 (safeRead (fromMaybe "1" $ lookup "startFrom" keyvals)) fmtOpts = defaultFormatOpts{ startNumber = firstNum, numberLines = any (`elem` - ["number","numberLines", "number-lines"]) classes } + ["number","numberLines", "number-lines"]) classes, + lineIdPrefix = if null ident + then mempty + else T.pack (ident ++ "-") } tokenizeOpts = TokenizerConfig{ syntaxMap = syntaxmap , traceOutput = False } classes' = map T.pack classes diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 89cec38a2700..1999bdbcf1d4 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -101,6 +101,7 @@ data WriterState = WriterState , stHtml5 :: Bool -- ^ Use HTML5 , stEPUBVersion :: Maybe EPUBVersion -- ^ EPUB version if for epub , stSlideVariant :: HTMLSlideVariant + , stCodeBlockNum :: Int -- ^ Number of code block } defaultWriterState :: WriterState @@ -108,7 +109,8 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False, stHighlighting = False, stSecNum = [], stElement = False, stHtml5 = False, stEPUBVersion = Nothing, - stSlideVariant = NoSlides} + stSlideVariant = NoSlides, + stCodeBlockNum = 0} -- Helpers to render HTML with the appropriate function. @@ -703,6 +705,12 @@ blockToHtml _ HorizontalRule = do html5 <- gets stHtml5 return $ if html5 then H5.hr else H.hr blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do + id'' <- if null id' + then do + modify $ \st -> st{ stCodeBlockNum = stCodeBlockNum st + 1 } + codeblocknum <- gets stCodeBlockNum + return ("cb" ++ show codeblocknum) + else return id' let tolhs = isEnabled Ext_literate_haskell opts && any (\c -> map toLower c == "haskell") classes && any (\c -> map toLower c == "literate") classes @@ -716,7 +724,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do else rawCode hlCode = if isJust (writerHighlightStyle opts) then highlight (writerSyntaxMap opts) formatHtmlBlock - (id',classes',keyvals) adjCode + (id'',classes',keyvals) adjCode else Left "" case hlCode of Left msg -> do @@ -725,7 +733,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do addAttrs opts (id',classes,keyvals) $ H.pre $ H.code $ toHtml adjCode Right h -> modify (\st -> st{ stHighlighting = True }) >> - addAttrs opts (id',[],keyvals) h + addAttrs opts (id'',[],keyvals) h blockToHtml opts (BlockQuote blocks) = do -- in S5, treat list in blockquote specially -- if default is incremental, make it nonincremental; diff --git a/stack.yaml b/stack.yaml index 5e25529f5393..da5869ff32dc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -9,7 +9,7 @@ packages: extra-deps: - pandoc-types-1.17.2 - hslua-0.9.2 -- skylighting-0.4.2 +- skylighting-0.4.3 - cmark-gfm-0.1.1 - QuickCheck-2.10.0.1 - tasty-quickcheck-0.9.1 diff --git a/test/lhs-test.html b/test/lhs-test.html index 28cfdf7a4194..a921c6a568c5 100644 --- a/test/lhs-test.html +++ b/test/lhs-test.html @@ -72,9 +72,9 @@

lhs test

unsplit is an arrow that takes a pair of values and combines them to return a single value:

-
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
-
unsplit = arr . uncurry
-
-- arr (\op (x,y) -> x `op` y)
+
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
+
unsplit = arr . uncurry
+
-- arr (\op (x,y) -> x `op` y)

(***) combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).

diff --git a/test/lhs-test.html+lhs b/test/lhs-test.html+lhs index f7a8302a4e8f..8d27e6a58ed4 100644 --- a/test/lhs-test.html+lhs +++ b/test/lhs-test.html+lhs @@ -72,9 +72,9 @@ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Infor

lhs test

unsplit is an arrow that takes a pair of values and combines them to return a single value:

-
> unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
-
> unsplit = arr . uncurry
-
> -- arr (\op (x,y) -> x `op` y)
+
> unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
+
> unsplit = arr . uncurry
+
> -- arr (\op (x,y) -> x `op` y)

(***) combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).