Skip to content

Commit 0900e9c

Browse files
committed
Filter update, documentation still missing
1 parent 9d33641 commit 0900e9c

26 files changed

+1437
-298
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ max_line_length = 80
2323
# Text with 60 to 66 characters per line is said to be the easiest
2424
# to read.
2525
max_line_length = 66
26+
27+
[*.qmd]
28+
# Text with 60 to 66 characters per line is said to be the easiest
29+
# to read.
30+
max_line_length = 66

.github/workflows/ci.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ on:
1717
# This way we will catch incompatible pandoc changes in a timely
1818
# manner.
1919
schedule:
20-
# At 5:39am each Tuesday
21-
- cron: '39 5 * * 2'
20+
# At 3:47am each Thursday
21+
- cron: '47 3 * * 4'
2222

2323
jobs:
2424
test:
@@ -27,10 +27,9 @@ jobs:
2727
fail-fast: true
2828
matrix:
2929
pandoc:
30-
- edge
30+
#- edge # uncomment to catch errors faster
3131
- latest
32-
# This should be the oldest version that's supported
33-
# - 2.19.2
32+
# - 2.19.2
3433

3534
container:
3635
image: pandoc/core:${{ matrix.pandoc }}
@@ -43,4 +42,4 @@ jobs:
4342
run: apk add make
4443

4544
- name: Test
46-
run: make test
45+
run: make test BUILD=false
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish Website
1+
name: Publish Manual
22

33
# Allow one concurrent deployment
44
concurrency:
@@ -14,9 +14,13 @@ permissions:
1414
on:
1515
push:
1616
branches: ['main']
17+
paths-ignore:
18+
- 'README.md'
19+
- LICENSE
20+
- .editorconfig
1721

1822
jobs:
19-
website:
23+
manual:
2024
runs-on: ubuntu-latest
2125
environment:
2226
name: github-pages
@@ -26,11 +30,15 @@ jobs:
2630
uses: actions/checkout@v4
2731
- name: Setup Pages
2832
uses: actions/configure-pages@v5
33+
- name: Prepare custom pandoc container
34+
run: |
35+
docker build -t custom-pandoc -f .tools/Dockerfile .
2936
- name: Render Website
3037
run: |
3138
make -B website \
39+
SOURCE_DIR="" \
3240
PANDOC="docker run --rm --volume $(pwd):/data \
33-
--user $(id -u):$(id -g) pandoc/core:latest"
41+
--user $(id -u):$(id -g) custom-pandoc"
3442
- name: Upload artifact
3543
uses: actions/upload-pages-artifact@v3
3644
with:

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
# Docs output
12
/_site/
3+
4+
# Quarto artefacts
5+
/example-quarto/*_files/
6+
/example-quarto/*.html
7+
/example-quarto/*.pdf
8+
/example-quarto/*.tex
9+
/.luarc.json
10+
11+
# MacOS
12+
**/*.DS_Store

.tools/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM pandoc/latex:latest
2+
3+
# Uncomment the lines below to customize latex.
4+
# Specify here an archive TeXLive if the pandoc/latex image isn't
5+
# yet updated to the last version.
6+
#
7+
# RUN tlmgr option repository https://mirror.ctan.org/systems/texlive/tlnet \
8+
# && tlmgr install \
9+
# latex-package-1 \
10+
# latex-package-2
11+
12+
ENTRYPOINT [ "/usr/local/bin/pandoc" ]

.tools/anchorlinks.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* anchorlinks.js: add anchor links before headers h2, h3
2+
*/
3+
document.addEventListener("DOMContentLoaded", function () {
4+
const headers = document.querySelectorAll("h2, h3" );
5+
var css_needed = false;
6+
7+
headers.forEach(header => {
8+
if (header.id) {
9+
css_needed = true
10+
// create anchor
11+
const anchor = document.createElement("a");
12+
anchor.href = `#${header.id}`;
13+
anchor.textContent = "#";
14+
anchor.className = "header-anchor";
15+
// insert after header
16+
header.appendChild(anchor);
17+
}
18+
});
19+
20+
if (css_needed) {
21+
const style = document.createElement("style");
22+
style.appendChild(document.createTextNode(`
23+
.header-anchor {
24+
display: inline-block;
25+
text-decoration: none;
26+
margin-left: 8px;
27+
font-size: 0.8em;
28+
opacity: 0.5;
29+
}
30+
31+
.header-anchor:hover {
32+
opacity: 1;
33+
text-decoration: underline;
34+
}
35+
`));
36+
document.head.appendChild(style);
37+
}
38+
});

.tools/anchorlinks.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function Meta(meta)
2+
ptype = pandoc.utils.type
3+
if meta['header-includes'] then
4+
head_inc = meta['header-includes']
5+
if ptype(head_inc) == 'table' then
6+
head_inc = pandoc.List:new(head_inc)
7+
else
8+
head_inc = pandoc.List:new{head_inc}
9+
end
10+
else
11+
head_inc = pandoc.List:new{}
12+
end
13+
head_inc:insert(pandoc.RawBlock('html',
14+
'<script src=anchorlinks.js></script>'))
15+
meta['header-includes'] = head_inc
16+
return meta
17+
end
18+
19+

.tools/docs.lua

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ local path = require 'pandoc.path'
22
local utils = require 'pandoc.utils'
33
local stringify = utils.stringify
44

5+
local function log(msg)
6+
io.stderr:write('[Docs.lua filter: ERROR] '..msg..'\n')
7+
end
8+
59
local function read_file (filename)
610
local fh = io.open(filename)
11+
if not fh then
12+
log('Cannot read file '..filename..'.')
13+
return
14+
end
715
local content = fh:read('*a')
816
fh:close()
917
return content
@@ -17,8 +25,11 @@ local formats_by_extension = {
1725
html = 'html',
1826
}
1927

20-
local function sample_blocks (sample_file)
28+
local function sample_blocks(sample_file)
2129
local sample_content = read_file(sample_file)
30+
if not sample_content then
31+
return nil
32+
end
2233
local extension = select(2, path.split_extension(sample_file)):sub(2)
2334
local format = formats_by_extension[extension] or extension
2435
local filename = path.filename(sample_file)
@@ -30,17 +41,16 @@ local function sample_blocks (sample_file)
3041
}
3142
end
3243

33-
local function result_block_raw(result_file, format)
34-
local result_content = read_file(result_file)
35-
44+
local function result_block_raw(result_content, format)
3645
return pandoc.CodeBlock(result_content,
3746
pandoc.Attr('', {format, 'sample'})
3847
)
3948
end
4049

4150
local function result_block_html(filename)
4251
local html = '<iframe width=100% height=720px '
43-
..'src="'..filename..'" sandbox>\n'
52+
-- ..'src="'..filename..'" sandbox>\n'
53+
..'src="'..filename..'">\n' -- non-sandbox to display linked images
4454
..'<p><a href="'..filename..'">Click to see file</a></p>\n'
4555
..'</iframe>'
4656
return pandoc.RawBlock('html', html)
@@ -50,56 +60,69 @@ local function result_blocks(result_file)
5060
local extension = select(2, path.split_extension(result_file)):sub(2)
5161
local format = formats_by_extension[extension] or extension
5262
local filename = path.filename(result_file)
53-
local result = pandoc.List:new({
54-
pandoc.Header(3,
55-
pandoc.Link(pandoc.Str(filename), filename),
56-
{filename}
57-
)
58-
})
63+
local result = nil
5964

60-
if format == 'html' then
61-
result:insert(result_block_html(filename))
65+
if format == 'html' then
66+
result = result_block_html(filename)
6267
else
63-
result:insert(result_block_raw(result_file, format))
68+
result = result_block_raw(result_file, format)
6469
end
6570

66-
return result
67-
end
71+
if result then
72+
return pandoc.List:new{
73+
pandoc.Header(3,
74+
pandoc.Link(pandoc.Str(filename), filename),
75+
{ id = filename }
76+
),
77+
result
78+
}
79+
end
6880

81+
end
6982

7083
local function code_blocks (code_file)
7184
local code_content = read_file(code_file)
72-
local code_attr = pandoc.Attr(code_file, {'lua'})
73-
return {
74-
pandoc.CodeBlock(code_content, code_attr)
75-
}
85+
if code_content then
86+
local code_attr = pandoc.Attr(code_file, {'lua'})
87+
return {
88+
pandoc.CodeBlock(code_content, code_attr)
89+
}
90+
end
7691
end
7792

7893
function Pandoc (doc)
7994
local meta = doc.meta
8095
local blocks = doc.blocks
8196

82-
-- Set document title from README title. There should usually be just
83-
-- a single level 1 heading.
84-
blocks = blocks:walk{
85-
Header = function (h)
86-
if h.level == 1 then
87-
meta.title = h.content
88-
return {}
97+
-- Ensure the document has a title: already set or first level 1 heading.
98+
if not meta.title then
99+
blocks = blocks:walk{
100+
Header = function (h)
101+
if h.level == 1 and not meta.title then
102+
meta.title = h.content
103+
return {}
104+
end
89105
end
90-
end
91-
}
106+
}
107+
end
92108

93-
-- Add the sample file as an example.
94-
blocks:extend{pandoc.Header(2, 'Example', pandoc.Attr('Example'))}
95-
blocks:extend(sample_blocks(stringify(meta['sample-file'])))
96-
blocks:extend(result_blocks(stringify(meta['result-file'])))
109+
-- Add the sample file source and result as an example if both present.
110+
local spl_blocks = sample_blocks(stringify(meta['sample-file']))
111+
local res_blocks = result_blocks(stringify(meta['result-file']))
112+
if spl_blocks and res_blocks then
113+
blocks:extend{pandoc.Header(2, 'Example', pandoc.Attr('Example'))}
114+
blocks:extend(spl_blocks)
115+
blocks:extend(res_blocks)
116+
end
97117

98118
-- Add the filter code.
99119
local code_file = stringify(meta['code-file'])
100-
blocks:extend{pandoc.Header(2, 'Code', pandoc.Attr('Code'))}
101-
blocks:extend{pandoc.Para{pandoc.Link(pandoc.Str(code_file), code_file)}}
102-
blocks:extend(code_blocks(code_file))
120+
local cde_blocks = code_blocks(code_file)
121+
if cde_blocks then
122+
blocks:extend{pandoc.Header(2, 'Code', pandoc.Attr('Code'))}
123+
blocks:extend{pandoc.Para{pandoc.Link(pandoc.Str(code_file), code_file)}}
124+
blocks:extend(cde_blocks)
125+
end
103126

104127
return pandoc.Pandoc(blocks, meta)
105128
end

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

33
Copyright © 2021–2022 Albert Krewinkel and contributors.
4+
Copyright © 2022–2024 Julien Dutant.
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)