Skip to content

Commit ed684bd

Browse files
committed
Merge remote-tracking branch 'upstream/master' into biblio-place
2 parents 71e68b7 + 8ebbe09 commit ed684bd

File tree

10 files changed

+168
-39
lines changed

10 files changed

+168
-39
lines changed

abstract-to-meta/Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
DIFF ?= diff --strip-trailing-cr -u
22

3-
test: sample.md abstract-to-meta.lua
4-
@pandoc --lua-filter=abstract-to-meta.lua --standalone --to=markdown $< \
5-
| $(DIFF) expected.md -
3+
test: sample1.md sample2.md abstract-to-meta.lua
4+
@pandoc --lua-filter=abstract-to-meta.lua --standalone --to=markdown \
5+
sample1.md | $(DIFF) expected1.md -
6+
@pandoc --lua-filter=abstract-to-meta.lua --standalone --to=markdown \
7+
sample2.md | $(DIFF) expected2.md -
68

7-
expected.md: sample.md abstract-to-meta.lua
9+
expected: sample1.md expected1.md sample2.md expected2.md abstract-to-meta.lua
10+
11+
expected1.md: sample1.md abstract-to-meta.lua
12+
pandoc --lua-filter=abstract-to-meta.lua --standalone --output $@ $<
13+
14+
expected2.md: sample2.md abstract-to-meta.lua
815
pandoc --lua-filter=abstract-to-meta.lua --standalone --output $@ $<
916

1017
.PHONY: test

abstract-to-meta/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,21 @@ satisfy this condition.^[1]
3535

3636
[1]: This requires the `auto_identifier` extension. It is
3737
enabled by default.
38+
39+
The abstract can be placed anywhere in the document.
40+
41+
The filter assumes that the abstract runs up until the next
42+
heading or a [horizontal rule], whichever comes first). Thus the
43+
abstract can be placed at the beginning of a document whose text
44+
doesn't start with a heading:
45+
46+
# Abstract
47+
48+
The abstract text includes this.
49+
50+
* * * *
51+
52+
This text is the beginning of the document.
53+
54+
55+
[horizontal rule]: https://pandoc.org/MANUAL.html#horizontal-rules

abstract-to-meta/abstract-to-meta.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ function abstract_from_blocklist (blocks)
2020
body_blocks[#body_blocks + 1] = block
2121
end
2222
elseif looking_at_abstract then
23-
abstract[#abstract + 1] = block
23+
if block.t == 'HorizontalRule' then
24+
looking_at_abstract = false
25+
else
26+
abstract[#abstract + 1] = block
27+
end
2428
else
2529
body_blocks[#body_blocks + 1] = block
2630
end
File renamed without changes.

abstract-to-meta/expected2.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
abstract: |
3+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
4+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
5+
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
6+
aliquip ex ea commodo consequat. Duis aute irure dolor in
7+
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
8+
pariatur.
9+
10+
- one
11+
- two
12+
- three
13+
14+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
15+
officia deserunt mollit anim id est laborum.
16+
---
17+
18+
::: {.frontmatter}
19+
Mauris vel erat tincidunt, venenatis elit ac, luctus augue. Aliquam sed
20+
hendrerit augue. Donec finibus mi et dolor semper, non malesuada nulla
21+
ullamcorper. Fusce auctor ullamcorper nunc, sit amet molestie nunc
22+
ornare ac. Nunc vulputate non ante vitae hendrerit. Pellentesque
23+
habitant morbi tristique senectus et netus et malesuada fames ac turpis
24+
egestas. Ut maximus enim molestie ex egestas, a tincidunt quam rhoncus.
25+
Quisque tincidunt est arcu, quis aliquet justo varius a. Fusce nec massa
26+
neque.
27+
:::
28+
29+
# Lorem Ipsum
30+
31+
Quo dolore molestiae et laboriosam occaecati explicabo corrupti. Earum
32+
expedita ducimus quaerat est quam ut molestiae. Illum deleniti vel
33+
labore facilis et cum est. Est nemo est vel ad. Assumenda consequatur
34+
rerum officiis atque officia. Est nihil iste cumque ad qui.

abstract-to-meta/sample.md renamed to abstract-to-meta/sample1.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ deserunt mollit anim id est laborum.
2525

2626
# Lorem Ipsum
2727

28-
Quo dolore molestiae et laboriosam occaecati explicabo corrupti. Earum expedita
29-
ducimus quaerat est quam ut molestiae. Illum deleniti vel labore facilis et cum
30-
est. Est nemo est vel ad. Assumenda consequatur rerum officiis atque officia.
31-
Est nihil iste cumque ad qui.
28+
Quo dolore molestiae et laboriosam occaecati explicabo corrupti.
29+
Earum expedita ducimus quaerat est quam ut molestiae. Illum
30+
deleniti vel labore facilis et cum est. Est nemo est vel ad.
31+
Assumenda consequatur rerum officiis atque officia. Est nihil iste
32+
cumque ad qui.

abstract-to-meta/sample2.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
::: {.frontmatter}
2+
# Abstract
3+
4+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
5+
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
6+
enim ad minim veniam, quis nostrud exercitation ullamco laboris
7+
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
8+
reprehenderit in voluptate velit esse cillum dolore eu fugiat
9+
nulla pariatur.
10+
11+
- one
12+
- two
13+
- three
14+
15+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
16+
officia deserunt mollit anim id est laborum.
17+
18+
---
19+
20+
Mauris vel erat tincidunt, venenatis elit ac, luctus augue.
21+
Aliquam sed hendrerit augue. Donec finibus mi et dolor semper, non
22+
malesuada nulla ullamcorper. Fusce auctor ullamcorper nunc, sit
23+
amet molestie nunc ornare ac. Nunc vulputate non ante vitae
24+
hendrerit. Pellentesque habitant morbi tristique senectus et netus
25+
et malesuada fames ac turpis egestas. Ut maximus enim molestie ex
26+
egestas, a tincidunt quam rhoncus. Quisque tincidunt est arcu,
27+
quis aliquet justo varius a. Fusce nec massa neque.
28+
:::
29+
30+
# Lorem Ipsum
31+
32+
Quo dolore molestiae et laboriosam occaecati explicabo corrupti.
33+
Earum expedita ducimus quaerat est quam ut molestiae. Illum
34+
deleniti vel labore facilis et cum est. Est nemo est vel ad.
35+
Assumenda consequatur rerum officiis atque officia. Est nihil iste
36+
cumque ad qui.

diagram-generator/diagram-generator.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ function CodeBlock(block)
355355
--
356356
-- to be referenced as @fig:example outside of the figure when used
357357
-- with `pandoc-crossref`.
358-
local img_attr = pandoc.Attr {
358+
local img_attr = {
359359
id = block.identifier,
360360
name = block.attributes.name
361361
}

wordcount/README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
# wordcount
22

3-
This filter counts the words and characters in the body of a document (omitting
4-
metadata like titles and abstracts), including words in code.
5-
It should be more accurate than `wc -w` or `wc -m` run directly on a
6-
Markdown document, since `wc` will also count markup
7-
characters, like the `#` in front of an ATX header, or
8-
tags in HTML documents.
3+
This filter counts the words and characters in the body of a document
4+
(omitting metadata like titles and abstracts), including words in
5+
code. It should be more accurate than `wc -w` or `wc -m` run directly
6+
on a Markdown document, since `wc` will also count markup characters,
7+
like the `#` in front of an ATX header, or tags in HTML documents.
98

109
To run it, `pandoc --lua-filter wordcount.lua myfile.md`.
1110
The word count will be printed to stdout.
11+
12+
If you want to process the document as well as printing the word count
13+
set the variable `wordcount` to `process` (or `process-anyway` or `convert`).
14+
This works only in conjunction with the standalone document option (`-s`).
15+
This can be done through the command line:
16+
17+
```
18+
pandoc -s -L wordcount.lua -M wordcount=process sample.md -o output.html
19+
```
20+
21+
Or the document's metadata block:
22+
23+
```
24+
---
25+
title: My Long Book
26+
wordcount: process-anyway
27+
---
28+
```
29+

wordcount/wordcount.lua

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,56 @@
1-
-- counts words in a document
1+
-- counts words in a document
22

3-
words = 0
3+
words = 0
44
characters = 0
55
characters_and_spaces = 0
6+
process_anyway = false
67

7-
wordcount = {
8-
Str = function(el)
9-
-- we don't count a word if it's entirely punctuation:
10-
if el.text:match("%P") then
11-
words = words + 1
12-
end
8+
wordcount = {
9+
Str = function(el)
10+
-- we don't count a word if it's entirely punctuation:
11+
if el.text:match("%P") then
12+
words = words + 1
13+
end
1314
characters = characters + utf8.len(el.text)
1415
characters_and_spaces = characters_and_spaces + utf8.len(el.text)
15-
end,
16+
end,
1617

1718
Space = function(el)
1819
characters_and_spaces = characters_and_spaces + 1
1920
end,
2021

21-
Code = function(el)
22-
_,n = el.text:gsub("%S+","")
23-
words = words + n
22+
Code = function(el)
23+
_,n = el.text:gsub("%S+","")
24+
words = words + n
2425
text_nospace = el.text:gsub("%s", "")
2526
characters = characters + utf8.len(text_nospace)
2627
characters_and_spaces = characters_and_spaces + utf8.len(el.text)
27-
end,
28+
end,
2829

29-
CodeBlock = function(el)
30-
_,n = el.text:gsub("%S+","")
31-
words = words + n
30+
CodeBlock = function(el)
31+
_,n = el.text:gsub("%S+","")
32+
words = words + n
3233
text_nospace = el.text:gsub("%s", "")
3334
characters = characters + utf8.len(text_nospace)
3435
characters_and_spaces = characters_and_spaces + utf8.len(el.text)
35-
end
36-
}
36+
end
37+
}
38+
39+
-- check if the `wordcount` variable is set to `process-anyway`
40+
function Meta(meta)
41+
if meta.wordcount and (meta.wordcount=="process-anyway"
42+
or meta.wordcount=="process" or meta.wordcount=="convert") then
43+
process_anyway = true
44+
end
45+
end
3746

38-
function Pandoc(el)
39-
-- skip metadata, just count body:
40-
pandoc.walk_block(pandoc.Div(el.blocks), wordcount)
41-
print(words .. " words in body")
47+
function Pandoc(el)
48+
-- skip metadata, just count body:
49+
pandoc.walk_block(pandoc.Div(el.blocks), wordcount)
50+
print(words .. " words in body")
4251
print(characters .. " characters in body")
4352
print(characters_and_spaces .. " characters in body (including spaces)")
44-
os.exit(0)
53+
if not process_anyway then
54+
os.exit(0)
55+
end
4556
end

0 commit comments

Comments
 (0)