Skip to content

Commit e477d39

Browse files
committed
Generate README from perevirky
1 parent 23e9dcd commit e477d39

7 files changed

+114
-26
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ test-%: $(FILTER_FILE) test/input-%.md test/test-%.yaml
1111
# Check expected results with perevir
1212
test:
1313
pandoc lua test/runtests.lua test/perevirky/
14+
15+
# Generate README.md from perevirky files.
16+
README.md: test/docs.yaml $(wildcard test/perevirky/*.md)
17+
pandoc -d test/docs --output=README.md

README.md

+40-18
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,85 @@
11
run-lua
2-
==================================================================
2+
=======
33

44
Executes any Lua command in a `lua` XML processing instruction and
55
includes the result in the document.
66

77
Example:
88

99
``` markdown
10-
The fifth triangular number is <?lua return 1 + 2 + 3 + 4 + 5?>.
10+
The number <?lua return 1 + 2 + 3 + 4 + 5?> is the fifth triangular number.
1111
```
1212

1313
This yields
1414

15-
> The fifth triangular number is 15.
15+
> <div id="output">
16+
>
17+
> The number 15 is the fifth triangular number.
18+
>
19+
> </div>
1620
17-
The value that's returned by the Lua code is spliced back into the
21+
The value thats returned by the Lua code is spliced back into the
1822
document. The `=` character can be used as a shorthand for
1923
`return` when placed at the beginning of an expression.
2024

2125
``` xml
22-
<?lua =1 + 2 ?>
26+
1 + 2 = <?lua =1 + 2 ?>
2327
```
2428

29+
Result:
30+
31+
> <div id="output">
32+
>
33+
> 1 + 2 = 3
34+
>
35+
> </div>
36+
2537
The filter tries to detect when the `return` has been omitted and
2638
inserts it automatically in that case. Therefore, the above can be
2739
shortened to
2840

2941
``` xml
30-
<?lua 1 + 2 ?>
42+
1 + 2 = <?lua 1 + 2 ?>
3143
```
3244

45+
> <div id="output">
46+
>
47+
> 1 + 2 = 3
48+
>
49+
> </div>
50+
3351
Raw attributes syntax with format `run-lua` or `runlua` can be
3452
used as an alternative to the processing-instructions-based
3553
syntax.
3654

3755
For example,
3856

39-
`````markdown
40-
𝜋 ≈ `math.pi`{=runlua}
41-
`````
57+
``` markdown
58+
𝜋 ≈ `math.pi`{=run-lua}
59+
60+
𝜏 ≈ `2 * math.pi`{=runlua}
61+
```
4262

4363
yields
4464

65+
> <div id="output">
66+
>
4567
> 𝜋 ≈ 3.1415926535898
68+
>
69+
> 𝜏 ≈ 6.2831853071796
70+
>
71+
> </div>
4672
47-
**Note** that pandoc isn't an XML processor, and the processing
73+
**Note** that pandoc isnt an XML processor, and the processing
4874
instruction is terminated by a single `>`. Use the “raw attribute”
4975
syntax if your code contains that character:
5076

5177
```{=runlua}
5278
return 1 > 0 and 'all is well'
5379
```
5480

55-
[CI badge]: https://img.shields.io/github/actions/workflow/status/pandoc-ext/run-lua/ci.yaml?branch=main&logo=github
56-
[CI workflow]: https://github.com/pandoc-ext/run-lua/actions/workflows/ci.yaml
57-
58-
5981
Usage
60-
------------------------------------------------------------------
82+
-----
6183

6284
The filter modifies the internal document representation; it can
6385
be used with many publishing systems that are based on pandoc.
@@ -75,8 +97,8 @@ Users of Quarto can install this filter as an extension with
7597

7698
quarto install extension pandoc-ext/run-lua
7799

78-
and use it by adding `run-lua` to the `filters` entry
79-
in their YAML header.
100+
and use it by adding `run-lua` to the `filters` entry in their
101+
YAML header.
80102

81103
``` yaml
82104
---
@@ -100,7 +122,7 @@ output:
100122
```
101123

102124
License
103-
------------------------------------------------------------------
125+
-------
104126

105127
This pandoc Lua filter is published under the MIT license, see
106128
file `LICENSE` for details.

test/docs.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
input-files:
2+
- test/perevirky/01-intro.md
3+
- test/perevirky/02-shorthand-equal.md
4+
- test/perevirky/03-no-return.md
5+
- test/perevirky/04-raw-attributes-inline.md
6+
- test/perevirky/10-usage.md
7+
- test/perevirky/99-license.md
8+
9+
to: gfm
10+
markdown-headings: setext
11+
columns: 66

test/perevirky/02-shorthand-equal.md

-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ document. The `=` character can be used as a shorthand for
66
1 + 2 = <?lua =1 + 2 ?>
77
```
88

9-
<details>
10-
119
Result:
1210

1311
> <div id="output">
1412
>
1513
> 1 + 2 = 3
1614
>
1715
> </div>
18-
19-
</details>

test/perevirky/03-no-return.md

-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ shortened to
66
1 + 2 = <?lua 1 + 2 ?>
77
```
88

9-
<details>
10-
119
> <div id="output">
1210
>
1311
> 1 + 2 = 3
1412
>
1513
> </div>
16-
17-
</details>

test/perevirky/10-usage.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
perevir:
3+
# No tests in here
4+
disable: true
5+
---
6+
7+
Usage
8+
------------------------------------------------------------------
9+
10+
The filter modifies the internal document representation; it can
11+
be used with many publishing systems that are based on pandoc.
12+
13+
### Plain pandoc
14+
15+
Pass the filter to pandoc via the `--lua-filter` (or `-L`) command
16+
line option.
17+
18+
pandoc --lua-filter run-lua.lua ...
19+
20+
### Quarto
21+
22+
Users of Quarto can install this filter as an extension with
23+
24+
quarto install extension pandoc-ext/run-lua
25+
26+
and use it by adding `run-lua` to the `filters` entry
27+
in their YAML header.
28+
29+
``` yaml
30+
---
31+
filters:
32+
- run-lua
33+
---
34+
```
35+
36+
### R Markdown
37+
38+
Use `pandoc_args` to invoke the filter. See the [R Markdown
39+
Cookbook](https://bookdown.org/yihui/rmarkdown-cookbook/lua-filters.html)
40+
for details.
41+
42+
``` yaml
43+
---
44+
output:
45+
word_document:
46+
pandoc_args: ['--lua-filter=run-lua.lua']
47+
---
48+
```

test/perevirky/99-license.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
perevir:
3+
# No tests in here
4+
disable: true
5+
---
6+
7+
License
8+
------------------------------------------------------------------
9+
10+
This pandoc Lua filter is published under the MIT license, see
11+
file `LICENSE` for details.

0 commit comments

Comments
 (0)