git.iko.soy/typeable/pandoc
on master help sign in
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.

commit20cd33e5a44810b68fed74da00f4f51eb2282147 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 8 Apr 2021, 14:47 (6 years ago) parente227496
2 files changed+41−5
src/Text/Pandoc/Shared.hs+13−5 test/command/7214.md+28
src/Text/Pandoc/Shared.hs+13−5
@@ -153,12 +153,20 @@ splitTextBy isSep t
153153 in first : splitTextBy isSep (T.dropWhile isSep rest)
154154
155155splitTextByIndices :: [Int] -> T.Text -> [T.Text]
156−splitTextByIndices ns = splitTextByRelIndices (zipWith (-) ns (0:ns))
156+splitTextByIndices ns = splitTextByRelIndices (zipWith (-) ns (0:ns)) . T.unpack
157157 where
158− splitTextByRelIndices [] t = [t]
159− splitTextByRelIndices (x:xs) t =
160− let (first, rest) = T.splitAt x t
161− in first : splitTextByRelIndices xs rest
158+ splitTextByRelIndices [] cs = [T.pack cs]
159+ splitTextByRelIndices (x:xs) cs =
160+ let (first, rest) = splitAt' x cs
161+ in T.pack first : splitTextByRelIndices xs rest
162+
163+-- Note: don't replace this with T.splitAt, which is not sensitive
164+-- to character widths!
165+splitAt' :: Int -> [Char] -> ([Char],[Char])
166+splitAt' _ [] = ([],[])
167+splitAt' n xs | n <= 0 = ([],xs)
168+splitAt' n (x:xs) = (x:ys,zs)
169+ where (ys,zs) = splitAt' (n - charWidth x) xs
162170
163171ordNub :: (Ord a) => [a] -> [a]
164172ordNub l = go Set.empty l
test/command/7214.mdnew file+28
@@ -0,0 +1,28 @@
1+```
2+% pandoc
3++------------+----------+------------------+
4+|日本語 | の文字列 | words in english |
5++------------+----------+------------------+
6+|abc defghij | def | xyz |
7++------------+----------+------------------+
8+^D
9+<table style="width:60%;">
10+<colgroup>
11+<col style="width: 18%" />
12+<col style="width: 15%" />
13+<col style="width: 26%" />
14+</colgroup>
15+<tbody>
16+<tr class="odd">
17+<td>日本語</td>
18+<td>の文字列</td>
19+<td>words in english</td>
20+</tr>
21+<tr class="even">
22+<td>abc defghij</td>
23+<td>def</td>
24+<td>xyz</td>
25+</tr>
26+</tbody>
27+</table>
28+```