Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous refactors #10457

Merged
merged 7 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/Text/Pandoc/App/OutputSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Control.Monad.Except (throwError)
import Control.Monad.Trans
import Data.Char (toLower)
import Data.List (find)
import Data.Maybe (fromMaybe)
import Data.Maybe (catMaybes, fromMaybe)
import Skylighting (defaultSyntaxMap)
import Skylighting.Parser (addSyntaxDefinition, parseSyntaxDefinition)
import System.Directory (getCurrentDirectory)
Expand Down Expand Up @@ -321,10 +321,11 @@ isBinaryFormat s =
sandbox' :: (PandocMonad m, MonadIO m) => Opt -> PandocPure a -> m a
sandbox' opts = sandbox sandboxedFiles
where
sandboxedFiles = maybe id (:) (optReferenceDoc opts) .
maybe id (:) (optEpubMetadata opts) .
maybe id (:) (optEpubCoverImage opts) .
maybe id (:) (optCSL opts) .
maybe id (:) (optCitationAbbreviations opts) $
sandboxedFiles = catMaybes [ optReferenceDoc opts
, optEpubMetadata opts
, optEpubCoverImage opts
, optCSL opts
, optCitationAbbreviations opts
] ++
optEpubFonts opts ++
optBibliography opts
14 changes: 5 additions & 9 deletions src/Text/Pandoc/Readers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -927,25 +927,21 @@ pMath inCase = try $ do
let attr = toStringAttr attr'
unless inCase $
guard (maybe True (== mathMLNamespace) (lookup "xmlns" attr))
let isDisplay = case lookup "display" attr of
Just "block" -> True
_ -> False
let constructor = case lookup "display" attr of
Just "block" -> B.displayMath
_ -> B.math
contents <- manyTill pAny (pSatisfy (matchTagClose "math"))
-- KaTeX and others include original TeX in annotation tag;
-- just use this if present rather than parsing MathML:
case extractTeXAnnotation contents of
Just x -> return $ if isDisplay
then B.displayMath x
else B.math x
Just x -> return $ constructor x
Nothing ->
case mathMLToTeXMath (renderTags $
[open] <> contents <> [TagClose "math"]) of
Left _ -> return $ B.spanWith ("",["math"],attr) $ B.text $
innerText contents
Right "" -> return mempty
Right x -> return $ if isDisplay
then B.displayMath x
else B.math x
Right x -> return $ constructor x

extractTeXAnnotation :: [Tag Text] -> Maybe Text
extractTeXAnnotation [] = Nothing
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Pandoc/Readers/Mdoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Monad.Except (throwError)
#if MIN_VERSION_base(4,19,0)
import Data.List (intersperse, unsnoc)
#else
import Data.List (intersperse, uncons)
import Data.List (intersperse)
#endif
import qualified Data.Map.Strict as M
import qualified Data.Text as T
Expand All @@ -46,7 +46,7 @@ import Text.Pandoc.Shared (stringify)

#if !MIN_VERSION_base(4,19,0)
unsnoc :: [a] -> Maybe ([a], a)
unsnoc xs = (\(hd, tl) -> (reverse tl, hd)) <$> uncons (reverse xs)
unsnoc = foldr (\x -> Just . maybe ([], x) (\(~(a, b)) -> (x : a, b))) Nothing
#endif

{- As a general principle, if mandoc -T lint issues a WARNING admonition
Expand Down
9 changes: 3 additions & 6 deletions src/Text/Pandoc/Readers/Vimwiki.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import Data.List (isInfixOf)
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
import Safe (lastMay)
import Text.Pandoc.Builder (Blocks, Inlines, fromList, toList, trimInlines)
import qualified Text.Pandoc.Builder as B (blockQuote, bulletList, code,
codeBlockWith, definitionList,
Expand Down Expand Up @@ -510,9 +511,7 @@ strong = try $ do
notFollowedBy (oneOf spaceChars)
contents <- mconcat <$> many1Till inline'
(try (char '*' *> notFollowedBy alphaNum))
guard $ case reverse (toList contents) of
Space:_ -> False
_ -> True
guard $ lastMay (toList contents) /= Just Space
return $ B.spanWith (makeId contents, [], []) mempty <> B.strong contents

makeId :: Inlines -> Text
Expand All @@ -524,9 +523,7 @@ emph = try $ do
notFollowedBy (oneOf spaceChars)
contents <- mconcat <$> many1Till inline'
(try (char '_' *> notFollowedBy alphaNum))
guard $ case reverse (toList contents) of
Space:_ -> False
_ -> True
guard $ lastMay (toList contents) /= Just Space
return $ B.emph contents

strikeout :: PandocMonad m => VwParser m Inlines
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ makeSectionsWithOffsets numoffsets numbering mbBaseLevel bs =
where
getLevel (Header level _ _) = Min level
getLevel _ = Min 99
minLevel = if null numoffsets || all (== 0) numoffsets
minLevel = if all (== 0) numoffsets
then getMin $ query getLevel bs
else 1 -- see #5071, for backwards compatibility
go :: [Block] -> S.State [Int] [Block]
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Pandoc/Writers/ANSI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pandocToANSI opts (Pandoc meta blocks) = do
body <- blockListToANSI opts blocks'
notes <- gets $ reverse . stNotes
let notemark x = D.literal (tshow (x :: Int) <> ".") <+> D.space
let marks = take (length notes) $ map notemark [1..]
let marks = map notemark [1..length notes]
let hangWidth = foldr (max . D.offset) 0 marks
let notepretty | not (null notes) = D.cblock width hr $+$ hangMarks hangWidth marks notes
| otherwise = D.empty
Expand Down Expand Up @@ -297,12 +297,12 @@ inlineToANSI opts (Strikeout lst) = do
inlineToANSI opts (Superscript lst) = do
case traverse toSuperscriptInline lst of
Just xs -> inlineListToANSI opts xs
Nothing -> inlineListToANSI opts lst >>= return . D.parens
Nothing -> D.parens <$> inlineListToANSI opts lst

inlineToANSI opts (Subscript lst) = do
case traverse toSubscriptInline lst of
Just xs -> inlineListToANSI opts xs
Nothing -> inlineListToANSI opts lst >>= return . D.parens
Nothing -> D.parens <$> inlineListToANSI opts lst

inlineToANSI opts (SmallCaps lst) = inlineListToANSI opts lst

Expand Down
Loading