git.iko.soy/typeable/pandoc
on master help sign in
Split off T.P.Readers.LaTeX.Accent.
925815bJohn MacFarlane
pandoc.cabal+1
@@ -630,6 +630,7 @@ library
630 Text.Pandoc.Readers.LaTeX.Parsing,
630 Text.Pandoc.Readers.LaTeX.Parsing,
631 Text.Pandoc.Readers.LaTeX.Lang,
631 Text.Pandoc.Readers.LaTeX.Lang,
632 Text.Pandoc.Readers.LaTeX.SIunitx,
632 Text.Pandoc.Readers.LaTeX.SIunitx,
633+ Text.Pandoc.Readers.LaTeX.Accent,
633 Text.Pandoc.Readers.Odt.Base,
634 Text.Pandoc.Readers.Odt.Base,
634 Text.Pandoc.Readers.Odt.Namespaces,
635 Text.Pandoc.Readers.Odt.Namespaces,
635 Text.Pandoc.Readers.Odt.StyleReader,
636 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,
57import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
57import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
58 ArgSpec (..), Tok (..), TokType (..))
58 ArgSpec (..), Tok (..), TokType (..))
59import Text.Pandoc.Readers.LaTeX.Parsing
59import Text.Pandoc.Readers.LaTeX.Parsing
60+import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
60import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
61import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
61 babelLangToBCP47)
62 babelLangToBCP47)
62import Text.Pandoc.Readers.LaTeX.SIunitx
63import Text.Pandoc.Readers.LaTeX.SIunitx
@@ -64,7 +65,6 @@ import Text.Pandoc.Shared
64import qualified Text.Pandoc.Translations as Translations
65import qualified Text.Pandoc.Translations as Translations
65import Text.Pandoc.Walk
66import Text.Pandoc.Walk
66import qualified Text.Pandoc.Builder as B
67import qualified Text.Pandoc.Builder as B
67−import qualified Data.Text.Normalize as Normalize
68import Safe
68import Safe
69
69
70-- for debugging:
70-- for debugging:
@@ -247,9 +247,6 @@ doxspace =
247 startsWithLetter _ = False
247 startsWithLetter _ = False
248
248
249
249
250−lit :: Text -> LP m Inlines
251−lit = pure . str
252−
253removeDoubleQuotes :: Text -> Text
250removeDoubleQuotes :: Text -> Text
254removeDoubleQuotes t =
251removeDoubleQuotes t =
255 Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
252 Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
@@ -296,6 +293,9 @@ quoted' f starter ender = do
296 cs -> cs)
293 cs -> cs)
297 else lit startchs
294 else lit startchs
298
295
296+lit :: Text -> LP m Inlines
297+lit = pure . str
298+
299enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
299enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
300enquote starred mblang = do
300enquote starred mblang = do
301 skipopts
301 skipopts
@@ -631,7 +631,10 @@ inlineEnvironments = M.fromList [
631 ]
631 ]
632
632
633inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
633inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
634+inlineCommands =
634−inlineCommands = M.union inlineLanguageCommands $ M.fromList
635+ M.union inlineLanguageCommands $
636+ M.union (accentCommands tok) $
637+ M.fromList
635 [ ("emph", extractSpaces emph <$> tok)
638 [ ("emph", extractSpaces emph <$> tok)
636 , ("textit", extractSpaces emph <$> tok)
639 , ("textit", extractSpaces emph <$> tok)
637 , ("textsl", extractSpaces emph <$> tok)
640 , ("textsl", extractSpaces emph <$> tok)
@@ -703,48 +706,6 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
703 , ("MakeTextLowercase", makeLowercase <$> tok)
706 , ("MakeTextLowercase", makeLowercase <$> tok)
704 , ("lowercase", makeLowercase <$> tok)
707 , ("lowercase", makeLowercase <$> tok)
705 , ("/", pure mempty) -- italic correction
708 , ("/", 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
748 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
709 , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
749 guard $ not inTableCell
710 guard $ not inTableCell
750 optional opt
711 optional opt
@@ -960,19 +921,6 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
960 , ("hyphen", pure (str "-"))
921 , ("hyphen", pure (str "-"))
961 ]
922 ]
962
923
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−
976lettrine :: PandocMonad m => LP m Inlines
924lettrine :: PandocMonad m => LP m Inlines
977lettrine = do
925lettrine = do
978 optional opt
926 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+