Skip to content

Commit

Permalink
Base directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
smimram committed Nov 13, 2023
1 parent da486ce commit 76be2de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

- pandoc-include now fails if the file to include does not exist.
- pandoc-include now supports string boundaries.
- Add a pandoc-include to specify base directory.

0.2.0 (2023-11-10)
=====
Expand Down
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
all: build

test: build
pandoc test.md -t json | dune exec ./include.exe -- --directory ../examples | pandoc -f json -t markdown
pandoc -M xxx=YYY \
--filter=../_build/default/examples/inspect.exe \
--filter=../_build/default/examples/replace.exe \
Expand Down
14 changes: 11 additions & 3 deletions examples/include.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ let error fname n =
exit n)

let () =
let directory = ref "" in
Arg.parse
[
"--directory", Arg.Set_string directory, "Use this as base directory for included files."
]
ignore
"pandoc-include [options]";
let p = Pandoc.of_json (Yojson.Basic.from_channel stdin) in
let rec f = function
(* !include "file" *)
| Pandoc.Para [Str "!include"; _; Quoted (DoubleQuote, [Str s])] ->
let p = Pandoc.of_md_file s in
| Pandoc.Para [Str "!include"; _; Quoted (DoubleQuote, [Str fname])] ->
let fname = Filename.concat !directory fname in
let p = Pandoc.of_md_file fname in
let p = Pandoc.map_blocks f p in
Some (Pandoc.blocks p)
(* ```{.blabla include="file"}
``` *)
| CodeBlock ((ident, classes, keyvals), _) when List.mem_assoc "include" keyvals ->
let fname = List.assoc "include" keyvals in
let fname = List.assoc "include" keyvals |> Filename.concat !directory in
let error n = error fname n in
let from =
match List.assoc_opt "from" keyvals with
Expand Down

0 comments on commit 76be2de

Please sign in to comment.