git.iko.soy/typeable/pandoc
on master help sign in
Added Text.Pandoc.Asciify utility module.

This has functions to create ascii-only versions of identifiers.

commitcecceee0d38109ea8846b8369bb5d85ac0491bf8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 23 Apr 2013, 20:00 (13 years ago) parenta405b81
3 files changed+425
CONTRIBUTING.md+2 pandoc.cabal+1 src/Text/Pandoc/Asciify.hs+422
CONTRIBUTING.md+2
@@ -167,6 +167,8 @@ The library is structured as follows:
167167 - `Text.Pandoc.Templates` defines pandoc's templating system.
168168 - `Text.Pandoc.UTF8` contains functions for converting text to and from
169169 UTF8 bytestrings (strict and lazy).
170+ - `Text.Pandoc.Asciify` contains functions to derive ascii versions of
171+ identifiers that use accented characters.
170172 - `Text.Pandoc.UUID` contains functions for generating UUIDs.
171173 - `Text.Pandoc.XML` contains functions for formatting XML.
172174
pandoc.cabal+1
@@ -324,6 +324,7 @@ Library
324324 Text.Pandoc.SelfContained
325325 Other-Modules: Text.Pandoc.Readers.Haddock.Lex,
326326 Text.Pandoc.Readers.Haddock.Parse,
327+ Text.Pandoc.Asciify,
327328 Text.Pandoc.MIME,
328329 Text.Pandoc.Parsing,
329330 Text.Pandoc.UUID,
src/Text/Pandoc/Asciify.hsnew file+422
@@ -0,0 +1,422 @@
1+{-
2+Copyright (C) 2013 John MacFarlane <jgm@berkeley.edu>
3+
4+This program is free software; you can redistribute it and/or modify
5+it under the terms of the GNU General Public License as published by
6+the Free Software Foundation; either version 2 of the License, or
7+(at your option) any later version.
8+
9+This program is distributed in the hope that it will be useful,
10+but WITHOUT ANY WARRANTY; without even the implied warranty of
11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+GNU General Public License for more details.
13+
14+You should have received a copy of the GNU General Public License
15+along with this program; if not, write to the Free Software
16+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+-}
18+
19+{- |
20+ Module : Text.Pandoc.SelfContained
21+ Copyright : Copyright (C) 2013 John MacFarlane
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : John MacFarlane <jgm@berkeley.edu>
25+ Stability : alpha
26+ Portability : portable
27+
28+Function to convert accented latin letters to their unaccented
29+ascii equivalents (used in constructing HTML identifiers).
30+-}
31+module Text.Pandoc.Asciify (toAsciiChar)
32+where
33+import qualified Data.Map as M
34+import Data.Char (isAscii)
35+
36+toAsciiChar :: Char -> Maybe Char
37+toAsciiChar c | isAscii c = Just c
38+ | otherwise = M.lookup c asciiMap
39+
40+asciiMap :: M.Map Char Char
41+asciiMap = M.fromList
42+ [('\192','A')
43+ ,('\193','A')
44+ ,('\194','A')
45+ ,('\195','A')
46+ ,('\196','A')
47+ ,('\197','A')
48+ ,('\199','C')
49+ ,('\200','E')
50+ ,('\201','E')
51+ ,('\202','E')
52+ ,('\203','E')
53+ ,('\204','I')
54+ ,('\205','I')
55+ ,('\206','I')
56+ ,('\207','I')
57+ ,('\209','N')
58+ ,('\210','O')
59+ ,('\211','O')
60+ ,('\212','O')
61+ ,('\213','O')
62+ ,('\214','O')
63+ ,('\217','U')
64+ ,('\218','U')
65+ ,('\219','U')
66+ ,('\220','U')
67+ ,('\221','Y')
68+ ,('\224','a')
69+ ,('\225','a')
70+ ,('\226','a')
71+ ,('\227','a')
72+ ,('\228','a')
73+ ,('\229','a')
74+ ,('\231','c')
75+ ,('\232','e')
76+ ,('\233','e')
77+ ,('\234','e')
78+ ,('\235','e')
79+ ,('\236','i')
80+ ,('\237','i')
81+ ,('\238','i')
82+ ,('\239','i')
83+ ,('\241','n')
84+ ,('\242','o')
85+ ,('\243','o')
86+ ,('\244','o')
87+ ,('\245','o')
88+ ,('\246','o')
89+ ,('\249','u')
90+ ,('\250','u')
91+ ,('\251','u')
92+ ,('\252','u')
93+ ,('\253','y')
94+ ,('\255','y')
95+ ,('\256','A')
96+ ,('\257','a')
97+ ,('\258','A')
98+ ,('\259','a')
99+ ,('\260','A')
100+ ,('\261','a')
101+ ,('\262','C')
102+ ,('\263','c')
103+ ,('\264','C')
104+ ,('\265','c')
105+ ,('\266','C')
106+ ,('\267','c')
107+ ,('\268','C')
108+ ,('\269','c')
109+ ,('\270','D')
110+ ,('\271','d')
111+ ,('\274','E')
112+ ,('\275','e')
113+ ,('\276','E')
114+ ,('\277','e')
115+ ,('\278','E')
116+ ,('\279','e')
117+ ,('\280','E')
118+ ,('\281','e')
119+ ,('\282','E')
120+ ,('\283','e')
121+ ,('\284','G')
122+ ,('\285','g')
123+ ,('\286','G')
124+ ,('\287','g')
125+ ,('\288','G')
126+ ,('\289','g')
127+ ,('\290','G')
128+ ,('\291','g')
129+ ,('\292','H')
130+ ,('\293','h')
131+ ,('\296','I')
132+ ,('\297','i')
133+ ,('\298','I')
134+ ,('\299','i')
135+ ,('\300','I')
136+ ,('\301','i')
137+ ,('\302','I')
138+ ,('\303','i')
139+ ,('\304','I')
140+ ,('\308','J')
141+ ,('\309','j')
142+ ,('\310','K')
143+ ,('\311','k')
144+ ,('\313','L')
145+ ,('\314','l')
146+ ,('\315','L')
147+ ,('\316','l')
148+ ,('\317','L')
149+ ,('\318','l')
150+ ,('\323','N')
151+ ,('\324','n')
152+ ,('\325','N')
153+ ,('\326','n')
154+ ,('\327','N')
155+ ,('\328','n')
156+ ,('\332','O')
157+ ,('\333','o')
158+ ,('\334','O')
159+ ,('\335','o')
160+ ,('\336','O')
161+ ,('\337','o')
162+ ,('\340','R')
163+ ,('\341','r')
164+ ,('\342','R')
165+ ,('\343','r')
166+ ,('\344','R')
167+ ,('\345','r')
168+ ,('\346','S')
169+ ,('\347','s')
170+ ,('\348','S')
171+ ,('\349','s')
172+ ,('\350','S')
173+ ,('\351','s')
174+ ,('\352','S')
175+ ,('\353','s')
176+ ,('\354','T')
177+ ,('\355','t')
178+ ,('\356','T')
179+ ,('\357','t')
180+ ,('\360','U')
181+ ,('\361','u')
182+ ,('\362','U')
183+ ,('\363','u')
184+ ,('\364','U')
185+ ,('\365','u')
186+ ,('\366','U')
187+ ,('\367','u')
188+ ,('\368','U')
189+ ,('\369','u')
190+ ,('\370','U')
191+ ,('\371','u')
192+ ,('\372','W')
193+ ,('\373','w')
194+ ,('\374','Y')
195+ ,('\375','y')
196+ ,('\376','Y')
197+ ,('\377','Z')
198+ ,('\378','z')
199+ ,('\379','Z')
200+ ,('\380','z')
201+ ,('\381','Z')
202+ ,('\382','z')
203+ ,('\416','O')
204+ ,('\417','o')
205+ ,('\431','U')
206+ ,('\432','u')
207+ ,('\461','A')
208+ ,('\462','a')
209+ ,('\463','I')
210+ ,('\464','i')
211+ ,('\465','O')
212+ ,('\466','o')
213+ ,('\467','U')
214+ ,('\468','u')
215+ ,('\486','G')
216+ ,('\487','g')
217+ ,('\488','K')
218+ ,('\489','k')
219+ ,('\490','O')
220+ ,('\491','o')
221+ ,('\496','j')
222+ ,('\500','G')
223+ ,('\501','g')
224+ ,('\504','N')
225+ ,('\505','n')
226+ ,('\512','A')
227+ ,('\513','a')
228+ ,('\514','A')
229+ ,('\515','a')
230+ ,('\516','E')
231+ ,('\517','e')
232+ ,('\518','E')
233+ ,('\519','e')
234+ ,('\520','I')
235+ ,('\521','i')
236+ ,('\522','I')
237+ ,('\523','i')
238+ ,('\524','O')
239+ ,('\525','o')
240+ ,('\526','O')
241+ ,('\527','o')
242+ ,('\528','R')
243+ ,('\529','r')
244+ ,('\530','R')
245+ ,('\531','r')
246+ ,('\532','U')
247+ ,('\533','u')
248+ ,('\534','U')
249+ ,('\535','u')
250+ ,('\536','S')
251+ ,('\537','s')
252+ ,('\538','T')
253+ ,('\539','t')
254+ ,('\542','H')
255+ ,('\543','h')
256+ ,('\550','A')
257+ ,('\551','a')
258+ ,('\552','E')
259+ ,('\553','e')
260+ ,('\558','O')
261+ ,('\559','o')
262+ ,('\562','Y')
263+ ,('\563','y')
264+ ,('\894',';')
265+ ,('\7680','A')
266+ ,('\7681','a')
267+ ,('\7682','B')
268+ ,('\7683','b')
269+ ,('\7684','B')
270+ ,('\7685','b')
271+ ,('\7686','B')
272+ ,('\7687','b')
273+ ,('\7690','D')
274+ ,('\7691','d')
275+ ,('\7692','D')
276+ ,('\7693','d')
277+ ,('\7694','D')
278+ ,('\7695','d')
279+ ,('\7696','D')
280+ ,('\7697','d')
281+ ,('\7698','D')
282+ ,('\7699','d')
283+ ,('\7704','E')
284+ ,('\7705','e')
285+ ,('\7706','E')
286+ ,('\7707','e')
287+ ,('\7710','F')
288+ ,('\7711','f')
289+ ,('\7712','G')
290+ ,('\7713','g')
291+ ,('\7714','H')
292+ ,('\7715','h')
293+ ,('\7716','H')
294+ ,('\7717','h')
295+ ,('\7718','H')
296+ ,('\7719','h')
297+ ,('\7720','H')
298+ ,('\7721','h')
299+ ,('\7722','H')
300+ ,('\7723','h')
301+ ,('\7724','I')
302+ ,('\7725','i')
303+ ,('\7728','K')
304+ ,('\7729','k')
305+ ,('\7730','K')
306+ ,('\7731','k')
307+ ,('\7732','K')
308+ ,('\7733','k')
309+ ,('\7734','L')
310+ ,('\7735','l')
311+ ,('\7738','L')
312+ ,('\7739','l')
313+ ,('\7740','L')
314+ ,('\7741','l')
315+ ,('\7742','M')
316+ ,('\7743','m')
317+ ,('\7744','M')
318+ ,('\7745','m')
319+ ,('\7746','M')
320+ ,('\7747','m')
321+ ,('\7748','N')
322+ ,('\7749','n')
323+ ,('\7750','N')
324+ ,('\7751','n')
325+ ,('\7752','N')
326+ ,('\7753','n')
327+ ,('\7754','N')
328+ ,('\7755','n')
329+ ,('\7764','P')
330+ ,('\7765','p')
331+ ,('\7766','P')
332+ ,('\7767','p')
333+ ,('\7768','R')
334+ ,('\7769','r')
335+ ,('\7770','R')
336+ ,('\7771','r')
337+ ,('\7774','R')
338+ ,('\7775','r')
339+ ,('\7776','S')
340+ ,('\7777','s')
341+ ,('\7778','S')
342+ ,('\7779','s')
343+ ,('\7786','T')
344+ ,('\7787','t')
345+ ,('\7788','T')
346+ ,('\7789','t')
347+ ,('\7790','T')
348+ ,('\7791','t')
349+ ,('\7792','T')
350+ ,('\7793','t')
351+ ,('\7794','U')
352+ ,('\7795','u')
353+ ,('\7796','U')
354+ ,('\7797','u')
355+ ,('\7798','U')
356+ ,('\7799','u')
357+ ,('\7804','V')
358+ ,('\7805','v')
359+ ,('\7806','V')
360+ ,('\7807','v')
361+ ,('\7808','W')
362+ ,('\7809','w')
363+ ,('\7810','W')
364+ ,('\7811','w')
365+ ,('\7812','W')
366+ ,('\7813','w')
367+ ,('\7814','W')
368+ ,('\7815','w')
369+ ,('\7816','W')
370+ ,('\7817','w')
371+ ,('\7818','X')
372+ ,('\7819','x')
373+ ,('\7820','X')
374+ ,('\7821','x')
375+ ,('\7822','Y')
376+ ,('\7823','y')
377+ ,('\7824','Z')
378+ ,('\7825','z')
379+ ,('\7826','Z')
380+ ,('\7827','z')
381+ ,('\7828','Z')
382+ ,('\7829','z')
383+ ,('\7830','h')
384+ ,('\7831','t')
385+ ,('\7832','w')
386+ ,('\7833','y')
387+ ,('\7840','A')
388+ ,('\7841','a')
389+ ,('\7842','A')
390+ ,('\7843','a')
391+ ,('\7864','E')
392+ ,('\7865','e')
393+ ,('\7866','E')
394+ ,('\7867','e')
395+ ,('\7868','E')
396+ ,('\7869','e')
397+ ,('\7880','I')
398+ ,('\7881','i')
399+ ,('\7882','I')
400+ ,('\7883','i')
401+ ,('\7884','O')
402+ ,('\7885','o')
403+ ,('\7886','O')
404+ ,('\7887','o')
405+ ,('\7908','U')
406+ ,('\7909','u')
407+ ,('\7910','U')
408+ ,('\7911','u')
409+ ,('\7922','Y')
410+ ,('\7923','y')
411+ ,('\7924','Y')
412+ ,('\7925','y')
413+ ,('\7926','Y')
414+ ,('\7927','y')
415+ ,('\7928','Y')
416+ ,('\7929','y')
417+ ,('\8175','`')
418+ ,('\8490','K')
419+ ,('\8800','=')
420+ ,('\8814','<')
421+ ,('\8815','>')
422+ ]