initial version generated by chatgpt, but cabal file does not work
This commit is contained in:
commit
68507e85d1
17
README.md
Normal file
17
README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Docster
|
||||
|
||||
A self-contained CLI tool that converts Markdown with Mermaid diagrams into PDF or HTML using Pandoc and Mermaid CLI.
|
||||
|
||||
## Usage
|
||||
|
||||
docster -pdf path/to/file.md
|
||||
docster -html path/to/file.md
|
||||
|
||||
Mermaid code blocks (```mermaid) will be rendered to SVG and embedded.
|
||||
|
||||
## Requirements
|
||||
|
||||
- GHC + Cabal (via ghcup)
|
||||
- Pandoc
|
||||
- TeX Live (for PDF)
|
||||
- Mermaid CLI (`npm install -g @mermaid-js/mermaid-cli`)
|
68
app/Main.hs
Normal file
68
app/Main.hs
Normal file
@ -0,0 +1,68 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Main where
|
||||
|
||||
import Text.Pandoc
|
||||
import Text.Pandoc.Error
|
||||
import Text.Pandoc.Class (runIOorExplode)
|
||||
import Text.Pandoc.PDF (makePDF)
|
||||
import System.Environment (getArgs)
|
||||
import System.FilePath (replaceExtension)
|
||||
import System.Process (callProcess)
|
||||
import System.IO (writeFile)
|
||||
import System.Directory (doesFileExist)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.IO as TIO
|
||||
import Data.Hashable (hash)
|
||||
import Control.Monad (when, void)
|
||||
|
||||
-- Transform Mermaid code blocks into image embeds
|
||||
processMermaid :: Block -> IO Block
|
||||
processMermaid (CodeBlock (id', classes, _) contents)
|
||||
| "mermaid" `elem` classes = do
|
||||
let baseName = if null id' then "diagram-" ++ take 6 (show (abs (hash contents))) else id'
|
||||
mmdFile = baseName ++ ".mmd"
|
||||
svgFile = baseName ++ ".svg"
|
||||
|
||||
writeFile mmdFile contents
|
||||
exists <- doesFileExist svgFile
|
||||
when (not exists) $ void $ callProcess "mmdc" ["-i", mmdFile, "-o", svgFile]
|
||||
|
||||
return $ Para [Image nullAttr [] (T.pack svgFile, "Mermaid diagram")]
|
||||
processMermaid x = return x
|
||||
|
||||
-- Walk the Pandoc AST and process blocks
|
||||
transformDoc :: Pandoc -> IO Pandoc
|
||||
transformDoc = walkM processMermaid
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
case args of
|
||||
["-pdf", path] -> compileToPDF path
|
||||
["-html", path] -> compileToHTML path
|
||||
_ -> putStrLn "Usage: docster -pdf|-html <file.md>"
|
||||
|
||||
compileToPDF :: FilePath -> IO ()
|
||||
compileToPDF path = do
|
||||
content <- TIO.readFile path
|
||||
pandoc <- runIOorExplode $ readMarkdown def content
|
||||
transformed <- transformDoc pandoc
|
||||
|
||||
let outputPath = replaceExtension path "pdf"
|
||||
result <- runIOorExplode $ makePDF "pdflatex" [] transformed
|
||||
case result of
|
||||
Left err -> error $ "PDF error: " ++ show err
|
||||
Right bs -> writeFile outputPath bs >> putStrLn ("✅ PDF written to " ++ outputPath)
|
||||
|
||||
compileToHTML :: FilePath -> IO ()
|
||||
compileToHTML path = do
|
||||
content <- TIO.readFile path
|
||||
pandoc <- runIOorExplode $ readMarkdown def content
|
||||
transformed <- transformDoc pandoc
|
||||
|
||||
let outputPath = replaceExtension path "html"
|
||||
html <- runIOorExplode $ writeHtml5String def transformed
|
||||
TIO.writeFile outputPath html
|
||||
putStrLn ("✅ HTML written to " ++ outputPath)
|
BIN
dist-newstyle/cache/config
vendored
Normal file
BIN
dist-newstyle/cache/config
vendored
Normal file
Binary file not shown.
19
docster.cabal
Normal file
19
docster.cabal
Normal file
@ -0,0 +1,19 @@
|
||||
cabal-version: >=1.24
|
||||
name: docster
|
||||
version: 0.1.0.0
|
||||
build-type: Simple
|
||||
|
||||
executable docster
|
||||
main-is: Main.hs
|
||||
hs-source-dirs: app
|
||||
build-depends:
|
||||
base >=4.14 && <5,
|
||||
text,
|
||||
filepath,
|
||||
directory,
|
||||
process,
|
||||
hashable,
|
||||
pandoc,
|
||||
pandoc-types,
|
||||
pandoc-pdf
|
||||
default-language: Haskell2010
|
9
mermaid-to-svg/sample.md
Normal file
9
mermaid-to-svg/sample.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Example Document
|
||||
|
||||
This diagram should render:
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
A --> B
|
||||
B --> C
|
||||
```
|
6
mise.toml
Normal file
6
mise.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[tools]
|
||||
cabal = "3.16.0.0"
|
||||
|
||||
# Node.js - required for Claude Code (18+) and frontend assets
|
||||
node = "24.0.1"
|
||||
|
1752
participant-pointers.md
Normal file
1752
participant-pointers.md
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user