4 * handle string spacing as markdown:
5 * - two spaces escape a linebreak (otherwise text wraps)
6 * - two linebreaks become a paragraph (remain unchanged)
9 string markdown(string s)
14 FOREACH_CHAR(s, true, {
17 for (; spaces > 0; --spaces) {
18 buf = strcat(buf, " ");
20 buf = strcat(buf, chr2str(it));
30 buf = strcat(buf, "\n\n");
37 buf = strcat(buf, "\n");
45 TEST(Markdown, LineWrap)
47 #define X(expect, in) MACRO_BEGIN \
48 string out = markdown(in); \
49 EXPECT_TRUE(expect == out); \
55 X("lorem ipsum", "lorem ipsum");
56 // trim trailing space
57 X("lorem ipsum", "lorem ipsum ");
58 // allow manual input wrapping
59 X("lorem ipsum", "lorem\nipsum");
61 X("lorem\nipsum", "lorem \nipsum");
63 X("lorem\n\nipsum", "lorem\n\nipsum");