From 68f8216b552f8f3acf3f40d3aea1c634c117c79b Mon Sep 17 00:00:00 2001 From: Yu Cong Date: Sun, 20 Apr 2025 19:38:11 +0800 Subject: [PATCH] first commit --- .ghc.environment.aarch64-darwin-9.4.8 | 6 ++++++ filter.hs | 16 ++++++++++++++++ input.md | 5 +++++ makefile | 8 ++++++++ output.html | 6 ++++++ 5 files changed, 41 insertions(+) create mode 100644 .ghc.environment.aarch64-darwin-9.4.8 create mode 100755 filter.hs create mode 100644 input.md create mode 100644 makefile create mode 100644 output.html diff --git a/.ghc.environment.aarch64-darwin-9.4.8 b/.ghc.environment.aarch64-darwin-9.4.8 new file mode 100644 index 0000000..3eedeb6 --- /dev/null +++ b/.ghc.environment.aarch64-darwin-9.4.8 @@ -0,0 +1,6 @@ +clear-package-db +global-package-db +package-db /Users/congyu/.cabal/store/ghc-9.4.8/package.db +package-id base-4.17.2.1 +package-id pndc-typs-1.23.1-53806a08 +package-id text-2.0.2 diff --git a/filter.hs b/filter.hs new file mode 100755 index 0000000..d235966 --- /dev/null +++ b/filter.hs @@ -0,0 +1,16 @@ +#!/usr/bin/env runhaskell +-- filter.hs +import Text.Pandoc.JSON +import qualified Data.Text.IO as TIO +import qualified Data.Text as T + +doInclude :: Block -> IO Block +doInclude cb@(CodeBlock (id, classes, namevals) contents) = + case lookup (T.pack "include") namevals of + Just f -> CodeBlock (id, classes, namevals) <$> + TIO.readFile (T.unpack f) + Nothing -> return cb +doInclude x = return x + +main :: IO () +main = toJSONFilter doInclude \ No newline at end of file diff --git a/input.md b/input.md new file mode 100644 index 0000000..23a10df --- /dev/null +++ b/input.md @@ -0,0 +1,5 @@ +Here's the pandoc README: + +~~~~ {include="input.md"} +this will be replaced by contents of README +~~~~ \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..2d78466 --- /dev/null +++ b/makefile @@ -0,0 +1,8 @@ + +.PHONY: filter showAST + +filter: + pandoc -fmarkdown -thtml input.md --filter ./filter.hs > output.html + +showAST: + pandoc -fmarkdown -tnative input.md \ No newline at end of file diff --git a/output.html b/output.html new file mode 100644 index 0000000..c6b66e7 --- /dev/null +++ b/output.html @@ -0,0 +1,6 @@ +

Here’s the pandoc README:

+
Here's the pandoc README:
+
+~~~~ {include="input.md"}
+this will be replaced by contents of README
+~~~~