diff --git a/README.md b/README.md index 9a93361..e9ab57b 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,20 @@ stack setup stack install ``` +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](https://ctan.org/starter), on macOS `brew cask install + mactex` then add `/Library/TeX/texbin` to your `PATH`) + +Then run: + +``` sh +make +``` + ## Run If you have installed from sources, and you have `~/.local/bin` on your @@ -239,6 +253,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..322bee6 100644 --- a/README.src.md +++ b/README.src.md @@ -226,6 +226,17 @@ stack setup stack install ``` +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](https://ctan.org/starter), on macOS `brew cask install mactex` then add `/Library/TeX/texbin` to your `PATH`) + +Then run: + +``` sh +make +``` + ## Run If you have installed from sources, and you have `~/.local/bin` on your @@ -235,6 +246,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..bc31faa 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}
    @@ -230,9 +234,38 @@ 

    Build

    cd pandoc-emphasize-code stack setup stack install
    +

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

    + +

    Then run:

    +
    make

    Run

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

    -
    pandoc --filter pandoc-emphasize-code input.md output.html
    +
    pandoc --filter pandoc-emphasize-code input.md output.html
    +

    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:

    +
    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:

    +
    match "*.md" $ do
    +  route $ setExtension "html"
    +  compile $ emphasizeCodePandocCompiler
    +    >>= loadAndApplyTemplate "templates/default.html" defaultContext
    +    >>= relativizeUrls

    Changelog