-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for Mermaid (#74)
* Fix copy paste typo for D2 * Add initial support for Mermaid Requires mermaid-cli to be installed and `mmdc` command to be available.
- Loading branch information
1 parent
5753e8f
commit 8f69379
Showing
9 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,3 +146,7 @@ sageplot: | |
d2: | ||
executable: d2 | ||
command_line_arguments: | ||
|
||
mermaid: | ||
executable: mmdc | ||
command_line_arguments: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
-- | | ||
-- Module : $header$ | ||
-- Copyright : (c) Sanchayan Maity, 2024 - present | ||
-- License : GNU GPL, version 2 or above | ||
-- Maintainer : [email protected] | ||
-- Stability : internal | ||
-- Portability : portable | ||
-- | ||
-- Rendering Mermaid plots code blocks | ||
module Text.Pandoc.Filter.Plot.Renderers.Mermaid | ||
( mermaid, | ||
mermaidSupportedSaveFormats, | ||
) | ||
where | ||
|
||
import Data.Char (toLower) | ||
import Text.Pandoc.Filter.Plot.Renderers.Prelude | ||
|
||
mermaid :: PlotM Renderer | ||
mermaid = do | ||
cmdargs <- asksConfig mermaidCmdArgs | ||
return | ||
$ Renderer | ||
{ rendererToolkit = Mermaid, | ||
rendererCapture = mermaidCapture, | ||
rendererCommand = mermaidCommand cmdargs, | ||
rendererAvailability = CommandSuccess $ \exe -> [st|#{pathToExe exe} -V|], | ||
rendererSupportedSaveFormats = mermaidSupportedSaveFormats, | ||
rendererChecks = mempty, | ||
rendererLanguage = "mermaid", | ||
rendererComment = mempty, | ||
rendererScriptExtension = ".mermaid" | ||
} | ||
|
||
mermaidSupportedSaveFormats :: [SaveFormat] | ||
mermaidSupportedSaveFormats = [PDF, PNG, SVG] | ||
|
||
mermaidCommand :: Text -> OutputSpec -> Text | ||
mermaidCommand cmdargs OutputSpec {..} = | ||
let fmt = fmap toLower . show . saveFormat $ oFigureSpec | ||
in [st|#{pathToExe oExecutable} #{cmdargs} -q -e #{fmt} -i "#{oScriptPath}" -o "#{oFigurePath}"|] | ||
|
||
-- Mermaid export is entirely based on command-line arguments | ||
-- so there is no need to modify the script itself. | ||
mermaidCapture :: FigureSpec -> FilePath -> Script | ||
mermaidCapture FigureSpec {..} _ = script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.