4 * handle string spacing as markdown:
5 * - two spaces escape a linebreak (otherwise text wraps)
6 * - two linebreaks become a paragraph (remain unchanged)
8 string markdown(string s)
13 FOREACH_CHAR(s, true, {
16 for (; spaces > 0; --spaces) {
17 buf = strcat(buf, " ");
19 buf = strcat(buf, chr2str(it));
29 buf = strcat(buf, "\n\n");
36 buf = strcat(buf, "\n");
44 TEST(Markdown, LineWrap)
46 #define X(expect, in) MACRO_BEGIN \
47 string out = markdown(in); \
48 EXPECT_TRUE(expect == out); \
54 X("lorem ipsum", "lorem ipsum");
55 // trim trailing space
56 X("lorem ipsum", "lorem ipsum ");
57 // allow manual input wrapping
58 X("lorem ipsum", "lorem\nipsum");
60 X("lorem\nipsum", "lorem \nipsum");
62 X("lorem\n\nipsum", "lorem\n\nipsum");