summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-02-05 00:06:02 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2016-02-05 00:06:02 -0800
commit555472cf8d1ffe99506fdbd2a87e2e33bb3b197f (patch)
treebeabf7ac93ee86838b2c4592d478e6f652b16172 /src
parentcdb0a5e8602ce2475555c48c9f285e736ccb22ef (diff)
Fixed tabs in indentation.
Closes #101. This patch fixes `S_advance_offset` so that it doesn't gobble a tab character when advancing less than the width of a tab.
Diffstat (limited to 'src')
-rw-r--r--src/blocks.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 9f41e1f..6d02a84 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -570,12 +570,14 @@ static void S_advance_offset(cmark_parser *parser, cmark_chunk *input,
bufsize_t count, bool columns) {
char c;
int chars_to_tab;
+ int chars_to_advance;
while (count > 0 && (c = peek_at(input, parser->offset))) {
if (c == '\t') {
chars_to_tab = TAB_STOP - (parser->column % TAB_STOP);
- parser->column += chars_to_tab;
- parser->offset += 1;
- count -= (columns ? chars_to_tab : 1);
+ chars_to_advance = chars_to_tab > count ? count : chars_to_tab;
+ parser->column += chars_to_advance;
+ parser->offset += chars_to_advance < chars_to_tab ? 0 : 1;
+ count -= (columns ? chars_to_advance : 1);
} else {
parser->offset += 1;
parser->column += 1; // assume ascii; block starts are ascii