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