Skip to content

Commit

Permalink
Minor improvements (#6)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wlupton authored Apr 10, 2023
1 parent 6f10283 commit d8ab6aa
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 89 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ text

```text
(#) pandoc Pandoc {
blocks: Blocks {
blocks: Blocks[1] {
[1] Para {
content: Inlines {
content: Inlines[1] {
[1] Str "text"
}
}
Expand Down Expand Up @@ -66,14 +66,14 @@ end
```text
% pandoc simple.md -L para.lua >/dev/null --verbose
[INFO] Running filter para.lua
(I) para Para {content: Inlines {[1] Str "text"}}
[INFO] Completed filter para.lua in 8 ms
(I) para Para {content: Inlines[1] {[1] Str "text"}}
[INFO] Completed filter para.lua in 7 ms
```

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:

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

Expand All @@ -95,14 +95,14 @@ end
```text
% pandoc simple.md -L para2.lua >/dev/null --verbose
[INFO] Running filter para2.lua
(I) para Para {content: Inlines {[1] Str "text"}}
(I) para.content Inlines {[1] Str "text"}
(I) para Para {content: Inlines[1] {[1] Str "text"}}
(I) para.content Inlines[1] {[1] Str "text"}
(I) para.content[1] Str "text"
(I) para.content[1].text text
[INFO] Completed filter para2.lua in 8 ms
[INFO] Completed filter para2.lua in 7 ms
```

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

# Module contents

Expand Down
23 changes: 17 additions & 6 deletions examples/dumpex.lua.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@ false
"string"
"Here’s a non-ASCII character."
{}
{[1] 1, [2] 2, [3] 3}
[3] {[1] 1, [2] 2, [3] 3}
{a: 1, b: 2, c: 3}
{[1] 4, [2] 5, a: 1, b: 2, c: 3}
{[1] 4, [2] 5, [3] 6, [4] 7, [5] 8, [6] 9, [7] 10, a: 1, b: 2, c: 3}
{
[2] {[1] 4, [2] 5, a: 1, b: 2, c: 3}
[7] {
[1] 4
[2] 5
[3] 6
[4] 7
[5] 8
[6] 9
[7] 10
a: 1
b: 2
c: 3
}
[8] {
[1] 4
[2] 5
[3] 6
Expand All @@ -21,10 +32,10 @@ false
b: 2
c: 3
}
{
[3] {
[1] 1
[2] 2
[3] {
[3] [3] {
[1] 3
[2] 4
[3] {
Expand Down
4 changes: 2 additions & 2 deletions examples/levels.lua.expected
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(E) this is output if loglevel >= -1
(W) this is output if loglevel >= 0
(#) args are automatically separated with spaces and a newline is added if necessary
(#) args can be of any type, e.g. {maps: "like", this: "one"} or {[1] "lists", [2] "like", [3] "this", [4] "one"}
(#) if an arg is too long it will be output on multiple lines {
(#) args can be of any type, e.g. {maps: "like", this: "one"} or [4] {[1] "lists", [2] "like", [3] "this", [4] "one"}
(#) if an arg is too long it will be output on multiple lines [5] {
[1] "aardvark"
[2] "bison"
[3] "camel"
Expand Down
16 changes: 8 additions & 8 deletions examples/para.lua.expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[INFO] Running filter para.lua
(I) para Para {
content: Inlines {
content: Inlines[29] {
[1] Str "This"
[2] Space
[3] Str "directory"
Expand Down Expand Up @@ -33,7 +33,7 @@
}
}
(I) para Para {
content: Inlines {
content: Inlines[25] {
[1] Str "These"
[2] Space
[3] Str "files"
Expand Down Expand Up @@ -62,7 +62,7 @@
}
}
(I) para Para {
content: Inlines {
content: Inlines[37] {
[1] Str "There’s"
[2] Space
[3] Str "also"
Expand Down Expand Up @@ -110,28 +110,28 @@
}
}
(I) para Para {
content: Inlines {
content: Inlines[11] {
[1] Str "Paragraph"
[2] Space
[3] Str "with"
[4] Space
[5] Emph {
content: Inlines {
content: Inlines[1] {
[1] Str "emphasized"
}
}
[6] Space
[7] Str "and"
[8] Space
[9] Strong {
content: Inlines {
content: Inlines[1] {
[1] Str "bold"
}
}
[10] Space
[11] Str "text."
}
}
(I) para Para {content: Inlines {[1] Str "text"}}
(I) para Para {content: Inlines {[1] Str "smart-quote-’"}}
(I) para Para {content: Inlines[1] {[1] Str "text"}}
(I) para Para {content: Inlines[1] {[1] Str "smart-quote-’"}}
[INFO] Completed filter para.lua in NN ms
32 changes: 16 additions & 16 deletions examples/para2.lua.expected
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[INFO] Running filter para2.lua
(I) para Para {
content: Inlines {
content: Inlines[29] {
[1] Str "This"
[2] Space
[3] Str "directory"
Expand Down Expand Up @@ -32,7 +32,7 @@
[29] Str "files."
}
}
(I) para.content Inlines {
(I) para.content Inlines[29] {
[1] Str "This"
[2] Space
[3] Str "directory"
Expand Down Expand Up @@ -66,7 +66,7 @@
(I) para.content[1] Str "This"
(I) para.content[1].text This
(I) para Para {
content: Inlines {
content: Inlines[25] {
[1] Str "These"
[2] Space
[3] Str "files"
Expand Down Expand Up @@ -94,7 +94,7 @@
[25] Str "file."
}
}
(I) para.content Inlines {
(I) para.content Inlines[25] {
[1] Str "These"
[2] Space
[3] Str "files"
Expand Down Expand Up @@ -124,7 +124,7 @@
(I) para.content[1] Str "These"
(I) para.content[1].text These
(I) para Para {
content: Inlines {
content: Inlines[37] {
[1] Str "There’s"
[2] Space
[3] Str "also"
Expand Down Expand Up @@ -171,7 +171,7 @@
[37] Str "output."
}
}
(I) para.content Inlines {
(I) para.content Inlines[37] {
[1] Str "There’s"
[2] Space
[3] Str "also"
Expand Down Expand Up @@ -220,43 +220,43 @@
(I) para.content[1] Str "There’s"
(I) para.content[1].text There’s
(I) para Para {
content: Inlines {
content: Inlines[11] {
[1] Str "Paragraph"
[2] Space
[3] Str "with"
[4] Space
[5] Emph {
content: Inlines {
content: Inlines[1] {
[1] Str "emphasized"
}
}
[6] Space
[7] Str "and"
[8] Space
[9] Strong {
content: Inlines {
content: Inlines[1] {
[1] Str "bold"
}
}
[10] Space
[11] Str "text."
}
}
(I) para.content Inlines {
(I) para.content Inlines[11] {
[1] Str "Paragraph"
[2] Space
[3] Str "with"
[4] Space
[5] Emph {
content: Inlines {
content: Inlines[1] {
[1] Str "emphasized"
}
}
[6] Space
[7] Str "and"
[8] Space
[9] Strong {
content: Inlines {
content: Inlines[1] {
[1] Str "bold"
}
}
Expand All @@ -265,12 +265,12 @@
}
(I) para.content[1] Str "Paragraph"
(I) para.content[1].text Paragraph
(I) para Para {content: Inlines {[1] Str "text"}}
(I) para.content Inlines {[1] Str "text"}
(I) para Para {content: Inlines[1] {[1] Str "text"}}
(I) para.content Inlines[1] {[1] Str "text"}
(I) para.content[1] Str "text"
(I) para.content[1].text text
(I) para Para {content: Inlines {[1] Str "smart-quote-’"}}
(I) para.content Inlines {[1] Str "smart-quote-’"}
(I) para Para {content: Inlines[1] {[1] Str "smart-quote-’"}}
(I) para.content Inlines[1] {[1] Str "smart-quote-’"}
(I) para.content[1] Str "smart-quote-’"
(I) para.content[1].text smart-quote-’
[INFO] Completed filter para2.lua in NN ms
Loading

0 comments on commit d8ab6aa

Please sign in to comment.