From 9f941720504d81815973e37491c79f44fd4a4a1b Mon Sep 17 00:00:00 2001 From: luca0N! Date: Wed, 2 Mar 2022 17:44:07 -0300 Subject: [PATCH] Added paragraph support to MarkdownParser MarkdownParser will now recognize and insert paragraphs. --- src/MarkdownParser.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/MarkdownParser.cxx b/src/MarkdownParser.cxx index 1059e7f..3652078 100644 --- a/src/MarkdownParser.cxx +++ b/src/MarkdownParser.cxx @@ -40,6 +40,7 @@ std::string make_html(std::filesystem::path const &path) { // Tag flags bool tag_b = false, tag_i = false, + tag_p = false, // If there is an escape character at the end of the buffer, use // this flag to prevent ignoring it. escaping = false, @@ -52,6 +53,13 @@ std::string make_html(std::filesystem::path const &path) { int tag_h = 0; while (fgets(buf, buflen, mdFile) != NULL) { manualBreak = false; + + if (tag_p && buf[0] == '\n') { + // Empty newline; end paragraph. + html += "

\n"; + continue; + } + // Read character by character for (int x = 0; x < buflen; x++) { char c = buf[x]; @@ -72,6 +80,13 @@ std::string make_html(std::filesystem::path const &path) { html += '\n'; break; } + // Start paragraph if newline and no + // special characters were matched. + + if (newline && x == 0 && c != '#') + html += "

", + tag_p = true; + switch (c) { case '*': // Bold check