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