Fix list line break issue (#5)

Fixed an issue which would cause the MarkdownParser to prematurely end a list on a single line break.
This commit is contained in:
luca0N! 2023-09-07 23:10:02 -03:00
parent 340046a264
commit 12814571cf
Signed by: luca0N
GPG Key ID: 5978D960572B449E
1 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2022 luca0N! * Copyright (C) 2022-2023 luca0N!
* *
* This file is part of Static Website Generator (swg). * This file is part of Static Website Generator (swg).
* *
@ -102,9 +102,10 @@ std::string make_html(std::filesystem::path const &path) {
// End ul tag if it's active and a new line doesn't contain an // End ul tag if it's active and a new line doesn't contain an
// item. // item.
if (tag_ul && newline && buf[0] != '-') { if (tag_ul && newline && buf[0] != '-' && buf[0] == '\n') {
tag_ul = false; tag_ul = false;
html += "</ul>"; tag_li = false;
html += "</li></ul>";
} }
// Read character by character // Read character by character
@ -129,15 +130,14 @@ std::string make_html(std::filesystem::path const &path) {
html += ">"; html += ">";
tag_h = 0; tag_h = 0;
} }
if (tag_li) html += "</li>", tag_li = false; if (!tag_li)
html += '\n'; html += '\n';
break; break;
} }
// Start paragraph if newline and no // Start paragraph if newline and no
// special characters were matched. // special characters were matched.
if (!tag_comment && !tag_ul && (!tag_p && newline && x == 0 &&
if (!tag_comment && (!tag_p && newline && x == 0 &&
c != '#' && c != '-')) c != '#' && c != '-'))
html += "<p>", html += "<p>",
tag_p = true; tag_p = true;
@ -261,6 +261,10 @@ std::string make_html(std::filesystem::path const &path) {
// Start unordered list tag if it's not active. // Start unordered list tag if it's not active.
if (!tag_ul) html += "<ul>", tag_ul = true; if (!tag_ul) html += "<ul>", tag_ul = true;
// End previous list item, if active.
if (tag_li) html += "</li>\n", tag_li = false;
html += "<li>"; html += "<li>";
ignoreSpace = true; ignoreSpace = true;
tag_li = true; tag_li = true;