From 7042c648077dbb84bd3fd34dba7325febfc0e376 Mon Sep 17 00:00:00 2001 From: Nicolas Hery Date: Sun, 9 Sep 2018 16:00:44 -0400 Subject: [PATCH 1/2] Add instructions for usage with Hakyll --- README.md | 37 +++++++++++++++++++++++ README.src.md | 32 ++++++++++++++++++++ docs/index.html | 52 ++++++++++++++++++++++++--------- docs/pandoc-emphasize-code.pdf | Bin 322284 -> 325014 bytes 4 files changed, 108 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 9a93361..cc62c8e 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,43 @@ If you have installed from sources, and you have `~/.local/bin` on your pandoc --filter pandoc-emphasize-code input.md output.html ``` +## Usage with Hakyll + +If you are using the [Hakyll](https://jaspervdj.be/hakyll/) static site +generator, you can use the filter by importing it as a library and using +the snippet below. + +Add `pandoc`, `pandoc-types`, and `pandoc-emphasize-code` to your +project dependencies, then define a custom Hakyll compiler using a +Pandoc transform: + +``` haskell +import Text.Pandoc (Format (..), Pandoc) +import Text.Pandoc.Walk (walkM) +import Text.Pandoc.Filter.EmphasizeCode (emphasizeCode) + +emphasizeCodeTransform :: Pandoc -> IO Pandoc +emphasizeCodeTransform = walkM (emphasizeCode (Just (Format "html5"))) + +emphasizeCodePandocCompiler :: Compiler (Item String) +emphasizeCodePandocCompiler = + pandocCompilerWithTransformM + defaultHakyllReaderOptions + defaultHakyllWriterOptions {writerHighlightStyle = Nothing} + (unsafeCompiler . emphasizeCodeTransform) +``` + +You can now use `emphasizeCodePandocCompiler` instead of the default +`pandocCompiler` in your Hakyll rules: + +``` haskell +match "*.md" $ do + route $ setExtension "html" + compile $ emphasizeCodePandocCompiler + >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= relativizeUrls +``` + ## Changelog - **0.2.4** diff --git a/README.src.md b/README.src.md index 80379ad..50fbc47 100644 --- a/README.src.md +++ b/README.src.md @@ -235,6 +235,38 @@ If you have installed from sources, and you have `~/.local/bin` on your pandoc --filter pandoc-emphasize-code input.md output.html ``` +## Usage with Hakyll + +If you are using the [Hakyll](https://jaspervdj.be/hakyll/) static site generator, you can use the filter by importing it as a library and using the snippet below. + +Add `pandoc`, `pandoc-types`, and `pandoc-emphasize-code` to your project dependencies, then define a custom Hakyll compiler using a Pandoc transform: + +```haskell +import Text.Pandoc (Format (..), Pandoc) +import Text.Pandoc.Walk (walkM) +import Text.Pandoc.Filter.EmphasizeCode (emphasizeCode) + +emphasizeCodeTransform :: Pandoc -> IO Pandoc +emphasizeCodeTransform = walkM (emphasizeCode (Just (Format "html5"))) + +emphasizeCodePandocCompiler :: Compiler (Item String) +emphasizeCodePandocCompiler = + pandocCompilerWithTransformM + defaultHakyllReaderOptions + defaultHakyllWriterOptions {writerHighlightStyle = Nothing} + (unsafeCompiler . emphasizeCodeTransform) +``` + +You can now use `emphasizeCodePandocCompiler` instead of the default `pandocCompiler` in your Hakyll rules: + +```haskell +match "*.md" $ do + route $ setExtension "html" + compile $ emphasizeCodePandocCompiler + >>= loadAndApplyTemplate "templates/default.html" defaultContext + >>= relativizeUrls +``` + ## Changelog - **0.2.4** diff --git a/docs/index.html b/docs/index.html index 96acd1c..102872f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -9,12 +9,13 @@ code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} + div.line-block{white-space: pre-line;} div.column{display: inline-block; vertical-align: top; width: 50%;} - - - + + + @@ -99,6 +102,7 @@

pandoc-emphasize-code

  • Build
  • Run
  • +
  • Usage with Hakyll
  • Changelog
  • License
  • @@ -192,12 +196,12 @@

    Rendering with LaTeX

    NOTE: When rendering as Beamer slides, any frame including an emphasized block must be marked as fragile:

    ## My Slide {.fragile}
     
    -```{.haskell emphasize=2:3-2:14,3:3-3:12}
    -myFunc = do
    -  newStuffHere
    -  andThisToo notThis
    -  notSoRelevant
    -```
    +```{.haskell emphasize=2:3-2:14,3:3-3:12} +myFunc = do + newStuffHere + andThisToo notThis + notSoRelevant +```

    Regular Highlighting

    You can still use regular Pandoc highlighting (the skylighting library):

    ``` {.haskell}
    @@ -233,6 +237,28 @@ 

    Build

    Run

    If you have installed from sources, and you have ~/.local/bin on your PATH, you can use the filter with Pandoc like so:

    +

    Usage with Hakyll

    +

    If you are using the Hakyll static site generator, you can use the filter by importing it as a library and using the snippet below.

    +

    Add pandoc, pandoc-types, and pandoc-emphasize-code to your project dependencies, then define a custom Hakyll compiler using a Pandoc transform:

    + +

    You can now use emphasizeCodePandocCompiler instead of the default pandocCompiler in your Hakyll rules:

    +

    Changelog

    +

    To build the example in README.src.md, make sure you have on your PATH:

    +
      +
    • pandoc (stack build pandoc)
    • +
    • pdflatex (can be obtained from a Tex distribution, on macOS brew cask install mactex then add /Library/TeX/texbin to your PATH)
    • +
    +

    Then run:

    +

    Run

    If you have installed from sources, and you have ~/.local/bin on your PATH, you can use the filter with Pandoc like so:

    - +

    Usage with Hakyll

    If you are using the Hakyll static site generator, you can use the filter by importing it as a library and using the snippet below.

    Add pandoc, pandoc-types, and pandoc-emphasize-code to your project dependencies, then define a custom Hakyll compiler using a Pandoc transform:

    - +

    You can now use emphasizeCodePandocCompiler instead of the default pandocCompiler in your Hakyll rules:

    - +

    Changelog