aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-04-08 14:47:11 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-04-08 14:48:29 -0700
commit20cd33e5a44810b68fed74da00f4f51eb2282147 (patch)
tree3ac87b5f2603ebeabae5df056863503d0268ac04 /src/Text/Pandoc
parente227496d3a5d07df8183b8d986ea2aa36c90612c (diff)
downloadpandoc-20cd33e5a44810b68fed74da00f4f51eb2282147.tar.gz
Fix regression in grid tables for wide characters.
In the translation from String to Text, a char-width-sensitive splitAt' was dropped. This commit reinstates it. Closes #7214.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Shared.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 3292b32f4..95cbdc8b8 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -153,12 +153,20 @@ splitTextBy isSep t
in first : splitTextBy isSep (T.dropWhile isSep rest)
splitTextByIndices :: [Int] -> T.Text -> [T.Text]
-splitTextByIndices ns = splitTextByRelIndices (zipWith (-) ns (0:ns))
+splitTextByIndices ns = splitTextByRelIndices (zipWith (-) ns (0:ns)) . T.unpack
where
- splitTextByRelIndices [] t = [t]
- splitTextByRelIndices (x:xs) t =
- let (first, rest) = T.splitAt x t
- in first : splitTextByRelIndices xs rest
+ splitTextByRelIndices [] cs = [T.pack cs]
+ splitTextByRelIndices (x:xs) cs =
+ let (first, rest) = splitAt' x cs
+ in T.pack first : splitTextByRelIndices xs rest
+
+-- Note: don't replace this with T.splitAt, which is not sensitive
+-- to character widths!
+splitAt' :: Int -> [Char] -> ([Char],[Char])
+splitAt' _ [] = ([],[])
+splitAt' n xs | n <= 0 = ([],xs)
+splitAt' n (x:xs) = (x:ys,zs)
+ where (ys,zs) = splitAt' (n - charWidth x) xs
ordNub :: (Ord a) => [a] -> [a]
ordNub l = go Set.empty l