{-
Copyright (C) 2006-7 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}{- |
Module : Text.Pandoc.CharacterReferences
Copyright : Copyright (C) 2006-7 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
Portability : portable
Functions for parsing character references.
-}moduleText.Pandoc.CharacterReferences(characterReference,decodeCharacterReferences,)whereimportData.Char(chr)importText.ParserCombinators.ParsecimportqualifiedData.MapasMap-- | Parse character entity.characterReference::GenParserCharstCharcharacterReference=try$dochar'&'character<-numRef<|>entitychar';'returncharacternumRef::GenParserCharstCharnumRef=dochar'#'num<-hexNum<|>decNumreturn$chr$numhexNum::GenParserCharstInthexNum=oneOf"Xx">>many1hexDigit>>=return.read.(\xs->'0':'x':xs)decNum::GenParserCharstIntdecNum=many1digit>>=return.readentity::GenParserCharstCharentity=dobody<-many1alphaNumreturn$Map.findWithDefault'?'bodyentityTable-- | Convert entities in a string to characters.decodeCharacterReferences::String->StringdecodeCharacterReferencesstr=caseparse(many(characterReference<|>anyChar))strstrofLefterr->error$"\nError: "++showerrRightresult->resultentityTable::Map.MapStringCharentityTable=Map.fromListentityTableListentityTableList::[(String,Char)]entityTableList=[("quot",chr34),("amp",chr38),("lt",chr60),("gt",chr62),("nbsp",chr160),("iexcl",chr161),("cent",chr162),("pound",chr163),("curren",chr164),("yen",chr165),("brvbar",chr166),("sect",chr167),("uml",chr168),("copy",chr169),("ordf",chr170),("laquo",chr171),("not",chr172),("shy",chr173),("reg",chr174),("macr",chr175),("deg",chr176),("plusmn",chr177),("sup2",chr178),("sup3",chr179),("acute",chr180),("micro",chr181),("para",chr182),("middot",chr183),("cedil",chr184),("sup1",chr185),("ordm",chr186),("raquo",chr187),("frac14",chr188),("frac12",chr189),("frac34",chr190),("iquest",chr191),("Agrave",chr192),("Aacute",chr193),("Acirc",chr194),("Atilde",chr195),("Auml",chr196),("Aring",chr197),("AElig",chr198),("Ccedil",chr199),("Egrave",chr200),("Eacute",chr201),("Ecirc",chr202),("Euml",chr203),("Igrave",chr204),("Iacute",chr205),("Icirc",chr206),("Iuml",chr207),("ETH",chr208),("Ntilde",chr209),("Ograve",chr210),("Oacute",chr211),("Ocirc",chr212),("Otilde",chr213),("Ouml",chr214),("times",chr215),("Oslash",chr216),("Ugrave",chr217),("Uacute",chr218),("Ucirc",chr219),("Uuml",chr220),("Yacute",chr221),("THORN",chr222),("szlig",chr223),("agrave",chr224),("aacute",chr225),("acirc",chr226),("atilde",chr227),("auml",chr228),("aring",chr229),("aelig",chr230),("ccedil",chr231),("egrave",chr232),("eacute",chr233),("ecirc",chr234),("euml",chr235),("igrave",chr236),("iacute",chr237),("icirc",chr238),("iuml",chr239),("eth",chr240),("ntilde",chr241),("ograve",chr242),("oacute",chr243),("ocirc",chr244),("otilde",chr245),("ouml",chr246),("divide",chr247),("oslash",chr248),("ugrave",chr249),("uacute",chr250),("ucirc",chr251),("uuml",chr252),("yacute",chr253),("thorn",chr254),("yuml",chr255),("OElig",chr338),("oelig",chr339),("Scaron",chr352),("scaron",chr353),("Yuml",chr376),("fnof",chr402),("circ",chr710),("tilde",chr732),("Alpha",chr913),("Beta",chr914),("Gamma",chr915),("Delta",chr916),("Epsilon",chr917),("Zeta",chr918),("Eta",chr919),("Theta",chr920),("Iota",chr921),("Kappa",chr922),("Lambda",chr923),("Mu",chr924),("Nu",chr925),("Xi",chr926),("Omicron",chr927),("Pi",chr928),("Rho",chr929),("Sigma",chr931),("Tau",chr932),("Upsilon",chr933),("Phi",chr934),("Chi",chr935),("Psi",chr936),("Omega",chr937),("alpha",chr945),("beta",chr946),("gamma",chr947),("delta",chr948),("epsilon",chr949),("zeta",chr950),("eta",chr951),("theta",chr952),("iota",chr953),("kappa",chr954),("lambda",chr955),("mu",chr956),("nu",chr957),("xi",chr958),("omicron",chr959),("pi",chr960),("rho",chr961),("sigmaf",chr962),("sigma",chr963),("tau",chr964),("upsilon",chr965),("phi",chr966),("chi",chr967),("psi",chr968),("omega",chr969),("thetasym",chr977),("upsih",chr978),("piv",chr982),("ensp",chr8194),("emsp",chr8195),("thinsp",chr8201),("zwnj",chr8204),("zwj",chr8205),("lrm",chr8206),("rlm",chr8207),("ndash",chr8211),("mdash",chr8212),("lsquo",chr8216),("rsquo",chr8217),("sbquo",chr8218),("ldquo",chr8220),("rdquo",chr8221),("bdquo",chr8222),("dagger",chr8224),("Dagger",chr8225),("bull",chr8226),("hellip",chr8230),("permil",chr8240),("prime",chr8242),("Prime",chr8243),("lsaquo",chr8249),("rsaquo",chr8250),("oline",chr8254),("frasl",chr8260),("euro",chr8364),("image",chr8465),("weierp",chr8472),("real",chr8476),("trade",chr8482),("alefsym",chr8501),("larr",chr8592),("uarr",chr8593),("rarr",chr8594),("darr",chr8595),("harr",chr8596),("crarr",chr8629),("lArr",chr8656),("uArr",chr8657),("rArr",chr8658),("dArr",chr8659),("hArr",chr8660),("forall",chr8704),("part",chr8706),("exist",chr8707),("empty",chr8709),("nabla",chr8711),("isin",chr8712),("notin",chr8713),("ni",chr8715),("prod",chr8719),("sum",chr8721),("minus",chr8722),("lowast",chr8727),("radic",chr8730),("prop",chr8733),("infin",chr8734),("ang",chr8736),("and",chr8743),("or",chr8744),("cap",chr8745),("cup",chr8746),("int",chr8747),("there4",chr8756),("sim",chr8764),("cong",chr8773),("asymp",chr8776),("ne",chr8800),("equiv",chr8801),("le",chr8804),("ge",chr8805),("sub",chr8834),("sup",chr8835),("nsub",chr8836),("sube",chr8838),("supe",chr8839),("oplus",chr8853),("otimes",chr8855),("perp",chr8869),("sdot",chr8901),("lceil",chr8968),("rceil",chr8969),("lfloor",chr8970),("rfloor",chr8971),("lang",chr9001),("rang",chr9002),("loz",chr9674),("spades",chr9824),("clubs",chr9827),("hearts",chr9829),("diams",chr9830)]