Skip to content

Commit

Permalink
Fix bug when table cells contain wide characters
Browse files Browse the repository at this point in the history
[Issue #4](#4)
  • Loading branch information
eldritch-blast committed May 28, 2021
1 parent f19b772 commit 11b1f05
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/line_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ impl<'s> LineParser<'s> {
let mut after_first_tilde = false;
let mut after_antislash = false;

for (idx, char) in self.src.char_indices().skip(self.idx) {
// self.idx tracks byte indices, but str::char_indices returns an
// iterator over chars, which may be wider than one byte. So we need
// to skip not self.idx elements, but the number of chars that occur
// before self.idx
let chars_to_skip = self.src[..self.idx].chars().count();
for (idx, char) in self.src.char_indices().skip(chars_to_skip) {
if self.code {
// only one thing matters: whether we're closing the inline code
if char == '`' {
Expand Down Expand Up @@ -495,6 +500,27 @@ mod tests {
);
}

#[test]
fn table_row_issue_4() {
assert_eq!(
Line::from("| 安 | 安 | 安 |"),
Line::new_table_row(vec![
Composite {
style: CompositeStyle::Paragraph,
compounds: vec![Compound::raw_str("安"),],
},
Composite {
style: CompositeStyle::Paragraph,
compounds: vec![Compound::raw_str("安"),],
},
Composite {
style: CompositeStyle::Paragraph,
compounds: vec![Compound::raw_str("安"),],
},
])
);
}

#[test]
fn table_alignments() {
assert_eq!(
Expand Down

0 comments on commit 11b1f05

Please sign in to comment.