diff options
Diffstat (limited to 'trunk/river.lua')
-rw-r--r-- | trunk/river.lua | 230 |
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 | |||
7 | os.setlocale("en_US.UTF-8") | ||
8 | |||
9 | local function flow(s) | ||
10 | return s:gsub("%s+", "\n") | ||
11 | end | ||
12 | |||
13 | local 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() | ||
45 | end | ||
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. | ||
51 | function 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) | ||
65 | end | ||
66 | |||
67 | -- Remove all formatting {{{ | ||
68 | function Note(s) | ||
69 | return nude(s) | ||
70 | end | ||
71 | |||
72 | function Blocksep() | ||
73 | return "\n" | ||
74 | end | ||
75 | function Emph(s) | ||
76 | return nude(s) | ||
77 | end | ||
78 | |||
79 | function Strong(s) | ||
80 | return nude(s) | ||
81 | end | ||
82 | |||
83 | function Subscript(s) | ||
84 | return nude(s) | ||
85 | end | ||
86 | |||
87 | function Superscript(s) | ||
88 | return nude(s) | ||
89 | end | ||
90 | |||
91 | function SmallCaps(s) | ||
92 | return nude(s) | ||
93 | end | ||
94 | |||
95 | function Strikeout(s) | ||
96 | return nude(s) | ||
97 | end | ||
98 | |||
99 | function Code(s, attr) | ||
100 | return nude(s) | ||
101 | end | ||
102 | |||
103 | function CodeBlock(s, attr) | ||
104 | return nude(s) | ||
105 | end | ||
106 | |||
107 | function InlineMath(s) | ||
108 | return nude(s) | ||
109 | end | ||
110 | |||
111 | function DisplayMath(s) | ||
112 | return nude(s) | ||
113 | end | ||
114 | |||
115 | function Span(s, attr) | ||
116 | return nude(s) | ||
117 | end | ||
118 | |||
119 | function Cite(s) | ||
120 | return nude(s) | ||
121 | end | ||
122 | |||
123 | function Plain(s) | ||
124 | return nude(s) | ||
125 | end | ||
126 | |||
127 | -- Links only include the link text | ||
128 | function Link(s, src, tit) | ||
129 | return nude(s) | ||
130 | end | ||
131 | |||
132 | -- Images have nothing to give us | ||
133 | -- (but add a space just in case) | ||
134 | function Image(s, src, tit) | ||
135 | return "\n" | ||
136 | end | ||
137 | |||
138 | function CaptionedImage(s, src, tit) | ||
139 | return "\n" | ||
140 | end | ||
141 | |||
142 | function Str(s) | ||
143 | return nude(s) | ||
144 | end | ||
145 | |||
146 | function Div(s, attr) | ||
147 | return nude(s) | ||
148 | end | ||
149 | |||
150 | function Space(s) | ||
151 | return "\n" | ||
152 | end | ||
153 | |||
154 | function LineBreak() | ||
155 | return "\n" | ||
156 | end | ||
157 | |||
158 | function Para(s) | ||
159 | return nude(s) | ||
160 | end | ||
161 | |||
162 | function Header(lev, s, attr) | ||
163 | return nude(s) | ||
164 | end | ||
165 | |||
166 | function BlockQuote(s) | ||
167 | return nude(s) | ||
168 | end | ||
169 | |||
170 | function HorizontalRule() | ||
171 | return "\n" | ||
172 | end | ||
173 | |||
174 | function BulletList(items) | ||
175 | local buffer = "" | ||
176 | for _, item in pairs(items) do | ||
177 | buffer = buffer .. nude(item) .. "\n" | ||
178 | end | ||
179 | return buffer .. "\n" | ||
180 | end | ||
181 | |||
182 | function OrderedList(items) | ||
183 | local buffer = "" | ||
184 | for _, item in pairs(items) do | ||
185 | buffer = buffer .. nude(item) .. "\n" | ||
186 | end | ||
187 | return buffer .. "\n" | ||
188 | end | ||
189 | |||
190 | function 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" | ||
198 | end | ||
199 | |||
200 | function 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 | ||
217 | end | ||
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. | ||
223 | local meta = {} | ||
224 | meta.__index = | ||
225 | function(_, key) | ||
226 | io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) | ||
227 | return function() return "" end | ||
228 | end | ||
229 | setmetatable(_G, meta) | ||
230 | |||