git.iko.soy/typeable/pandoc
on master help sign in
Split off T.P.Readers.LaTeX.Accent.

To help reduce memory demands compiling the main LaTeX reader.

commit925815bb33b462e1a4c19a8e2c617d403dec0ce7 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 27 Feb 2021, 17:02 (6 years ago) parent63123db
3 files changed+87−60
pandoc.cabal+1 src/Text/Pandoc/Readers/LaTeX.hs+8−60 src/Text/Pandoc/Readers/LaTeX/Accent.hs+78
pandoc.cabal+1
@@ -630,6 +630,7 @@ library
630630 Text.Pandoc.Readers.LaTeX.Parsing,
631631 Text.Pandoc.Readers.LaTeX.Lang,
632632 Text.Pandoc.Readers.LaTeX.SIunitx,
633+ Text.Pandoc.Readers.LaTeX.Accent,
633634 Text.Pandoc.Readers.Odt.Base,
634635 Text.Pandoc.Readers.Odt.Namespaces,
635636 Text.Pandoc.Readers.Odt.StyleReader,
src/Text/Pandoc/Readers/LaTeX.hs+8−60
@@ -57,6 +57,7 @@ import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
5757import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
5858 ArgSpec (..), Tok (..), TokType (..))
5959import Text.Pandoc.Readers.LaTeX.Parsing
60+import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
6061import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
6162 babelLangToBCP47)
6263import Text.Pandoc.Readers.LaTeX.SIunitx
@@ -64,7 +65,6 @@ import Text.Pandoc.Shared
6465import qualified Text.Pandoc.Translations as Translations
6566import Text.Pandoc.Walk
6667import qualified Text.Pandoc.Builder as B
67−import qualified Data.Text.Normalize as Normalize
6868import Safe
6969
7070-- for debugging:
@@ -247,9 +247,6 @@ doxspace =
247247 startsWithLetter _ = False
248248
249249
250−lit :: Text -> LP m Inlines
251−lit = pure . str
252−
253250removeDoubleQuotes :: Text -> Text
254251removeDoubleQuotes t =
255252 Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
@@ -296,6 +293,9 @@ quoted' f starter ender = do
296293 cs -> cs)
297294 else lit startchs
298295
296+lit :: Text -> LP m Inlines
297+lit = pure . str
298+
299299enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
300300enquote starred mblang = do
301301 skipopts
@@ -631,7 +631,10 @@ inlineEnvironments = M.fromList [
631631 ]
632632
633633inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
634−inlineCommands = M.union inlineLanguageCommands $ M.fromList
634+inlineCommands =
635+ M.union inlineLanguageCommands $
636+ M.union (accentCommands tok) $
637+ M.fromList
635638 [ ("emph", extractSpaces emph <$> tok)
636639 , ("textit", extractSpaces emph <$> tok)
637640 , ("textsl", extractSpaces emph <$> tok)
@@ -703,48 +706,6 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
703706 , ("MakeTextLowercase", makeLowercase <$> tok)
704707 , ("lowercase", makeLowercase <$> tok)
705708 , ("/", pure mempty) -- italic correction
706− , ("aa", lit "å")
707− , ("AA", lit "Å")
708− , ("ss", lit "ß")
709− , ("o", lit "ø")
710− , ("O", lit "Ø")
711− , ("L", lit "Ł")
712− , ("l", lit "ł")
713− , ("ae", lit "æ")
714− , ("AE", lit "Æ")
715− , ("oe", lit "œ")
716− , ("OE", lit "Œ")
717− , ("pounds", lit "£")
718− , ("euro", lit "€")
719− , ("copyright", lit "©")
720− , ("textasciicircum", lit "^")
721− , ("textasciitilde", lit "~")
722− , ("H", accent '\779' Nothing) -- hungarumlaut
723− , ("`", accent '\768' (Just '`')) -- grave
724− , ("'", accent '\769' (Just '\'')) -- acute
725− , ("^", accent '\770' (Just '^')) -- circ
726− , ("~", accent '\771' (Just '~')) -- tilde
727− , ("\"", accent '\776' Nothing) -- umlaut
728− , (".", accent '\775' Nothing) -- dot
729− , ("=", accent '\772' Nothing) -- macron
730− , ("|", accent '\781' Nothing) -- vertical line above
731− , ("b", accent '\817' Nothing) -- macron below
732− , ("c", accent '\807' Nothing) -- cedilla
733− , ("G", accent '\783' Nothing) -- doublegrave
734− , ("h", accent '\777' Nothing) -- hookabove
735− , ("d", accent '\803' Nothing) -- dotbelow
736− , ("f", accent '\785' Nothing) -- inverted breve
737− , ("r", accent '\778' Nothing) -- ringabove
738− , ("t", accent '\865' Nothing) -- double inverted breve
739− , ("U", accent '\782' Nothing) -- double vertical line above
740− , ("v", accent '\780' Nothing) -- hacek
741− , ("u", accent '\774' Nothing) -- breve
742− , ("k", accent '\808' Nothing) -- ogonek
743− , ("textogonekcentered", accent '\808' Nothing) -- ogonek
744− , ("i", lit "ı") -- dotless i
745− , ("j", lit "ȷ") -- dotless j
746− , ("newtie", accent '\785' Nothing) -- inverted breve
747− , ("textcircled", accent '\8413' Nothing) -- combining circle
748709 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
749710 guard $ not inTableCell
750711 optional opt
@@ -960,19 +921,6 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
960921 , ("hyphen", pure (str "-"))
961922 ]
962923
963−accent :: PandocMonad m => Char -> Maybe Char -> LP m Inlines
964−accent combiningAccent fallBack = try $ do
965− ils <- tok
966− case toList ils of
967− (Str (T.uncons -> Just (x, xs)) : ys) -> return $ fromList $
968− -- try to normalize to the combined character:
969− Str (Normalize.normalize Normalize.NFC
970− (T.pack [x, combiningAccent]) <> xs) : ys
971− [Space] -> return $ str $ T.singleton $ fromMaybe combiningAccent fallBack
972− [] -> return $ str $ T.singleton $ fromMaybe combiningAccent fallBack
973− _ -> return ils
974−
975−
976924lettrine :: PandocMonad m => LP m Inlines
977925lettrine = do
978926 optional opt
src/Text/Pandoc/Readers/LaTeX/Accent.hsnew file+78
@@ -0,0 +1,78 @@
1+{-# LANGUAGE ViewPatterns #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+module Text.Pandoc.Readers.LaTeX.Accent
4+ ( accentCommands )
5+where
6+
7+import Text.Pandoc.Class
8+import Text.Pandoc.Readers.LaTeX.Parsing
9+import Text.Pandoc.Builder as B
10+import qualified Data.Map as M
11+import Data.Text (Text)
12+import Data.Maybe (fromMaybe)
13+import Text.Pandoc.Parsing
14+import qualified Data.Text as T
15+import qualified Data.Text.Normalize as Normalize
16+
17+accentCommands :: PandocMonad m => LP m Inlines -> M.Map Text (LP m Inlines)
18+accentCommands tok =
19+ let accent = accentWith tok
20+ lit = pure . str
21+ in M.fromList
22+ [ ("aa", lit "å")
23+ , ("AA", lit "Å")
24+ , ("ss", lit "ß")
25+ , ("o", lit "ø")
26+ , ("O", lit "Ø")
27+ , ("L", lit "Ł")
28+ , ("l", lit "ł")
29+ , ("ae", lit "æ")
30+ , ("AE", lit "Æ")
31+ , ("oe", lit "œ")
32+ , ("OE", lit "Œ")
33+ , ("pounds", lit "£")
34+ , ("euro", lit "€")
35+ , ("copyright", lit "©")
36+ , ("textasciicircum", lit "^")
37+ , ("textasciitilde", lit "~")
38+ , ("H", accent '\779' Nothing) -- hungarumlaut
39+ , ("`", accent '\768' (Just '`')) -- grave
40+ , ("'", accent '\769' (Just '\'')) -- acute
41+ , ("^", accent '\770' (Just '^')) -- circ
42+ , ("~", accent '\771' (Just '~')) -- tilde
43+ , ("\"", accent '\776' Nothing) -- umlaut
44+ , (".", accent '\775' Nothing) -- dot
45+ , ("=", accent '\772' Nothing) -- macron
46+ , ("|", accent '\781' Nothing) -- vertical line above
47+ , ("b", accent '\817' Nothing) -- macron below
48+ , ("c", accent '\807' Nothing) -- cedilla
49+ , ("G", accent '\783' Nothing) -- doublegrave
50+ , ("h", accent '\777' Nothing) -- hookabove
51+ , ("d", accent '\803' Nothing) -- dotbelow
52+ , ("f", accent '\785' Nothing) -- inverted breve
53+ , ("r", accent '\778' Nothing) -- ringabove
54+ , ("t", accent '\865' Nothing) -- double inverted breve
55+ , ("U", accent '\782' Nothing) -- double vertical line above
56+ , ("v", accent '\780' Nothing) -- hacek
57+ , ("u", accent '\774' Nothing) -- breve
58+ , ("k", accent '\808' Nothing) -- ogonek
59+ , ("textogonekcentered", accent '\808' Nothing) -- ogonek
60+ , ("i", lit "ı") -- dotless i
61+ , ("j", lit "ȷ") -- dotless j
62+ , ("newtie", accent '\785' Nothing) -- inverted breve
63+ , ("textcircled", accent '\8413' Nothing) -- combining circle
64+ ]
65+
66+accentWith :: PandocMonad m
67+ => LP m Inlines -> Char -> Maybe Char -> LP m Inlines
68+accentWith tok combiningAccent fallBack = try $ do
69+ ils <- tok
70+ case toList ils of
71+ (Str (T.uncons -> Just (x, xs)) : ys) -> return $ fromList $
72+ -- try to normalize to the combined character:
73+ Str (Normalize.normalize Normalize.NFC
74+ (T.pack [x, combiningAccent]) <> xs) : ys
75+ [Space] -> return $ str $ T.singleton $ fromMaybe combiningAccent fallBack
76+ [] -> return $ str $ T.singleton $ fromMaybe combiningAccent fallBack
77+ _ -> return ils
78+