Skip to content

Commit

Permalink
Clean-up splitMath implementation some more
Browse files Browse the repository at this point in the history
  • Loading branch information
lierdakil committed Aug 31, 2024
1 parent dee4b63 commit 42b9955
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib-internal/Text/Pandoc/CrossRef/References/Blocks/Math.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ replaceEqn eqTemplate (label, _, attrs) eq = do
splitMath :: [Block] -> [Block]
splitMath (Para ils:xs)
| _:_:_ <- ils -- at least two elements
= map Para (split [] [] ils) <> xs
= map Para (split ils) <> xs
where
split res acc [] = reverse (reverse acc : res)
split res acc (x@(Span _ [Math DisplayMath _]):ys) =
split ([x] : reverse (dropSpaces acc) : res)
[] (dropSpaces ys)
split res acc (y:ys) = split res (y:acc) ys
split ys =
let (before, after) = break isMath ys
beforeEl
| null before = id
| otherwise = (before :)
in beforeEl $ case after of
z:zs -> [z] : split (dropSpaces zs)
[] -> []
dropSpaces = dropWhile isSpace
isMath (Span _ [Math DisplayMath _]) = True
isMath _ = False
splitMath xs = xs

0 comments on commit 42b9955

Please sign in to comment.