summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2014-08-12 10:26:49 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2014-08-12 10:26:49 -0400
commit9d0b390d48823e2fcbcbabf84fd105b595bcb60b (patch)
tree8132d433e79778ef92b81fb73b6ea0c0dc1ef37f /src/Text/Pandoc/Readers/Docx
parente4a8e4a636fb4b9bc860591f31bdb8e4dde62049 (diff)
Docx reader: move combining logic to Reducible
Introduces a new function in Reducibles, concatR. The idea is that if we have two list of Reducibles (blocks or inlines), we can combine them and just perform the reduction on the joining parts (the last element of the first list, the first element of the second list). This is useful in cases where the two lists are already reduced, and we're only worried about the joining elements. This actually improves the efficiency a bit further, because concatR can be smart about empty lists.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Reducible.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Reducible.hs b/src/Text/Pandoc/Readers/Docx/Reducible.hs
index a852e25bf..39a93d988 100644
--- a/src/Text/Pandoc/Readers/Docx/Reducible.hs
+++ b/src/Text/Pandoc/Readers/Docx/Reducible.hs
@@ -39,6 +39,7 @@ module Text.Pandoc.Readers.Docx.Reducible ((<++>),
innards,
reduceList,
reduceListB,
+ concatR,
rebuild)
where
@@ -78,6 +79,15 @@ reduceList' as (x:xs) = reduceList' (init as ++ (last as <++> x) ) xs
reduceList :: (Reducible a) => [a] -> [a]
reduceList = reduceList' []
+concatR :: (Reducible a) => [a] -> [a] -> [a]
+concatR [] [] = []
+concatR [] ss = ss
+concatR rs [] = rs
+concatR rs ss = let (x:xs) = reverse rs
+ (y:ys) = ss
+ in
+ reverse xs ++ ( x <++> y ) ++ ys
+
combineReducibles :: (Reducible a, Eq a) => a -> a -> [a]
combineReducibles r s =
let (conts, rs) = topLevelContainers r