about summary refs log tree commit diff stats
path: root/test/lua/river.lua
diff options
context:
space:
mode:
authorCase Duckworth2015-03-14 11:33:14 -0700
committerCase Duckworth2015-03-14 11:33:14 -0700
commit4fe237fa977eb7fca100aac29960a21c09107217 (patch)
tree32d87372b7c258ebb5aac53c2ee2bdb8358b7554 /test/lua/river.lua
parentChange link underline style (diff)
downloadautocento-4fe237fa977eb7fca100aac29960a21c09107217.tar.gz
autocento-4fe237fa977eb7fca100aac29960a21c09107217.zip
Move test suite into its own folder
Diffstat (limited to 'test/lua/river.lua')
-rw-r--r--test/lua/river.lua226
1 files changed, 226 insertions, 0 deletions
diff --git a/test/lua/river.lua b/test/lua/river.lua new file mode 100644 index 0000000..d060ba9 --- /dev/null +++ b/test/lua/river.lua
@@ -0,0 +1,226 @@
1-- Pandoc River writer
2-- it takes out all formatting, leaving only a river of text
3-- running down the page: one word per line
4-- vim: fdm=marker
5-- invoke with: pandoc -t river.lua
6
7local function flow(s)
8 return s:gsub("%s+", "\n")
9end
10
11local function nude(s)
12 -- Expand contractions
13 s = s:gsub("'%a+%s", function (x)
14 if x == "'ll" then
15 return " will "
16 elseif x == "'ve" then
17 return " have "
18 elseif x == "'re" then
19 return " are "
20 else
21 return x
22 end
23 end)
24 -- Get rid of quotes around words
25 s = s:gsub('"', ' ')
26 s = s:gsub("%s+'", ' ')
27 s = s:gsub("'%s+", ' ')
28 -- Remove HTML entities
29 s = s:gsub('&.-;', ' ')
30 s = s:gsub('%b<>', ' ')
31 -- Remove end-of-line backslashes
32 s = s:gsub('%s+\\$', ' ')
33 -- Remove dashes (not hyphens)
34 s = s:gsub('%-%-+', ' ')
35 s = s:gsub('%-%s', ' ')
36 -- Remove general punctuation
37 s = s:gsub('[%.!%?:;,%[%]%(%)<>]', ' ')
38 -- Remove extra spaces
39 s = s:gsub('%s+', ' ')
40 return s:lower()
41end
42
43-- This function is called once for the whole document. Parameters:
44-- body is a string, metadata is a table, variables is a table.
45-- One could use some kind of templating
46-- system here; this just gives you a simple standalone HTML file.
47function Doc(body, metadata, variables)
48 local buffer = ""
49 local function add(s)
50 buffer = buffer .. nude(s) .. "\n"
51 end
52 if metadata['title'] then
53 add(metadata['title'])
54 end
55 if metadata['subtitle'] then
56 add(metadata['subtitle'])
57 end
58 -- TODO: epigraph.content, epigraph.attrib, dedication, other metadata?
59 add(body)
60 return flow(buffer)
61end
62
63-- Remove all formatting {{{
64function Note(s)
65 return nude(s)
66end
67
68function Blocksep()
69 return "\n"
70end
71function Emph(s)
72 return nude(s)
73end
74
75function Strong(s)
76 return nude(s)
77end
78
79function Subscript(s)
80 return nude(s)
81end
82
83function Superscript(s)
84 return nude(s)
85end
86
87function SmallCaps(s)
88 return nude(s)
89end
90
91function Strikeout(s)
92 return nude(s)
93end
94
95function Code(s, attr)
96 return nude(s)
97end
98
99function CodeBlock(s, attr)
100 return nude(s)
101end
102
103function InlineMath(s)
104 return nude(s)
105end
106
107function DisplayMath(s)
108 return nude(s)
109end
110
111function Span(s, attr)
112 return nude(s)
113end
114
115function Cite(s)
116 return nude(s)
117end
118
119function Plain(s)
120 return nude(s)
121end
122
123-- Links only include the link text
124function Link(s, src, tit)
125 return nude(s)
126end
127
128-- Images have nothing to give us
129-- (but add a space just in case)
130function Image(s, src, tit)
131 return "\n"
132end
133
134function CaptionedImage(s, src, tit)
135 return "\n"
136end
137
138function Str(s)
139 return nude(s)
140end
141
142function Div(s, attr)
143 return nude(s)
144end
145
146function Space(s)
147 return "\n"
148end
149
150function LineBreak()
151 return "\n"
152end
153
154function Para(s)
155 return nude(s)
156end
157
158function Header(lev, s, attr)
159 return nude(s)
160end
161
162function BlockQuote(s)
163 return nude(s)
164end
165
166function HorizontalRule()
167 return "\n"
168end
169
170function BulletList(items)
171 local buffer = ""
172 for _, item in pairs(items) do
173 buffer = buffer .. nude(item) .. "\n"
174 end
175 return buffer .. "\n"
176end
177
178function OrderedList(items)
179 local buffer = ""
180 for _, item in pairs(items) do
181 buffer = buffer .. nude(item) .. "\n"
182 end
183 return buffer .. "\n"
184end
185
186function DefinitionList(items)
187 local buffer = ""
188 for _, item in pairs(items) do
189 for k, v in pairs(item) do
190 buffer = buffer .. nude(k) .. "\n" .. nude(v) .. "\n"
191 end
192 end
193 return buffer .. "\n"
194end
195
196function Table(caption, aligns, widths, headers, rows)
197 local buffer = ""
198 local function add(s)
199 buffer = buffer .. nude(s) .. "\n"
200 end
201 if caption ~= "" then
202 add(caption)
203 end
204 for _,h in pairs(headers) do
205 add(h)
206 end
207 for _, row in pairs(rows) do
208 for _, cell in pairs(row) do
209 add(cell)
210 end
211 end
212 return buffer
213end
214-- }}}
215
216-- The following code will produce runtime warnings when you haven't defined
217-- all of the functions you need for the custom writer, so it's useful
218-- to include when you're working on a writer.
219local meta = {}
220meta.__index =
221 function(_, key)
222 io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key))
223 return function() return "" end
224 end
225setmetatable(_G, meta)
226