HTML writer: Retain ID attribute in highlighted code blocks.
This commit is contained in:
parent
f0e0e1e5d4
commit
1a22e75352
1 changed files with 5 additions and 2 deletions
|
@ -36,6 +36,7 @@ import Text.Highlighting.Kate ( languages, highlightAs, formatAsHtml, FormatOpti
|
|||
import Data.List (find)
|
||||
import Data.Maybe (fromMaybe)
|
||||
import Data.Char (toLower)
|
||||
import qualified Text.Blaze.Html5.Attributes as A
|
||||
|
||||
highlightHtml :: Bool -- ^ True if inline HTML
|
||||
-> Attr -- ^ Attributes of the Code or CodeBlock
|
||||
|
@ -52,12 +53,14 @@ highlightHtml inline (id', classes, keyvals) rawCode =
|
|||
Just _ -> [OptNumberLines]
|
||||
addBirdTracks = "literate" `elem` classes
|
||||
lcLanguages = map (map toLower) languages
|
||||
addId = if null id' then id else (! A.id (toValue id'))
|
||||
in case find (\c -> (map toLower c) `elem` lcLanguages) classes of
|
||||
Nothing -> Left "Unknown or unsupported language"
|
||||
Just language -> case highlightAs language rawCode of
|
||||
Left err -> Left err
|
||||
Right hl -> Right $ formatAsHtml fmtOpts language $
|
||||
if addBirdTracks
|
||||
Right hl -> Right $ addId
|
||||
$ formatAsHtml fmtOpts language
|
||||
$ if addBirdTracks
|
||||
then map (("ot","> "):) hl
|
||||
else hl
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue