Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ do_latex() {
--lua-filter=convert-diagrams.lua
--lua-filter=convert-images.lua
--lua-filter=center-images.lua
--lua-filter=include-into-code-blocks.lua
--lua-filter=informative-sections.lua
--lua-filter=parse-html.lua
--lua-filter=apply-classes-to-tables.lua
Expand Down Expand Up @@ -984,6 +985,7 @@ do_docx() {
--standalone
--lua-filter=convert-diagrams.lua
--lua-filter=convert-images.lua
--lua-filter=include-into-code-blocks.lua
--lua-filter=parse-html.lua
--lua-filter=apply-classes-to-tables.lua
--lua-filter=landscape-pages.lua
Expand Down Expand Up @@ -1025,6 +1027,7 @@ do_html() {
--standalone
${HTML_ARGS}
--lua-filter=convert-diagrams.lua
--lua-filter=include-into-code-blocks.lua
--lua-filter=parse-html.lua
--lua-filter=apply-classes-to-tables.lua
--lua-filter=landscape-pages.lua
Expand Down
2 changes: 2 additions & 0 deletions filter/divide-code-blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function CodeBlock(block)
-- all code blocks are rendered consistently.
table.insert(block.classes, "_placeholder")

block.text = block.text:gsub("\r", "") -- Remove carriage-returns.

font = class_spec["font"]
return {
pandoc.RawInline('latex', string.format([[
Expand Down
26 changes: 26 additions & 0 deletions filter/include-into-code-blocks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Allow code blocks to include code from other files.

-- Patch the path to include the current script's directory.
package.path = package.path .. ";" .. debug.getinfo(1).source:match("@?(.*/)") .. "?.lua"
utils = require "utils"

function resolveIncludes(text)
-- A hack to make the regex below work, since gsub can't match `^ | \n`
if text:match("^!include ") then
text = "\n" .. text
end

return text:gsub("\n(!include )(%C+)", function(_, include_path)
return utils.readFile(include_path)
end)
end

function CodeBlock(el)
for i, class in ipairs(el.classes) do
if class == 'include' then
return pandoc.CodeBlock(resolveIncludes(el.text), el.attr)
end
end

return el
end
17 changes: 17 additions & 0 deletions guide.tcg
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,23 @@ auctor lorem, ultricies vehicula orci aliquam sed. Praesent interdum leo metus,
ut rhoncus sem consequat a.
```

Code blocks can also include content from other files.

````md
```include {.small}
!include sample-text.inc
```
````

The result looks like this:

```include {.small}
!include sample-text.inc
```

An `include` block can contain multiple `!include` directives. Paths are resolved
relative to the directory in which the build occurs.

## Footnotes {#sec:footnotes}

```md
Expand Down
3 changes: 3 additions & 0 deletions sample-text.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This file now can
be included verbatim
into the source spec.