Skip to content

Commit

Permalink
Enable all mmark extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Nov 22, 2019
1 parent 9d02ed1 commit 76b9f89
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This release comes with major API refactor. Key changes:
- Remove the following:
- JSON cache
- `Rib.Simple`
- Support for Table of Contents via MMark

## 0.4.1.0

Expand Down
25 changes: 24 additions & 1 deletion src/Rib/Markup/MMark.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}

module Rib.Markup.MMark
Expand All @@ -27,6 +28,7 @@ import qualified Text.Megaparsec as M
import Text.MMark (MMark)
import qualified Text.MMark as MMark
import qualified Text.MMark.Extension as Ext
import qualified Text.MMark.Extension.Common as Ext
import Text.URI (URI)

import Rib.Markup
Expand All @@ -36,7 +38,10 @@ instance Markup MMark where

parseDoc f s = case MMark.parse f s of
Left e -> Left e
Right v -> Right $ Document f v $ MMark.projectYaml v
Right doc ->
let doc' = MMark.useExtensions exts $ useTocExt doc
meta = MMark.projectYaml doc
in Right $ Document f doc' meta

readDoc (Arg k) (Arg f) = do
content <- T.decodeUtf8 <$> BS.readFile f
Expand All @@ -60,3 +65,21 @@ getFirstImg = flip MMark.runScanner $ Fold f Nothing id
Ext.Naked xs -> NE.toList xs
Ext.Paragraph xs -> NE.toList xs
_ -> []

exts :: [MMark.Extension]
exts =
[ Ext.fontAwesome
, Ext.footnotes
, Ext.kbd
, Ext.linkTarget
, Ext.mathJax (Just '$')
, Ext.obfuscateEmail "protected-email"
, Ext.punctuationPrettifier
, Ext.ghcSyntaxHighlighter
, Ext.skylighting
]

useTocExt :: MMark -> MMark
useTocExt doc = MMark.useExtension (Ext.toc "toc" toc) doc
where
toc = MMark.runScanner doc $ Ext.tocScanner (\x -> x > 1 && x < 5)

0 comments on commit 76b9f89

Please sign in to comment.