| Copyright | © 2017 Mark Karpov |
|---|---|
| License | BSD 3 clause |
| Maintainer | Mark Karpov <markkarpov92@gmail.com> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.MMark.Extension.Common
Description
Commonly useful extensions for MMark markdown processor.
We suggest using a qualified import, like this:
import qualified Text.MMark.Extension.Common as Ext
Here is an example that uses several extensions from this module at the same time, it should give you an idea where to start:
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Data.Default.Class
import qualified Data.Text.IO as T
import qualified Data.Text.Lazy.IO as TL
import qualified Lucid as L
import qualified Text.MMark as MMark
import qualified Text.MMark.Extension.Common as Ext
main :: IO ()
main = do
let input = "input.md"
txt <- T.readFile input
case MMark.parse input txt of
Left errs -> putStrLn (MMark.parseErrorsPretty txt errs)
Right r ->
let toc = MMark.runScanner r (Ext.tocScanner 4)
in TL.writeFile "output.html"
. L.renderText
. MMark.render
. MMark.useExtensions
[ Ext.toc "toc" toc
, Ext.punctuationPrettifier def
, Ext.obfuscateEmail "protected-email"
, Ext.fontAwesome ]
$ r- data Toc
- tocScanner :: Int -> Fold Bni Toc
- toc :: Text -> Toc -> Extension
- data Punctuation = Punctuation {
- punctEnDash :: !Bool
- punctEmDash :: !Bool
- punctuationPrettifier :: Punctuation -> Extension
- obfuscateEmail :: Text -> Extension
- fontAwesome :: Extension
Table of contents
Place this markup in markdown document where you want table of contents to be inserted:
```toc ```
You may use something different than "toc" as the info string of the
code block.
An opaque type representing table of contents produced by the
tocScanner scanner.
Arguments
| :: Text | Label of the code block to replace by the table of contents |
| -> Toc | Previously generated by |
| -> Extension |
Create an extension that replaces a certain code block with previously constructed table of contents.
Punctuation prettifier
data Punctuation Source #
Settings for the punctuation-prettifying extension.
Constructors
| Punctuation | |
Fields
| |
Instances
punctuationPrettifier :: Punctuation -> Extension Source #
Prettify punctuation according to the settings in Punctuation.
Email address obfuscation
This extension makes email addresses in links be rendered as something like this:
<a class="protected-email" data-email="something@example.org" href="javascript:void(0)">Enable JavaScript to see the email</a>
You'll also need to include jQuery and this bit of JS code for the magic to work:
$(document).ready(function () {
$(".protected-email").each(function () {
var item = $(this);
var email = item.data('email');
item.attr('href', 'mailto:' + email);
item.html(email);
});
});Font Awesome icons
fontAwesome :: Extension Source #
Allow to insert spans with font awesome icons using autolinks like
this:
<fa:user>
This user identifier is the name of icon you want to insert. You can
also control the size of the icon like this:
<fa:user/fw> -- fixed width <fa:user/lg> -- large <fa:user/2x> <fa:user/3x> <fa:user/4x> <fa:user/5x>
In general, all path components in this URI that go after the name of
icon will be prefixed with "fa-" and added as classes, so you can do
a lot of fancy stuff, see http://fontawesome.io/examples/:
<fa:quote-left/3x/pull-left/border>
See also: http://fontawesome.io.