about summary refs log tree commit diff stats
path: root/lua/river.lua
diff options
context:
space:
mode:
authorCase Duckworth2015-03-26 19:46:45 -0700
committerCase Duckworth2015-03-26 19:46:45 -0700
commitc654151582a77a0b459e3f55b687e43a32d4b67d (patch)
tree6d5d5d2b5f5650b494318e66cef6135b32c0cc72 /lua/river.lua
parentFlatten directory structure (diff)
downloadautocento-c654151582a77a0b459e3f55b687e43a32d4b67d.tar.gz
autocento-c654151582a77a0b459e3f55b687e43a32d4b67d.zip
Add HAPAX LEGOMENA support & flatten structure
The list of hapax legomena for this project is available at /hapax.html.

In addition, the directory structure has been further flattened.
All assets (javascript, lua, images, fonts) are in /trunk/.

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