commit c78768cdf461af899dff73d7628e4243162469ce
parent b4809580027b1ed231490822149cc453d733fd40
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 30 Sep 2026 20:54:11 -0500
permissive parsing of whitespaces per the spec
Diffstat:
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/utils.cpp b/src/utils.cpp
@@ -106,23 +106,23 @@ Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount, boo
}
if(!isPreformatted) {
- if(input.substr(0,2) == "=>" && isWhiteSpace(input,2)) {
+ if(input.substr(0,2) == "=>") {
Link* ln = new Link{input, prior, linkCount};
return ln;
}
- if( (input.substr(0,1) == "#" && isWhiteSpace(input,1)) ||
- (input.substr(0,2) == "##" && isWhiteSpace(input,2)) ||
- (input.substr(0,3) == "###" && isWhiteSpace(input,3))) {
+ if( (input.substr(0,1) == "#" ) ||
+ (input.substr(0,2) == "##") ||
+ (input.substr(0,3) == "###")) {
Heading* hd = new Heading{input};
return hd;
}
- if(input.substr(0,1) == ">" && isWhiteSpace(input,1)) {
+ if(input.substr(0,1) == ">") {
Quote* qt= new Quote{input};
return qt;
}
- if(input.substr(0,1) == "*" && isWhiteSpace(input,1)) {
+ if(input.substr(0,1) == "*") {
ListItem* li= new ListItem{input};
return li;
}
diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp
@@ -322,27 +322,27 @@ TEST_CASE("Test line parsing handles whitespace correctly") {
TEST_CASE("Proper whitespace compliance") {
- SECTION("Line types become plaintext when missing proper spacing") {
+ SECTION("Line types without white spacing") {
auto res1 = lineToLine("", std::nullopt, -1, false);
REQUIRE(res1->type() == PLAINTEXT);
auto res3 = lineToLine("=>gemini://laack.co", std::nullopt, 1, false);
- REQUIRE(res3->type() == PLAINTEXT);
+ REQUIRE(res3->type() == LINK);
auto res5 = lineToLine("#H1 Heading", std::nullopt, 1, false);
- REQUIRE(res5->type() == PLAINTEXT);
+ REQUIRE(res5->type() == H1);
auto res6 = lineToLine("##H2 Heading", std::nullopt, 1, false);
- REQUIRE(res6->type() == PLAINTEXT);
+ REQUIRE(res6->type() == H2);
auto res7 = lineToLine("###H3 Heading", std::nullopt, 1, false);
- REQUIRE(res7->type() == PLAINTEXT);
+ REQUIRE(res7->type() == H3);
auto res8 = lineToLine(">test quote", std::nullopt, 1, false);
- REQUIRE(res8->type() == PLAINTEXT);
+ REQUIRE(res8->type() == QUOTE);
auto res9 = lineToLine("*test li", std::nullopt, 1, false);
- REQUIRE(res9->type() == PLAINTEXT);
+ REQUIRE(res9->type() == LIST_ITEM);
}
SECTION("Non-whitespace based line types don't require whitespace") {
@@ -386,7 +386,7 @@ TEST_CASE("Line parser handles lines that are only format characters with whites
REQUIRE(res9->type() == LIST_ITEM);
}
-
+// I was wrong on this originally bc the spec states whitespaces are optional.
TEST_CASE("Line parser handles lines that are only format characters without whitespaces") {
auto res1 = lineToLine("", std::nullopt, -1, false);
REQUIRE(res1->type() == PLAINTEXT);
@@ -395,25 +395,25 @@ TEST_CASE("Line parser handles lines that are only format characters without whi
REQUIRE(res2->type() == PREFORMATTED);
auto res3 = lineToLine("=>", std::nullopt, 1, false);
- REQUIRE(res3->type() == PLAINTEXT);
+ REQUIRE(res3->type() == LINK);
auto res4 = lineToLine("```", std::nullopt, 1, false);
REQUIRE(res4->type() == FORMAT_SWITCH);
auto res5 = lineToLine("#", std::nullopt, 1, false);
- REQUIRE(res5->type() == PLAINTEXT);
+ REQUIRE(res5->type() == H1);
auto res6 = lineToLine("##", std::nullopt, 1, false);
- REQUIRE(res6->type() == PLAINTEXT);
+ REQUIRE(res6->type() == H2);
auto res7 = lineToLine("###", std::nullopt, 1, false);
- REQUIRE(res7->type() == PLAINTEXT);
+ REQUIRE(res7->type() == H3);
auto res8 = lineToLine(">", std::nullopt, 1, false);
- REQUIRE(res8->type() == PLAINTEXT);
+ REQUIRE(res8->type() == QUOTE);
auto res9 = lineToLine("*", std::nullopt, 1, false);
- REQUIRE(res9->type() == PLAINTEXT);
+ REQUIRE(res9->type() == LIST_ITEM);
}
static std::string linecharset = "#>=abc## de_-><0193248$#)(&@)(*&$#^*&#^%^&*&fghijklmnopqrstuvwxyz #````ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";