Finished unordered list implementation

Finished the unordered list implementation in MarkdownParser.
This commit is contained in:
luca0N! 2022-03-03 18:00:52 -03:00
parent 58710d07c5
commit 5ecf95a4bf
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 11 additions and 0 deletions

View File

@ -42,6 +42,7 @@ std::string make_html(std::filesystem::path const &path) {
tag_i = false, tag_i = false,
tag_p = false, tag_p = false,
tag_li = false, tag_li = false,
tag_ul = false,
// If there is an escape character at the end of the buffer, use // If there is an escape character at the end of the buffer, use
// this flag to prevent ignoring it. // this flag to prevent ignoring it.
escaping = false, escaping = false,
@ -62,6 +63,13 @@ std::string make_html(std::filesystem::path const &path) {
continue; continue;
} }
// End ul tag if it's active and a new line doesn't contain an
// item.
if (tag_ul && buf[0] != '-') {
tag_ul = false;
html += "</ul>";
}
// Read character by character // Read character by character
for (int x = 0; x < buflen; x++) { for (int x = 0; x < buflen; x++) {
char c = buf[x]; char c = buf[x];
@ -83,6 +91,7 @@ std::string make_html(std::filesystem::path const &path) {
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.
@ -177,6 +186,8 @@ std::string make_html(std::filesystem::path const &path) {
break; break;
} }
// Start unordered list tag if it's not active.
if (!tag_ul) html += "<ul>", tag_ul = true;
html += "<li>"; html += "<li>";
ignoreSpace = true; ignoreSpace = true;
tag_li = true; tag_li = true;