Skip to content

Commit d8ab6aa

Browse files
authored
Minor improvements (#6)
* Various minor improvements These include: - Some protection against infinite loops, e.g. with metatables - Reporting on Doc objects (the value is shown within '|' characters) - Showing array sizes * Update docs and examples to match the latest
1 parent 6f10283 commit d8ab6aa

File tree

8 files changed

+111
-89
lines changed

8 files changed

+111
-89
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ text
3030

3131
```text
3232
(#) pandoc Pandoc {
33-
blocks: Blocks {
33+
blocks: Blocks[1] {
3434
[1] Para {
35-
content: Inlines {
35+
content: Inlines[1] {
3636
[1] Str "text"
3737
}
3838
}
@@ -66,14 +66,14 @@ end
6666
```text
6767
% pandoc simple.md -L para.lua >/dev/null --verbose
6868
[INFO] Running filter para.lua
69-
(I) para Para {content: Inlines {[1] Str "text"}}
70-
[INFO] Completed filter para.lua in 8 ms
69+
(I) para Para {content: Inlines[1] {[1] Str "text"}}
70+
[INFO] Completed filter para.lua in 7 ms
7171
```
7272

7373
All lua objects can be passed to `logging.info()` etc., and they will be output in a form that should be useful for lua filter development and debugging. The output is intended to be a faithful representation of the [pandoc lua types](https://pandoc.org/lua-filters.html#module-pandoc) and should make it easy to "dig down". For example, you can see that:
7474

7575
* `para` is a [Para](https://pandoc.org/lua-filters.html#type-para) instance
76-
* `para.content` is an [Inlines](https://pandoc.org/lua-filters.html#type-inlines) instance
76+
* `para.content` is an [Inlines](https://pandoc.org/lua-filters.html#type-inlines) instance with a single element
7777
* `para.content[1]` is a [Str](https://pandoc.org/lua-filters.html#type-str) instance
7878
* `para.content[1].text` is a string
7979

@@ -95,14 +95,14 @@ end
9595
```text
9696
% pandoc simple.md -L para2.lua >/dev/null --verbose
9797
[INFO] Running filter para2.lua
98-
(I) para Para {content: Inlines {[1] Str "text"}}
99-
(I) para.content Inlines {[1] Str "text"}
98+
(I) para Para {content: Inlines[1] {[1] Str "text"}}
99+
(I) para.content Inlines[1] {[1] Str "text"}
100100
(I) para.content[1] Str "text"
101101
(I) para.content[1].text text
102-
[INFO] Completed filter para2.lua in 8 ms
102+
[INFO] Completed filter para2.lua in 7 ms
103103
```
104104

105-
Why is the last `text` not quoted?
105+
The last `text` is not quoted, because lua strings are always output literally.
106106

107107
# Module contents
108108

examples/dumpex.lua.expected

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ false
44
"string"
55
"Here’s a non-ASCII character."
66
{}
7-
{[1] 1, [2] 2, [3] 3}
7+
[3] {[1] 1, [2] 2, [3] 3}
88
{a: 1, b: 2, c: 3}
9-
{[1] 4, [2] 5, a: 1, b: 2, c: 3}
10-
{[1] 4, [2] 5, [3] 6, [4] 7, [5] 8, [6] 9, [7] 10, a: 1, b: 2, c: 3}
11-
{
9+
[2] {[1] 4, [2] 5, a: 1, b: 2, c: 3}
10+
[7] {
11+
[1] 4
12+
[2] 5
13+
[3] 6
14+
[4] 7
15+
[5] 8
16+
[6] 9
17+
[7] 10
18+
a: 1
19+
b: 2
20+
c: 3
21+
}
22+
[8] {
1223
[1] 4
1324
[2] 5
1425
[3] 6
@@ -21,10 +32,10 @@ false
2132
b: 2
2233
c: 3
2334
}
24-
{
35+
[3] {
2536
[1] 1
2637
[2] 2
27-
[3] {
38+
[3] [3] {
2839
[1] 3
2940
[2] 4
3041
[3] {

examples/levels.lua.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
(E) this is output if loglevel >= -1
33
(W) this is output if loglevel >= 0
44
(#) args are automatically separated with spaces and a newline is added if necessary
5-
(#) args can be of any type, e.g. {maps: "like", this: "one"} or {[1] "lists", [2] "like", [3] "this", [4] "one"}
6-
(#) if an arg is too long it will be output on multiple lines {
5+
(#) args can be of any type, e.g. {maps: "like", this: "one"} or [4] {[1] "lists", [2] "like", [3] "this", [4] "one"}
6+
(#) if an arg is too long it will be output on multiple lines [5] {
77
[1] "aardvark"
88
[2] "bison"
99
[3] "camel"

examples/para.lua.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[INFO] Running filter para.lua
22
(I) para Para {
3-
content: Inlines {
3+
content: Inlines[29] {
44
[1] Str "This"
55
[2] Space
66
[3] Str "directory"
@@ -33,7 +33,7 @@
3333
}
3434
}
3535
(I) para Para {
36-
content: Inlines {
36+
content: Inlines[25] {
3737
[1] Str "These"
3838
[2] Space
3939
[3] Str "files"
@@ -62,7 +62,7 @@
6262
}
6363
}
6464
(I) para Para {
65-
content: Inlines {
65+
content: Inlines[37] {
6666
[1] Str "There’s"
6767
[2] Space
6868
[3] Str "also"
@@ -110,28 +110,28 @@
110110
}
111111
}
112112
(I) para Para {
113-
content: Inlines {
113+
content: Inlines[11] {
114114
[1] Str "Paragraph"
115115
[2] Space
116116
[3] Str "with"
117117
[4] Space
118118
[5] Emph {
119-
content: Inlines {
119+
content: Inlines[1] {
120120
[1] Str "emphasized"
121121
}
122122
}
123123
[6] Space
124124
[7] Str "and"
125125
[8] Space
126126
[9] Strong {
127-
content: Inlines {
127+
content: Inlines[1] {
128128
[1] Str "bold"
129129
}
130130
}
131131
[10] Space
132132
[11] Str "text."
133133
}
134134
}
135-
(I) para Para {content: Inlines {[1] Str "text"}}
136-
(I) para Para {content: Inlines {[1] Str "smart-quote-’"}}
135+
(I) para Para {content: Inlines[1] {[1] Str "text"}}
136+
(I) para Para {content: Inlines[1] {[1] Str "smart-quote-’"}}
137137
[INFO] Completed filter para.lua in NN ms

examples/para2.lua.expected

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[INFO] Running filter para2.lua
22
(I) para Para {
3-
content: Inlines {
3+
content: Inlines[29] {
44
[1] Str "This"
55
[2] Space
66
[3] Str "directory"
@@ -32,7 +32,7 @@
3232
[29] Str "files."
3333
}
3434
}
35-
(I) para.content Inlines {
35+
(I) para.content Inlines[29] {
3636
[1] Str "This"
3737
[2] Space
3838
[3] Str "directory"
@@ -66,7 +66,7 @@
6666
(I) para.content[1] Str "This"
6767
(I) para.content[1].text This
6868
(I) para Para {
69-
content: Inlines {
69+
content: Inlines[25] {
7070
[1] Str "These"
7171
[2] Space
7272
[3] Str "files"
@@ -94,7 +94,7 @@
9494
[25] Str "file."
9595
}
9696
}
97-
(I) para.content Inlines {
97+
(I) para.content Inlines[25] {
9898
[1] Str "These"
9999
[2] Space
100100
[3] Str "files"
@@ -124,7 +124,7 @@
124124
(I) para.content[1] Str "These"
125125
(I) para.content[1].text These
126126
(I) para Para {
127-
content: Inlines {
127+
content: Inlines[37] {
128128
[1] Str "There’s"
129129
[2] Space
130130
[3] Str "also"
@@ -171,7 +171,7 @@
171171
[37] Str "output."
172172
}
173173
}
174-
(I) para.content Inlines {
174+
(I) para.content Inlines[37] {
175175
[1] Str "There’s"
176176
[2] Space
177177
[3] Str "also"
@@ -220,43 +220,43 @@
220220
(I) para.content[1] Str "There’s"
221221
(I) para.content[1].text There’s
222222
(I) para Para {
223-
content: Inlines {
223+
content: Inlines[11] {
224224
[1] Str "Paragraph"
225225
[2] Space
226226
[3] Str "with"
227227
[4] Space
228228
[5] Emph {
229-
content: Inlines {
229+
content: Inlines[1] {
230230
[1] Str "emphasized"
231231
}
232232
}
233233
[6] Space
234234
[7] Str "and"
235235
[8] Space
236236
[9] Strong {
237-
content: Inlines {
237+
content: Inlines[1] {
238238
[1] Str "bold"
239239
}
240240
}
241241
[10] Space
242242
[11] Str "text."
243243
}
244244
}
245-
(I) para.content Inlines {
245+
(I) para.content Inlines[11] {
246246
[1] Str "Paragraph"
247247
[2] Space
248248
[3] Str "with"
249249
[4] Space
250250
[5] Emph {
251-
content: Inlines {
251+
content: Inlines[1] {
252252
[1] Str "emphasized"
253253
}
254254
}
255255
[6] Space
256256
[7] Str "and"
257257
[8] Space
258258
[9] Strong {
259-
content: Inlines {
259+
content: Inlines[1] {
260260
[1] Str "bold"
261261
}
262262
}
@@ -265,12 +265,12 @@
265265
}
266266
(I) para.content[1] Str "Paragraph"
267267
(I) para.content[1].text Paragraph
268-
(I) para Para {content: Inlines {[1] Str "text"}}
269-
(I) para.content Inlines {[1] Str "text"}
268+
(I) para Para {content: Inlines[1] {[1] Str "text"}}
269+
(I) para.content Inlines[1] {[1] Str "text"}
270270
(I) para.content[1] Str "text"
271271
(I) para.content[1].text text
272-
(I) para Para {content: Inlines {[1] Str "smart-quote-’"}}
273-
(I) para.content Inlines {[1] Str "smart-quote-’"}
272+
(I) para Para {content: Inlines[1] {[1] Str "smart-quote-’"}}
273+
(I) para.content Inlines[1] {[1] Str "smart-quote-’"}
274274
(I) para.content[1] Str "smart-quote-’"
275275
(I) para.content[1].text smart-quote-’
276276
[INFO] Completed filter para2.lua in NN ms

0 commit comments

Comments
 (0)