git.iko.soy/typeable/pandoc
on master help sign in
Added --abbreviations=FILE option for custom abbreviations file.
2fe806eJohn MacFarlane
src/Text/Pandoc/App.hs+23−8
@@ -46,6 +46,7 @@ import Data.Aeson (eitherDecode', encode)
46import qualified Data.ByteString as BS
46import qualified Data.ByteString as BS
47import qualified Data.ByteString.Lazy as B
47import qualified Data.ByteString.Lazy as B
48import Data.Char (toLower, toUpper)
48import Data.Char (toLower, toUpper)
49+import qualified Data.Set as Set
49import Data.Foldable (foldrM)
50import Data.Foldable (foldrM)
50import Data.List (intercalate, isPrefixOf, isSuffixOf, sort)
51import Data.List (intercalate, isPrefixOf, isSuffixOf, sort)
51import qualified Data.Map as M
52import qualified Data.Map as M
@@ -279,6 +280,11 @@ convertWithOpts opts = do
279 uriFragment = "" }
280 uriFragment = "" }
280 _ -> Nothing
281 _ -> Nothing
281
282
283+ abbrevs <- case optAbbreviations opts of
284+ Nothing -> return $ readerAbbreviations def
285+ Just f -> (Set.fromList . filter (not . null) . lines)
286+ <$> UTF8.readFile f
287+
282 let readerOpts = def{ readerStandalone = standalone
288 let readerOpts = def{ readerStandalone = standalone
283 , readerColumns = optColumns opts
289 , readerColumns = optColumns opts
284 , readerTabStop = optTabStop opts
290 , readerTabStop = optTabStop opts
@@ -287,6 +293,7 @@ convertWithOpts opts = do
287 , readerDefaultImageExtension =
293 , readerDefaultImageExtension =
288 optDefaultImageExtension opts
294 optDefaultImageExtension opts
289 , readerTrackChanges = optTrackChanges opts
295 , readerTrackChanges = optTrackChanges opts
296+ , readerAbbreviations = abbrevs
290 }
297 }
291
298
292 highlightStyle <- lookupHighlightStyle $ optHighlightStyle opts
299 highlightStyle <- lookupHighlightStyle $ optHighlightStyle opts
@@ -489,6 +496,7 @@ data Opt = Opt
489 , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
496 , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
490 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
497 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
491 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
498 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
499+ , optAbbreviations :: Maybe FilePath -- ^ Path to abbrevs file
492 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
500 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
493 , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
501 , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
494 , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
502 , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
@@ -554,6 +562,7 @@ defaultOpts = Opt
554 , optHighlightStyle = Just "pygments"
562 , optHighlightStyle = Just "pygments"
555 , optTopLevelDivision = TopLevelDefault
563 , optTopLevelDivision = TopLevelDefault
556 , optHTMLMathMethod = PlainMath
564 , optHTMLMathMethod = PlainMath
565+ , optAbbreviations = Nothing
557 , optReferenceDoc = Nothing
566 , optReferenceDoc = Nothing
558 , optEpubMetadata = Nothing
567 , optEpubMetadata = Nothing
559 , optEpubFonts = []
568 , optEpubFonts = []
@@ -772,7 +781,7 @@ options =
772 , Option "o" ["output"]
781 , Option "o" ["output"]
773 (ReqArg
782 (ReqArg
774 (\arg opt -> return opt { optOutputFile = arg })
783 (\arg opt -> return opt { optOutputFile = arg })
775− "FILENAME")
784+ "FILE")
776 "" -- "Name of output file"
785 "" -- "Name of output file"
777
786
778 , Option "" ["data-dir"]
787 , Option "" ["data-dir"]
@@ -855,7 +864,7 @@ options =
855 (\arg opt ->
864 (\arg opt ->
856 return opt{ optTemplate = Just arg,
865 return opt{ optTemplate = Just arg,
857 optStandalone = True })
866 optStandalone = True })
858− "FILENAME")
867+ "FILE")
859 "" -- "Use custom template"
868 "" -- "Use custom template"
860
869
861 , Option "M" ["metadata"]
870 , Option "M" ["metadata"]
@@ -954,7 +963,7 @@ options =
954 (\arg opt -> return opt{ optIncludeInHeader =
963 (\arg opt -> return opt{ optIncludeInHeader =
955 arg : optIncludeInHeader opt,
964 arg : optIncludeInHeader opt,
956 optStandalone = True })
965 optStandalone = True })
957− "FILENAME")
966+ "FILE")
958 "" -- "File to include at end of header (implies -s)"
967 "" -- "File to include at end of header (implies -s)"
959
968
960 , Option "B" ["include-before-body"]
969 , Option "B" ["include-before-body"]
@@ -962,7 +971,7 @@ options =
962 (\arg opt -> return opt{ optIncludeBeforeBody =
971 (\arg opt -> return opt{ optIncludeBeforeBody =
963 arg : optIncludeBeforeBody opt,
972 arg : optIncludeBeforeBody opt,
964 optStandalone = True })
973 optStandalone = True })
965− "FILENAME")
974+ "FILE")
966 "" -- "File to include before document body"
975 "" -- "File to include before document body"
967
976
968 , Option "A" ["include-after-body"]
977 , Option "A" ["include-after-body"]
@@ -970,7 +979,7 @@ options =
970 (\arg opt -> return opt{ optIncludeAfterBody =
979 (\arg opt -> return opt{ optIncludeAfterBody =
971 arg : optIncludeAfterBody opt,
980 arg : optIncludeAfterBody opt,
972 optStandalone = True })
981 optStandalone = True })
973− "FILENAME")
982+ "FILE")
974 "" -- "File to include after document body"
983 "" -- "File to include after document body"
975
984
976 , Option "" ["self-contained"]
985 , Option "" ["self-contained"]
@@ -1110,7 +1119,7 @@ options =
1110 (ReqArg
1119 (ReqArg
1111 (\arg opt ->
1120 (\arg opt ->
1112 return opt { optReferenceDoc = Just arg })
1121 return opt { optReferenceDoc = Just arg })
1113− "FILENAME")
1122+ "FILE")
1114 "" -- "Path of custom reference doc"
1123 "" -- "Path of custom reference doc"
1115
1124
1116 , Option "" ["epub-cover-image"]
1125 , Option "" ["epub-cover-image"]
@@ -1118,13 +1127,13 @@ options =
1118 (\arg opt ->
1127 (\arg opt ->
1119 return opt { optVariables =
1128 return opt { optVariables =
1120 ("epub-cover-image", arg) : optVariables opt })
1129 ("epub-cover-image", arg) : optVariables opt })
1121− "FILENAME")
1130+ "FILE")
1122 "" -- "Path of epub cover image"
1131 "" -- "Path of epub cover image"
1123
1132
1124 , Option "" ["epub-metadata"]
1133 , Option "" ["epub-metadata"]
1125 (ReqArg
1134 (ReqArg
1126 (\arg opt -> return opt { optEpubMetadata = Just arg })
1135 (\arg opt -> return opt { optEpubMetadata = Just arg })
1127− "FILENAME")
1136+ "FILE")
1128 "" -- "Path of epub metadata file"
1137 "" -- "Path of epub metadata file"
1129
1138
1130 , Option "" ["epub-embed-font"]
1139 , Option "" ["epub-embed-font"]
@@ -1261,6 +1270,12 @@ options =
1261 (\opt -> return opt { optHTMLMathMethod = GladTeX }))
1270 (\opt -> return opt { optHTMLMathMethod = GladTeX }))
1262 "" -- "Use gladtex for HTML math"
1271 "" -- "Use gladtex for HTML math"
1263
1272
1273+ , Option "" ["abbreviations"]
1274+ (ReqArg
1275+ (\arg opt -> return opt { optAbbreviations = Just arg })
1276+ "FILE")
1277+ "" -- "Specify file for custom abbreviations"
1278+
1264 , Option "" ["trace"]
1279 , Option "" ["trace"]
1265 (NoArg
1280 (NoArg
1266 (\opt -> return opt { optVerbosity = DEBUG }))
1281 (\opt -> return opt { optVerbosity = DEBUG }))