packages feed

skylighting 0.3.4 → 0.3.4.1

raw patch · 3 files changed

+52/−45 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

changelog.md view
@@ -1,5 +1,10 @@ # Revision history for skylighting +## 0.3.4.1 -- 2017-09-09++  * HTML formatting: do not use `div` elements for source+    lines in inline output.+ ## 0.3.4 -- 2017-09-09    * HTML formatting changes (David Baynard).  Note that these
skylighting.cabal view
@@ -1,5 +1,5 @@ name:                skylighting-version:             0.3.4+version:             0.3.4.1 synopsis:            syntax highlighting library description:         Skylighting is a syntax highlighting library with                      support for over one hundred languages.  It derives
src/Skylighting/Format/HTML.hs view
@@ -47,13 +47,53 @@ -- 'WarningTok'        = @wa@. -- A 'NormalTok' is not marked up at all. formatHtmlInline :: FormatOptions -> [SourceLine] -> Html-formatHtmlInline opts = (H.code ! A.class_ (toValue $ Text.unwords-                                                    $ Text.pack "sourceCode"-                                                      : codeClasses opts))-                                . mconcat . intersperse (toHtml "\n")-                                . zipWith (sourceLineToHtml opts) [startNum..]-   where startNum = LineNo $ startNumber opts+formatHtmlInline opts = wrapCode opts+                      . mconcat . intersperse (toHtml "\n")+                      . map (mapM_ (tokenToHtml opts)) +-- | Format tokens as an HTML @pre@ block. Each line is wrapped in a div+-- with the class ‘source-line’. The whole code block is wrapped in a @div@+-- element to aid styling (e.g. the overflow-x property). If line numbering+-- is selected, this surrounding div is given the class ‘number-source’,+-- and the resulting html will display line numbers thanks to the included+-- css. Note that the html produced will always include the line numbers as+-- the 'data-line-number' attribute.+-- See the documentation for 'formatHtmlInline' for information about how+-- tokens are encoded.+formatHtmlBlock :: FormatOptions -> [SourceLine] -> Html+formatHtmlBlock opts ls = H.div ! A.class_ sourceCode $+                            pre ! A.class_ (toValue $ Text.unwords classes)+  where  sourceCode = toValue . Text.unwords $ Text.pack "sourceCode" :+                      if numberLines opts+                        then [Text.pack "numberSource"]+                        else []+         classes = Text.pack "sourceCode" :+                   [x | x <- containerClasses opts, x /= Text.pack "sourceCode"]+         startNum = LineNo $ startNumber opts+         pre = H.pre $ wrapCode opts+                     $ mconcat . intersperse (toHtml "\n")+                     $ zipWith (sourceLineToHtml opts) [startNum..] ls++wrapCode :: FormatOptions -> Html -> Html+wrapCode opts h = H.code ! A.class_ (toValue $ Text.unwords+                                             $ Text.pack "sourceCode"+                                               : codeClasses opts) $ h++-- | Each line of source is wrapped in an (inline-block) div that makes+-- subsequent per-line processing (e.g. adding line numnbers) possible.+sourceLineToHtml :: FormatOptions -> LineNo -> SourceLine -> Html+sourceLineToHtml opts lno cont = wrapElement ! A.class_ sourceLine+                                       ! A.id lineNum+                                       ! A.href lineRef+                                       ! H.dataAttribute (fromString "line-number") lineNum $+                                mapM_ (tokenToHtml opts) cont+  where  sourceLine = toValue "sourceLine"+         lineNum = toValue . show . lineNo $ lno+         lineRef = toValue . ('#':) . show . lineNo $ lno+         wrapElement = if lineAnchors opts+                then H.a+                else H.div+ tokenToHtml :: FormatOptions -> Token -> Html tokenToHtml _ (NormalTok, txt)  = toHtml txt tokenToHtml opts (toktype, txt) =@@ -94,44 +134,6 @@ short InformationTok    = "in" short WarningTok        = "wa" short NormalTok         = ""---- | Each line of source is wrapped in an (inline-block) div that makes--- subsequent per-line processing (e.g. adding line numnbers) possible.-sourceLineToHtml :: FormatOptions -> LineNo -> SourceLine -> Html-sourceLineToHtml opts lno cont = wrapElement ! A.class_ sourceLine-                                       ! A.id lineNum-                                       ! A.href lineRef-                                       ! H.dataAttribute (fromString "line-number") lineNum $-                                mapM_ (tokenToHtml opts) cont-  where  sourceLine = toValue "sourceLine"-         lineNum = toValue . show . lineNo $ lno-         lineRef = toValue . ('#':) . show . lineNo $ lno-         wrapElement = if lineAnchors opts-                then H.a-                else H.div--formatHtmlBlockPre :: FormatOptions -> [SourceLine] -> Html-formatHtmlBlockPre opts = H.pre . formatHtmlInline opts---- | Format tokens as an HTML @pre@ block. Each line is wrapped in a div--- with the class ‘source-line’. The whole code block is wrapped in a @div@--- element to aid styling (e.g. the overflow-x property). If line numbering--- is selected, this surrounding div is given the class ‘number-source’,--- and the resulting html will display line numbers thanks to the included--- css. Note that the html produced will always include the line numbers as--- the 'data-line-number' attribute.--- See the documentation for 'formatHtmlInline' for information about how--- tokens are encoded.-formatHtmlBlock :: FormatOptions -> [SourceLine] -> Html-formatHtmlBlock opts ls = H.div ! A.class_ sourceCode $-                            pre ! A.class_ (toValue $ Text.unwords classes)-  where  sourceCode = toValue . Text.unwords $ Text.pack "sourceCode" :-                      if numberLines opts-                        then [Text.pack "numberSource"]-                        else []-         classes = Text.pack "sourceCode" :-                   [x | x <- containerClasses opts, x /= Text.pack "sourceCode"]-         pre = formatHtmlBlockPre opts ls  -- | Returns CSS for styling highlighted code according to the given style. styleToCss :: Style -> String