git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1509 from jkr/symbol

Parse "w:sym"

commiteed1274fcaa0348fd08624eaa863ad26248958de authorJohn MacFarlane <jgm@berkeley.edu> dateSat 9 Aug 2014, 20:22 (12 years ago) parentc2a0d47ecb42cc
8 files changed+563−1
lib/fonts/Makefile+6 lib/fonts/parseUnicodeMapping.hs+40 lib/fonts/symbol.txt+256 pandoc.cabal+1 src/Text/Pandoc/Readers/Docx/Fonts.hs+237 src/Text/Pandoc/Readers/Docx/Parse.hs+22 tests/docx.unicode.docx tests/docx.unicode.native+1−1
lib/fonts/Makefilenew file+6
@@ -0,0 +1,6 @@
1+symbol.hs: symbol.txt
2+ runghc parseUnicodeMapping.hs symbol.txt
3+
4+.PHONY: clean
5+clean:
6+ -rm symbol.hs
lib/fonts/parseUnicodeMapping.hsnew file+40
@@ -0,0 +1,40 @@
1+import System.FilePath
2+import Text.Parsec
3+import Data.Char
4+import System.Environment
5+import Control.Applicative hiding (many)
6+import Data.List
7+
8+main :: IO ()
9+main = (head <$> getArgs) >>= parseUnicodeMapping
10+
11+
12+parseUnicodeMapping :: FilePath -> IO ()
13+parseUnicodeMapping fname = do
14+ fin <- readFile fname
15+ let mapname = dropExtension . takeFileName $ fname
16+ let res = runParse fin
17+ let header = "-- Generated from " ++ fname ++ "\n" ++
18+ mapname ++ " :: [(Char, Char)]\n" ++ mapname ++" =\n [ "
19+ let footer = "]"
20+ writeFile (replaceExtension fname ".hs")
21+ (header ++ (concat $ intersperse "\n , " (map show res)) ++ footer)
22+
23+type Unicode = Char
24+
25+runParse :: String -> [(Char, Unicode)]
26+runParse s= either (error . show) id (parse parseMap "" s)
27+
28+anyline = manyTill anyChar newline
29+
30+getHexChar :: Parsec String () Char
31+getHexChar = do
32+ [(c,_)] <- readLitChar . ("\\x" ++) <$> many1 hexDigit
33+ return c
34+
35+parseMap :: Parsec String () [(Char, Unicode)]
36+parseMap = do
37+ skipMany (char '#' >> anyline)
38+ many (flip (,) <$> getHexChar <* tab <*> getHexChar <* anyline)
39+
40+
lib/fonts/symbol.txtnew file+256
@@ -0,0 +1,256 @@
1+#
2+# Name: Adobe Symbol Encoding to Unicode
3+# Unicode version: 2.0
4+# Table version: 1.0
5+# Date: 2011 July 12
6+#
7+# Copyright (c) 1991-2011 Unicode, Inc. All Rights reserved.
8+#
9+# This file is provided as-is by Unicode, Inc. (The Unicode Consortium). No
10+# claims are made as to fitness for any particular purpose. No warranties of
11+# any kind are expressed or implied. The recipient agrees to determine
12+# applicability of information provided. If this file has been provided on
13+# magnetic media by Unicode, Inc., the sole remedy for any claim will be
14+# exchange of defective media within 90 days of receipt.
15+#
16+# Unicode, Inc. hereby grants the right to freely use the information
17+# supplied in this file in the creation of products supporting the
18+# Unicode Standard, and to make copies of this file in any form for
19+# internal or external distribution as long as this notice remains
20+# attached.
21+#
22+# Format: 4 tab-delimited fields:
23+#
24+# (1) The Unicode value (in hexadecimal)
25+# (2) The Symbol Encoding code point (in hexadecimal)
26+# (3) # Unicode name
27+# (4) # PostScript character name
28+#
29+# General Notes:
30+#
31+# The Unicode values in this table were produced as the result of applying
32+# the algorithm described in the section "Populating a Unicode space" in the
33+# document "Unicode and Glyph Names," at
34+# http://partners.adobe.com/asn/developer/typeforum/unicodegn.html
35+# to the characters in Symbol. Note that some characters, such as "space",
36+# are mapped to 2 Unicode values. 29 characters have assignments in the
37+# Corporate Use Subarea; these are indicated by "(CUS)" in field 4. Refer to
38+# the above document for more details.
39+#
40+# 2011 July 12: The above link is no longer valid. For comparable,
41+# more current information, see the document, "Glyph", at:
42+# <http://www.adobe.com/devnet/opentype/archives/glyph.html>
43+#
44+# Revision History:
45+#
46+# [v1.0, 2011 July 12]
47+# Updated terms of use to current wording.
48+# Updated contact information and document link.
49+# No changes to the mapping data.
50+#
51+# [v0.2, 30 March 1999]
52+# Different algorithm to produce Unicode values (see notes above) results in
53+# some character codes being mapped to 2 Unicode values; use of Corporate
54+# Use subarea values; addition of the euro character; changed assignments of
55+# some characters such as the COPYRIGHT SIGNs and RADICAL EXTENDER. Updated
56+# Unicode names to Unicode 2.0 names.
57+#
58+# [v0.1, 5 May 1995] First release.
59+#
60+# Use the Unicode reporting form <http://www.unicode.org/reporting.html>
61+# for any questions or comments or to report errors in the data.
62+#
63+0020 20 # SPACE # space
64+00A0 20 # NO-BREAK SPACE # space
65+0021 21 # EXCLAMATION MARK # exclam
66+2200 22 # FOR ALL # universal
67+0023 23 # NUMBER SIGN # numbersign
68+2203 24 # THERE EXISTS # existential
69+0025 25 # PERCENT SIGN # percent
70+0026 26 # AMPERSAND # ampersand
71+220B 27 # CONTAINS AS MEMBER # suchthat
72+0028 28 # LEFT PARENTHESIS # parenleft
73+0029 29 # RIGHT PARENTHESIS # parenright
74+2217 2A # ASTERISK OPERATOR # asteriskmath
75+002B 2B # PLUS SIGN # plus
76+002C 2C # COMMA # comma
77+2212 2D # MINUS SIGN # minus
78+002E 2E # FULL STOP # period
79+002F 2F # SOLIDUS # slash
80+0030 30 # DIGIT ZERO # zero
81+0031 31 # DIGIT ONE # one
82+0032 32 # DIGIT TWO # two
83+0033 33 # DIGIT THREE # three
84+0034 34 # DIGIT FOUR # four
85+0035 35 # DIGIT FIVE # five
86+0036 36 # DIGIT SIX # six
87+0037 37 # DIGIT SEVEN # seven
88+0038 38 # DIGIT EIGHT # eight
89+0039 39 # DIGIT NINE # nine
90+003A 3A # COLON # colon
91+003B 3B # SEMICOLON # semicolon
92+003C 3C # LESS-THAN SIGN # less
93+003D 3D # EQUALS SIGN # equal
94+003E 3E # GREATER-THAN SIGN # greater
95+003F 3F # QUESTION MARK # question
96+2245 40 # APPROXIMATELY EQUAL TO # congruent
97+0391 41 # GREEK CAPITAL LETTER ALPHA # Alpha
98+0392 42 # GREEK CAPITAL LETTER BETA # Beta
99+03A7 43 # GREEK CAPITAL LETTER CHI # Chi
100+0394 44 # GREEK CAPITAL LETTER DELTA # Delta
101+2206 44 # INCREMENT # Delta
102+0395 45 # GREEK CAPITAL LETTER EPSILON # Epsilon
103+03A6 46 # GREEK CAPITAL LETTER PHI # Phi
104+0393 47 # GREEK CAPITAL LETTER GAMMA # Gamma
105+0397 48 # GREEK CAPITAL LETTER ETA # Eta
106+0399 49 # GREEK CAPITAL LETTER IOTA # Iota
107+03D1 4A # GREEK THETA SYMBOL # theta1
108+039A 4B # GREEK CAPITAL LETTER KAPPA # Kappa
109+039B 4C # GREEK CAPITAL LETTER LAMDA # Lambda
110+039C 4D # GREEK CAPITAL LETTER MU # Mu
111+039D 4E # GREEK CAPITAL LETTER NU # Nu
112+039F 4F # GREEK CAPITAL LETTER OMICRON # Omicron
113+03A0 50 # GREEK CAPITAL LETTER PI # Pi
114+0398 51 # GREEK CAPITAL LETTER THETA # Theta
115+03A1 52 # GREEK CAPITAL LETTER RHO # Rho
116+03A3 53 # GREEK CAPITAL LETTER SIGMA # Sigma
117+03A4 54 # GREEK CAPITAL LETTER TAU # Tau
118+03A5 55 # GREEK CAPITAL LETTER UPSILON # Upsilon
119+03C2 56 # GREEK SMALL LETTER FINAL SIGMA # sigma1
120+03A9 57 # GREEK CAPITAL LETTER OMEGA # Omega
121+2126 57 # OHM SIGN # Omega
122+039E 58 # GREEK CAPITAL LETTER XI # Xi
123+03A8 59 # GREEK CAPITAL LETTER PSI # Psi
124+0396 5A # GREEK CAPITAL LETTER ZETA # Zeta
125+005B 5B # LEFT SQUARE BRACKET # bracketleft
126+2234 5C # THEREFORE # therefore
127+005D 5D # RIGHT SQUARE BRACKET # bracketright
128+22A5 5E # UP TACK # perpendicular
129+005F 5F # LOW LINE # underscore
130+F8E5 60 # RADICAL EXTENDER # radicalex (CUS)
131+03B1 61 # GREEK SMALL LETTER ALPHA # alpha
132+03B2 62 # GREEK SMALL LETTER BETA # beta
133+03C7 63 # GREEK SMALL LETTER CHI # chi
134+03B4 64 # GREEK SMALL LETTER DELTA # delta
135+03B5 65 # GREEK SMALL LETTER EPSILON # epsilon
136+03C6 66 # GREEK SMALL LETTER PHI # phi
137+03B3 67 # GREEK SMALL LETTER GAMMA # gamma
138+03B7 68 # GREEK SMALL LETTER ETA # eta
139+03B9 69 # GREEK SMALL LETTER IOTA # iota
140+03D5 6A # GREEK PHI SYMBOL # phi1
141+03BA 6B # GREEK SMALL LETTER KAPPA # kappa
142+03BB 6C # GREEK SMALL LETTER LAMDA # lambda
143+00B5 6D # MICRO SIGN # mu
144+03BC 6D # GREEK SMALL LETTER MU # mu
145+03BD 6E # GREEK SMALL LETTER NU # nu
146+03BF 6F # GREEK SMALL LETTER OMICRON # omicron
147+03C0 70 # GREEK SMALL LETTER PI # pi
148+03B8 71 # GREEK SMALL LETTER THETA # theta
149+03C1 72 # GREEK SMALL LETTER RHO # rho
150+03C3 73 # GREEK SMALL LETTER SIGMA # sigma
151+03C4 74 # GREEK SMALL LETTER TAU # tau
152+03C5 75 # GREEK SMALL LETTER UPSILON # upsilon
153+03D6 76 # GREEK PI SYMBOL # omega1
154+03C9 77 # GREEK SMALL LETTER OMEGA # omega
155+03BE 78 # GREEK SMALL LETTER XI # xi
156+03C8 79 # GREEK SMALL LETTER PSI # psi
157+03B6 7A # GREEK SMALL LETTER ZETA # zeta
158+007B 7B # LEFT CURLY BRACKET # braceleft
159+007C 7C # VERTICAL LINE # bar
160+007D 7D # RIGHT CURLY BRACKET # braceright
161+223C 7E # TILDE OPERATOR # similar
162+20AC A0 # EURO SIGN # Euro
163+03D2 A1 # GREEK UPSILON WITH HOOK SYMBOL # Upsilon1
164+2032 A2 # PRIME # minute
165+2264 A3 # LESS-THAN OR EQUAL TO # lessequal
166+2044 A4 # FRACTION SLASH # fraction
167+2215 A4 # DIVISION SLASH # fraction
168+221E A5 # INFINITY # infinity
169+0192 A6 # LATIN SMALL LETTER F WITH HOOK # florin
170+2663 A7 # BLACK CLUB SUIT # club
171+2666 A8 # BLACK DIAMOND SUIT # diamond
172+2665 A9 # BLACK HEART SUIT # heart
173+2660 AA # BLACK SPADE SUIT # spade
174+2194 AB # LEFT RIGHT ARROW # arrowboth
175+2190 AC # LEFTWARDS ARROW # arrowleft
176+2191 AD # UPWARDS ARROW # arrowup
177+2192 AE # RIGHTWARDS ARROW # arrowright
178+2193 AF # DOWNWARDS ARROW # arrowdown
179+00B0 B0 # DEGREE SIGN # degree
180+00B1 B1 # PLUS-MINUS SIGN # plusminus
181+2033 B2 # DOUBLE PRIME # second
182+2265 B3 # GREATER-THAN OR EQUAL TO # greaterequal
183+00D7 B4 # MULTIPLICATION SIGN # multiply
184+221D B5 # PROPORTIONAL TO # proportional
185+2202 B6 # PARTIAL DIFFERENTIAL # partialdiff
186+2022 B7 # BULLET # bullet
187+00F7 B8 # DIVISION SIGN # divide
188+2260 B9 # NOT EQUAL TO # notequal
189+2261 BA # IDENTICAL TO # equivalence
190+2248 BB # ALMOST EQUAL TO # approxequal
191+2026 BC # HORIZONTAL ELLIPSIS # ellipsis
192+F8E6 BD # VERTICAL ARROW EXTENDER # arrowvertex (CUS)
193+F8E7 BE # HORIZONTAL ARROW EXTENDER # arrowhorizex (CUS)
194+21B5 BF # DOWNWARDS ARROW WITH CORNER LEFTWARDS # carriagereturn
195+2135 C0 # ALEF SYMBOL # aleph
196+2111 C1 # BLACK-LETTER CAPITAL I # Ifraktur
197+211C C2 # BLACK-LETTER CAPITAL R # Rfraktur
198+2118 C3 # SCRIPT CAPITAL P # weierstrass
199+2297 C4 # CIRCLED TIMES # circlemultiply
200+2295 C5 # CIRCLED PLUS # circleplus
201+2205 C6 # EMPTY SET # emptyset
202+2229 C7 # INTERSECTION # intersection
203+222A C8 # UNION # union
204+2283 C9 # SUPERSET OF # propersuperset
205+2287 CA # SUPERSET OF OR EQUAL TO # reflexsuperset
206+2284 CB # NOT A SUBSET OF # notsubset
207+2282 CC # SUBSET OF # propersubset
208+2286 CD # SUBSET OF OR EQUAL TO # reflexsubset
209+2208 CE # ELEMENT OF # element
210+2209 CF # NOT AN ELEMENT OF # notelement
211+2220 D0 # ANGLE # angle
212+2207 D1 # NABLA # gradient
213+F6DA D2 # REGISTERED SIGN SERIF # registerserif (CUS)
214+F6D9 D3 # COPYRIGHT SIGN SERIF # copyrightserif (CUS)
215+F6DB D4 # TRADE MARK SIGN SERIF # trademarkserif (CUS)
216+220F D5 # N-ARY PRODUCT # product
217+221A D6 # SQUARE ROOT # radical
218+22C5 D7 # DOT OPERATOR # dotmath
219+00AC D8 # NOT SIGN # logicalnot
220+2227 D9 # LOGICAL AND # logicaland
221+2228 DA # LOGICAL OR # logicalor
222+21D4 DB # LEFT RIGHT DOUBLE ARROW # arrowdblboth
223+21D0 DC # LEFTWARDS DOUBLE ARROW # arrowdblleft
224+21D1 DD # UPWARDS DOUBLE ARROW # arrowdblup
225+21D2 DE # RIGHTWARDS DOUBLE ARROW # arrowdblright
226+21D3 DF # DOWNWARDS DOUBLE ARROW # arrowdbldown
227+25CA E0 # LOZENGE # lozenge
228+2329 E1 # LEFT-POINTING ANGLE BRACKET # angleleft
229+F8E8 E2 # REGISTERED SIGN SANS SERIF # registersans (CUS)
230+F8E9 E3 # COPYRIGHT SIGN SANS SERIF # copyrightsans (CUS)
231+F8EA E4 # TRADE MARK SIGN SANS SERIF # trademarksans (CUS)
232+2211 E5 # N-ARY SUMMATION # summation
233+F8EB E6 # LEFT PAREN TOP # parenlefttp (CUS)
234+F8EC E7 # LEFT PAREN EXTENDER # parenleftex (CUS)
235+F8ED E8 # LEFT PAREN BOTTOM # parenleftbt (CUS)
236+F8EE E9 # LEFT SQUARE BRACKET TOP # bracketlefttp (CUS)
237+F8EF EA # LEFT SQUARE BRACKET EXTENDER # bracketleftex (CUS)
238+F8F0 EB # LEFT SQUARE BRACKET BOTTOM # bracketleftbt (CUS)
239+F8F1 EC # LEFT CURLY BRACKET TOP # bracelefttp (CUS)
240+F8F2 ED # LEFT CURLY BRACKET MID # braceleftmid (CUS)
241+F8F3 EE # LEFT CURLY BRACKET BOTTOM # braceleftbt (CUS)
242+F8F4 EF # CURLY BRACKET EXTENDER # braceex (CUS)
243+232A F1 # RIGHT-POINTING ANGLE BRACKET # angleright
244+222B F2 # INTEGRAL # integral
245+2320 F3 # TOP HALF INTEGRAL # integraltp
246+F8F5 F4 # INTEGRAL EXTENDER # integralex (CUS)
247+2321 F5 # BOTTOM HALF INTEGRAL # integralbt
248+F8F6 F6 # RIGHT PAREN TOP # parenrighttp (CUS)
249+F8F7 F7 # RIGHT PAREN EXTENDER # parenrightex (CUS)
250+F8F8 F8 # RIGHT PAREN BOTTOM # parenrightbt (CUS)
251+F8F9 F9 # RIGHT SQUARE BRACKET TOP # bracketrighttp (CUS)
252+F8FA FA # RIGHT SQUARE BRACKET EXTENDER # bracketrightex (CUS)
253+F8FB FB # RIGHT SQUARE BRACKET BOTTOM # bracketrightbt (CUS)
254+F8FC FC # RIGHT CURLY BRACKET TOP # bracerighttp (CUS)
255+F8FD FD # RIGHT CURLY BRACKET MID # bracerightmid (CUS)
256+F8FE FE # RIGHT CURLY BRACKET BOTTOM # bracerightbt (CUS)
pandoc.cabal+1
@@ -327,6 +327,7 @@ Library
327327 Text.Pandoc.Readers.Docx.Reducible,
328328 Text.Pandoc.Readers.Docx.Parse,
329329 Text.Pandoc.Readers.Docx.OMath,
330+ Text.Pandoc.Readers.Docx.Fonts
330331 Text.Pandoc.Writers.Shared,
331332 Text.Pandoc.Asciify,
332333 Text.Pandoc.MIME,
src/Text/Pandoc/Readers/Docx/Fonts.hsnew file+237
@@ -0,0 +1,237 @@
1+{-
2+Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>
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.Readers.Docx.Fonts
21+ Copyright : Copyright (C) 2014 Matthew Pickering
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : Matthew Pickering <matthewtpickering@gmail.com>
25+ Stability : alpha
26+ Portability : portable
27+
28+Utilities to convert between font codepoints and unicode characters.
29+-}
30+module Text.Pandoc.Readers.Docx.Fonts (getUnicode, Font(..)) where
31+
32+
33+-- | Enumeration of recognised fonts
34+data Font = Symbol -- ^ <http://en.wikipedia.org/wiki/Symbol_(typeface) Adobe Symbol>
35+
36+-- | Given a font and codepoint, returns the corresponding unicode
37+-- character
38+getUnicode :: Font -> Char -> Maybe Char
39+getUnicode Symbol c = lookup c symbol
40+
41+-- Generated from lib/fonts/symbol.txt
42+symbol :: [(Char, Char)]
43+symbol =
44+ [ (' ',' ')
45+ , (' ','\160')
46+ , ('!','!')
47+ , ('"','\8704')
48+ , ('#','#')
49+ , ('$','\8707')
50+ , ('%','%')
51+ , ('&','&')
52+ , ('\'','\8715')
53+ , ('(','(')
54+ , (')',')')
55+ , ('*','\8727')
56+ , ('+','+')
57+ , (',',',')
58+ , ('-','\8722')
59+ , ('.','.')
60+ , ('/','/')
61+ , ('0','0')
62+ , ('1','1')
63+ , ('2','2')
64+ , ('3','3')
65+ , ('4','4')
66+ , ('5','5')
67+ , ('6','6')
68+ , ('7','7')
69+ , ('8','8')
70+ , ('9','9')
71+ , (':',':')
72+ , (';',';')
73+ , ('<','<')
74+ , ('=','=')
75+ , ('>','>')
76+ , ('?','?')
77+ , ('@','\8773')
78+ , ('A','\913')
79+ , ('B','\914')
80+ , ('C','\935')
81+ , ('D','\916')
82+ , ('D','\8710')
83+ , ('E','\917')
84+ , ('F','\934')
85+ , ('G','\915')
86+ , ('H','\919')
87+ , ('I','\921')
88+ , ('J','\977')
89+ , ('K','\922')
90+ , ('L','\923')
91+ , ('M','\924')
92+ , ('N','\925')
93+ , ('O','\927')
94+ , ('P','\928')
95+ , ('Q','\920')
96+ , ('R','\929')
97+ , ('S','\931')
98+ , ('T','\932')
99+ , ('U','\933')
100+ , ('V','\962')
101+ , ('W','\937')
102+ , ('W','\8486')
103+ , ('X','\926')
104+ , ('Y','\936')
105+ , ('Z','\918')
106+ , ('[','[')
107+ , ('\\','\8756')
108+ , (']',']')
109+ , ('^','\8869')
110+ , ('_','_')
111+ , ('`','\63717')
112+ , ('a','\945')
113+ , ('b','\946')
114+ , ('c','\967')
115+ , ('d','\948')
116+ , ('e','\949')
117+ , ('f','\966')
118+ , ('g','\947')
119+ , ('h','\951')
120+ , ('i','\953')
121+ , ('j','\981')
122+ , ('k','\954')
123+ , ('l','\955')
124+ , ('m','\181')
125+ , ('m','\956')
126+ , ('n','\957')
127+ , ('o','\959')
128+ , ('p','\960')
129+ , ('q','\952')
130+ , ('r','\961')
131+ , ('s','\963')
132+ , ('t','\964')
133+ , ('u','\965')
134+ , ('v','\982')
135+ , ('w','\969')
136+ , ('x','\958')
137+ , ('y','\968')
138+ , ('z','\950')
139+ , ('{','{')
140+ , ('|','|')
141+ , ('}','}')
142+ , ('~','\8764')
143+ , ('\160','\8364')
144+ , ('\161','\978')
145+ , ('\162','\8242')
146+ , ('\163','\8804')
147+ , ('\164','\8260')
148+ , ('\164','\8725')
149+ , ('\165','\8734')
150+ , ('\166','\402')
151+ , ('\167','\9827')
152+ , ('\168','\9830')
153+ , ('\169','\9829')
154+ , ('\170','\9824')
155+ , ('\171','\8596')
156+ , ('\172','\8592')
157+ , ('\173','\8593')
158+ , ('\174','\8594')
159+ , ('\175','\8595')
160+ , ('\176','\176')
161+ , ('\177','\177')
162+ , ('\178','\8243')
163+ , ('\179','\8805')
164+ , ('\180','\215')
165+ , ('\181','\8733')
166+ , ('\182','\8706')
167+ , ('\183','\8226')
168+ , ('\184','\247')
169+ , ('\185','\8800')
170+ , ('\186','\8801')
171+ , ('\187','\8776')
172+ , ('\188','\8230')
173+ , ('\189','\63718')
174+ , ('\190','\63719')
175+ , ('\191','\8629')
176+ , ('\192','\8501')
177+ , ('\193','\8465')
178+ , ('\194','\8476')
179+ , ('\195','\8472')
180+ , ('\196','\8855')
181+ , ('\197','\8853')
182+ , ('\198','\8709')
183+ , ('\199','\8745')
184+ , ('\200','\8746')
185+ , ('\201','\8835')
186+ , ('\202','\8839')
187+ , ('\203','\8836')
188+ , ('\204','\8834')
189+ , ('\205','\8838')
190+ , ('\206','\8712')
191+ , ('\207','\8713')
192+ , ('\208','\8736')
193+ , ('\209','\8711')
194+ , ('\210','\63194')
195+ , ('\211','\63193')
196+ , ('\212','\63195')
197+ , ('\213','\8719')
198+ , ('\214','\8730')
199+ , ('\215','\8901')
200+ , ('\216','\172')
201+ , ('\217','\8743')
202+ , ('\218','\8744')
203+ , ('\219','\8660')
204+ , ('\220','\8656')
205+ , ('\221','\8657')
206+ , ('\222','\8658')
207+ , ('\223','\8659')
208+ , ('\224','\9674')
209+ , ('\225','\9001')
210+ , ('\226','\63720')
211+ , ('\227','\63721')
212+ , ('\228','\63722')
213+ , ('\229','\8721')
214+ , ('\230','\63723')
215+ , ('\231','\63724')
216+ , ('\232','\63725')
217+ , ('\233','\63726')
218+ , ('\234','\63727')
219+ , ('\235','\63728')
220+ , ('\236','\63729')
221+ , ('\237','\63730')
222+ , ('\238','\63731')
223+ , ('\239','\63732')
224+ , ('\241','\9002')
225+ , ('\242','\8747')
226+ , ('\243','\8992')
227+ , ('\244','\63733')
228+ , ('\245','\8993')
229+ , ('\246','\63734')
230+ , ('\247','\63735')
231+ , ('\248','\63736')
232+ , ('\249','\63737')
233+ , ('\250','\63738')
234+ , ('\251','\63739')
235+ , ('\252','\63740')
236+ , ('\253','\63741')
237+ , ('\254','\63742')]
src/Text/Pandoc/Readers/Docx/Parse.hs+22
@@ -59,10 +59,13 @@ import Data.Bits ((.|.))
5959import qualified Data.ByteString.Lazy as B
6060import qualified Text.Pandoc.UTF8 as UTF8
6161import Control.Monad.Reader
62+import Control.Applicative ((<$>))
6263import qualified Data.Map as M
6364import Text.Pandoc.Compat.Except
6465import Text.Pandoc.Readers.Docx.OMath (readOMML)
66+import Text.Pandoc.Readers.Docx.Fonts (getUnicode, Font(..))
6567import Text.TeXMath (Exp)
68+import Data.Char (readLitChar)
6669
6770data ReaderEnv = ReaderEnv { envNotes :: Notes
6871 , envNumbering :: Numbering
@@ -673,8 +676,27 @@ elemToRunElem ns element
673676 return $ TextRun $ strContent element
674677 | isElem ns "w" "br" element = return LnBrk
675678 | isElem ns "w" "tab" element = return Tab
679+ | isElem ns "w" "sym" element = return (getSymChar ns element)
676680 | otherwise = throwError WrongElem
677681
682+-- The char attribute is a hex string
683+getSymChar :: NameSpaces -> Element -> RunElem
684+getSymChar ns element
685+ | Just s <- lowerFromPrivate <$> getCodepoint
686+ , Just font <- getFont =
687+ let [(char, _)] = readLitChar ("\\x" ++ s) in
688+ TextRun . maybe "" (:[]) $ getUnicode font char
689+ where
690+ getCodepoint = findAttr (elemName ns "w" "char") element
691+ getFont = stringToFont =<< findAttr (elemName ns "w" "font") element
692+ lowerFromPrivate ('F':xs) = '0':xs
693+ lowerFromPrivate xs = xs
694+getSymChar _ _ = TextRun ""
695+
696+stringToFont :: String -> Maybe Font
697+stringToFont "Symbol" = Just Symbol
698+stringToFont _ = Nothing
699+
678700elemToRunElems :: NameSpaces -> Element -> D [RunElem]
679701elemToRunElems ns element
680702 | isElem ns "w" "r" element
tests/docx.unicode.docx

Binary file not shown.

tests/docx.unicode.native+1−1
@@ -1 +1 @@
1−[Para [Str "Hello,",Space,Str "\19990\30028.",Space,Str "This",Space,Str "costs",Space,Str "\8364\&10."]]
1+[Para [Str "Hello,",Space,Str "\19990\30028.",Space,Str "This",Space,Str "costs",Space,Str "\8364\&10.\8744\8744"]]