From 29306d8dde650f5ac2bcc067f3c1d3bcfcac7a1d Mon Sep 17 00:00:00 2001 From: elij Date: Sun, 26 Jan 2025 12:18:58 -0800 Subject: [PATCH] strip indentation after a hard line break `++` * strip indentation (`\t` and ' ') after a hard line break `++` * add some tests to cover these cases --- src/main.c | 11 +++++++++++ test/line-breaks | 10 ++++++++++ test/lists | 20 ++++++++++++++++++++ diff --git a/src/main.c b/src/main.c index fa733c3377e105cf44efb8dabf6e5bb380674ec3..7c4d4af9021e81a6c80e362025d7095a930c8b27 100644 --- a/src/main.c +++ b/src/main.c @@ -200,8 +200,18 @@ } static void parse_text(struct parser *p) { uint32_t ch, next, last = ' '; + bool chomp_next_indent = false; int i = 0; while ((ch = parser_getch(p)) != UTF8_INVALID) { + // skip indentation if last was a linebreak + // and we need to chomp indentation + if (chomp_next_indent) { + if (ch == '\t' || ch == ' ') { + continue; + } + chomp_next_indent = false; + } + switch (ch) { case '\\': ch = parser_getch(p); @@ -235,6 +245,7 @@ break; case '+': if (parse_linebreak(p)) { last = '\n'; + chomp_next_indent = true; } break; case '\n': diff --git a/test/line-breaks b/test/line-breaks index 83dc70364076baed1b96a58a5e9a4c751acc47b9..9c28089b589a0ffbd8b8724aaae2d492005bcb3d 100755 --- a/test/line-breaks +++ b/test/line-breaks @@ -10,6 +10,16 @@ world EOF end 0 +begin "Handles line break with indentation" +scdoc </dev/null +test(8) + +test + hello++ + world +EOF +end 0 + begin "Disallows empty line after line break" scdoc </dev/null test(8) diff --git a/test/lists b/test/lists new file mode 100755 index 0000000000000000000000000000000000000000..4865f43e45bb0d5ca05b225f842f81a6fad2d3db --- /dev/null +++ b/test/lists @@ -0,0 +1,20 @@ +#!/bin/sh +. test/lib.sh + +begin "Handles lists" +scdoc </dev/null +test(8) + +- Item 1 +- Item 2 +EOF +end 0 + +begin "Handles line break in list" +scdoc </dev/null +test(8) + +- Item 1++ + Where am I rendered? +EOF +end 0 \ No newline at end of file -- 2.48.1