diff options
author | Case Duckworth | 2015-04-14 16:36:17 -0700 |
---|---|---|
committer | Case Duckworth | 2015-04-14 16:36:17 -0700 |
commit | 9fce418b46c9f0894f429384ef9e3dabaeffbeb4 (patch) | |
tree | b2339220ee50cf48b8887f0cc1fed4813a95901b /trunk/hapax.lua | |
parent | Add toc metadata (diff) | |
download | autocento-9fce418b46c9f0894f429384ef9e3dabaeffbeb4.tar.gz autocento-9fce418b46c9f0894f429384ef9e3dabaeffbeb4.zip |
Change file hierarchy and rewrite makefile
- File hierarchy is now as follows: - / - appendix/ < appendix source files - backlinks/ < backlink sources & builds - hapax/ < *.hapax source files - scripts/ < scripts, like *.js, *.hs, etc. - templates/ < templates for outputs - text/ < source files - trunk/ < assets, like css, images, heads, etc. - index.html - *.html - Makefile
Diffstat (limited to 'trunk/hapax.lua')
-rw-r--r-- | trunk/hapax.lua | 251 |
1 files changed, 0 insertions, 251 deletions
diff --git a/trunk/hapax.lua b/trunk/hapax.lua deleted file mode 100644 index af59e59..0000000 --- a/trunk/hapax.lua +++ /dev/null | |||
@@ -1,251 +0,0 @@ | |||
1 | -- Pandoc Hapax writer | ||
2 | -- it takes out all formatting, leaving only a river of text | ||
3 | -- running down the page: one word per line, stripping all duplicates | ||
4 | -- vim: fdm=marker | ||
5 | -- invoke with: pandoc -t hapax.lua | ||
6 | |||
7 | os.setlocale("en_US.UTF-8") | ||
8 | |||
9 | function hapax(s) | ||
10 | local function tablify (s, p) | ||
11 | local t={} | ||
12 | for w in s:gmatch(p) do | ||
13 | table.insert(t, w) | ||
14 | end | ||
15 | return t | ||
16 | end | ||
17 | local function stripDupes (t) | ||
18 | local seen = {} | ||
19 | local remove = {} | ||
20 | for i = 1, #t do | ||
21 | element = t[i] | ||
22 | if seen[element] then | ||
23 | remove[element] = true | ||
24 | else | ||
25 | seen[element] = true | ||
26 | end | ||
27 | end | ||
28 | for i = #t, 1, -1 do | ||
29 | if remove[t[i]] then | ||
30 | table.remove(t, i) | ||
31 | end | ||
32 | end | ||
33 | return t | ||
34 | end | ||
35 | return table.concat(stripDupes(tablify(s, "%S+")), "\n") | ||
36 | end | ||
37 | |||
38 | function flow(s) | ||
39 | return s:gsub("%s+", "\n") | ||
40 | end | ||
41 | |||
42 | function nude(s) | ||
43 | s = s:lower() | ||
44 | -- Expand contractions | ||
45 | s = s:gsub("'ll", " will ") | ||
46 | s = s:gsub("'ve", " have ") | ||
47 | s = s:gsub("'re", " are ") | ||
48 | s = s:gsub("i'm", " i am ") | ||
49 | s = s:gsub("it's", "it is") | ||
50 | s = s:gsub("n't", " not ") | ||
51 | s = s:gsub("&", " and ") | ||
52 | -- -- Remove dashes (not hyphens) | ||
53 | s = s:gsub('%-[%-%s]+', ' ') | ||
54 | -- Remove everything that is not letters or numbers | ||
55 | s = s:gsub('[^A-Za-z0-9/\'-]', ' ') | ||
56 | -- Remove extra spaces | ||
57 | s = s:gsub('%s+', ' ') | ||
58 | return " "..s.." " | ||
59 | end | ||
60 | |||
61 | -- This function is called once for the whole document. Parameters: | ||
62 | -- body is a string, metadata is a table, variables is a table. | ||
63 | -- One could use some kind of templating | ||
64 | -- system here; this just gives you a simple standalone HTML file. | ||
65 | function Doc(body, metadata, variables) | ||
66 | local buffer = "" | ||
67 | local function add(s) | ||
68 | buffer = buffer .. nude(s) .. "\n" | ||
69 | end | ||
70 | if metadata['title'] then | ||
71 | add(metadata['title']) | ||
72 | end | ||
73 | if metadata['subtitle'] then | ||
74 | add(metadata['subtitle']) | ||
75 | end | ||
76 | add(body) | ||
77 | return hapax(flow(buffer)) | ||
78 | -- return flow(buffer) | ||
79 | end | ||
80 | |||
81 | -- Remove all formatting {{{ | ||
82 | function Note(s) | ||
83 | return s | ||
84 | end | ||
85 | |||
86 | function Blocksep() | ||
87 | return "\n" | ||
88 | end | ||
89 | function Emph(s) | ||
90 | return s | ||
91 | end | ||
92 | |||
93 | function Strong(s) | ||
94 | return s | ||
95 | end | ||
96 | |||
97 | function Subscript(s) | ||
98 | return s | ||
99 | end | ||
100 | |||
101 | function Superscript(s) | ||
102 | return s | ||
103 | end | ||
104 | |||
105 | function SmallCaps(s) | ||
106 | return s | ||
107 | end | ||
108 | |||
109 | function Strikeout(s) | ||
110 | return s | ||
111 | end | ||
112 | |||
113 | function Code(s, attr) | ||
114 | return s | ||
115 | end | ||
116 | |||
117 | function CodeBlock(s, attr) | ||
118 | return s | ||
119 | end | ||
120 | |||
121 | function InlineMath(s) | ||
122 | return s | ||
123 | end | ||
124 | |||
125 | function DisplayMath(s) | ||
126 | return s | ||
127 | end | ||
128 | |||
129 | function Span(s, attr) | ||
130 | return s | ||
131 | end | ||
132 | |||
133 | function Cite(s) | ||
134 | return s | ||
135 | end | ||
136 | |||
137 | function Plain(s) | ||
138 | return s | ||
139 | end | ||
140 | |||
141 | -- Links only include the link text | ||
142 | function Link(s, src, tit) | ||
143 | return s | ||
144 | end | ||
145 | |||
146 | -- Images have nothing to give us | ||
147 | -- (but add a space just in case) | ||
148 | function Image(s, src, tit) | ||
149 | return "\n" | ||
150 | end | ||
151 | |||
152 | function RawBlock(s) | ||
153 | return s | ||
154 | end | ||
155 | |||
156 | function RawInline(s) | ||
157 | return s | ||
158 | end | ||
159 | |||
160 | function CaptionedImage(s, src, tit) | ||
161 | return "\n" | ||
162 | end | ||
163 | |||
164 | function Str(s) | ||
165 | return s | ||
166 | end | ||
167 | |||
168 | function Div(s, attr) | ||
169 | return s | ||
170 | end | ||
171 | |||
172 | function Space(s) | ||
173 | return "\n" | ||
174 | end | ||
175 | |||
176 | function LineBreak() | ||
177 | return "\n" | ||
178 | end | ||
179 | |||
180 | function Para(s) | ||
181 | return s | ||
182 | end | ||
183 | |||
184 | function Header(lev, s, attr) | ||
185 | return s | ||
186 | end | ||
187 | |||
188 | function BlockQuote(s) | ||
189 | return s | ||
190 | end | ||
191 | |||
192 | function HorizontalRule() | ||
193 | return "\n" | ||
194 | end | ||
195 | |||
196 | function BulletList(items) | ||
197 | local buffer = "" | ||
198 | for _, item in pairs(items) do | ||
199 | buffer = buffer .. " " .. item .. "\n" | ||
200 | end | ||
201 | return buffer .. "\n" | ||
202 | end | ||
203 | |||
204 | function OrderedList(items) | ||
205 | local buffer = "" | ||
206 | for _, item in pairs(items) do | ||
207 | buffer = buffer .. " " .. item .. "\n" | ||
208 | end | ||
209 | return buffer .. "\n" | ||
210 | end | ||
211 | |||
212 | function DefinitionList(items) | ||
213 | local buffer = "" | ||
214 | for _, item in pairs(items) do | ||
215 | for k, v in pairs(item) do | ||
216 | buffer = buffer .. " " .. k .. "\n" .. v .. "\n" | ||
217 | end | ||
218 | end | ||
219 | return buffer .. "\n" | ||
220 | end | ||
221 | |||
222 | function Table(caption, aligns, widths, headers, rows) | ||
223 | local buffer = "" | ||
224 | local function add(s) | ||
225 | buffer = buffer .. " " .. s .. "\n" | ||
226 | end | ||
227 | if caption ~= "" then | ||
228 | add(caption) | ||
229 | end | ||
230 | for _,h in pairs(headers) do | ||
231 | add(h) | ||
232 | end | ||
233 | for _, row in pairs(rows) do | ||
234 | for _, cell in pairs(row) do | ||
235 | add(cell) | ||
236 | end | ||
237 | end | ||
238 | return buffer | ||
239 | end | ||
240 | -- }}} | ||
241 | |||
242 | -- The following code will produce runtime warnings when you haven't defined | ||
243 | -- all of the functions you need for the custom writer, so it's useful | ||
244 | -- to include when you're working on a writer. | ||
245 | local meta = {} | ||
246 | meta.__index = | ||
247 | function(_, key) | ||
248 | io.stderr:write(string.format("WARNING: Undefined function '%s'\n",key)) | ||
249 | return function() return "" end | ||
250 | end | ||
251 | setmetatable(_G, meta) | ||