mirror of
https://github.com/aelve/guide.git
synced 2024-12-25 05:43:32 +03:00
Move highlighting into a separate library
This commit is contained in:
parent
1392ecd785
commit
7b588e7c6e
@ -41,6 +41,7 @@ executable guide
|
|||||||
, base-prelude
|
, base-prelude
|
||||||
, blaze-html >= 0.8.1.1
|
, blaze-html >= 0.8.1.1
|
||||||
, cheapskate
|
, cheapskate
|
||||||
|
, cheapskate-highlight == 0.1.*
|
||||||
, containers >= 0.5
|
, containers >= 0.5
|
||||||
, ekg
|
, ekg
|
||||||
, ekg-core
|
, ekg-core
|
||||||
|
@ -19,7 +19,6 @@ import Control.Monad.Writer
|
|||||||
-- Text
|
-- Text
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text.Lazy as TL
|
|
||||||
-- Parsing
|
-- Parsing
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
-- HTML
|
-- HTML
|
||||||
@ -31,9 +30,8 @@ import Data.Sequence
|
|||||||
-- Markdown
|
-- Markdown
|
||||||
import Cheapskate
|
import Cheapskate
|
||||||
import Cheapskate.Html
|
import Cheapskate.Html
|
||||||
|
import Cheapskate.Highlight
|
||||||
import ShortcutLinks
|
import ShortcutLinks
|
||||||
-- Highlighting
|
|
||||||
import qualified Text.Highlighting.Kate as Kate
|
|
||||||
|
|
||||||
|
|
||||||
blazeToLucid :: Monad m => Blaze.Html -> HtmlT m ()
|
blazeToLucid :: Monad m => Blaze.Html -> HtmlT m ()
|
||||||
@ -77,15 +75,6 @@ shortcutLinks i@(Link is url title) | '@' <- T.head url =
|
|||||||
Str ("[error when processing shortcut link: " <> T.pack err <> "]")
|
Str ("[error when processing shortcut link: " <> T.pack err <> "]")
|
||||||
shortcutLinks other = other
|
shortcutLinks other = other
|
||||||
|
|
||||||
highlight :: Block -> Block
|
|
||||||
highlight (CodeBlock attr code) =
|
|
||||||
HtmlBlock (TL.toStrict (Blaze.renderHtml formatted))
|
|
||||||
where
|
|
||||||
lang = T.unpack (codeLang attr)
|
|
||||||
highlighted = Kate.highlightAs lang (T.unpack code)
|
|
||||||
formatted = Kate.formatHtmlBlock Kate.defaultFormatOpts highlighted
|
|
||||||
highlight other = other
|
|
||||||
|
|
||||||
-- TODO: this should be in the shortcut-links package itself
|
-- TODO: this should be in the shortcut-links package itself
|
||||||
|
|
||||||
-- | Parse a shortcut link. Allowed formats:
|
-- | Parse a shortcut link. Allowed formats:
|
||||||
@ -127,5 +116,5 @@ renderMarkdownLine s = do
|
|||||||
renderMarkdownBlock :: Monad m => Text -> HtmlT m ()
|
renderMarkdownBlock :: Monad m => Text -> HtmlT m ()
|
||||||
renderMarkdownBlock =
|
renderMarkdownBlock =
|
||||||
blazeToLucid . renderDoc .
|
blazeToLucid . renderDoc .
|
||||||
walk highlight . walk shortcutLinks .
|
highlightDoc . walk shortcutLinks .
|
||||||
markdown def
|
markdown def
|
||||||
|
Loading…
Reference in New Issue
Block a user