aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Johnson <nick@nicksphere.ch>2022-01-18 00:00:00 +0000
committerNicholas Johnson <nick@nicksphere.ch>2022-01-18 00:00:00 +0000
commit97266cf7187c5e593def3138d01ec0e9560de1f4b8c76737945e43b02a935623 (patch)
treef2d0944cadb99ae6016b85d4059038118aacf7f69bb818bda47b313f7575dc7d
parent462caea6a2969f5cb9a2f0c9edc96aed103eb6b9711b5eb2ec849594f9a37a9e (diff)
Document getlinetype()
-rw-r--r--src/gemini2html.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/gemini2html.c b/src/gemini2html.c
index c080932..d40a3bd 100644
--- a/src/gemini2html.c
+++ b/src/gemini2html.c
@@ -24,6 +24,7 @@
#include "gemini2html.h"
/* Escapes text so it can be safely inserted within HTML tags and attributes.
+ *
* Examples:
* escape_text("5 < 6", 5) => "5 &lt; 6"
* escape_text("6 > 5", 5) => "6 &gt; 5"
@@ -91,7 +92,9 @@ void skip_non_whitespace(const char* str, size_t* pos) {
}
/* Escapes unescaped, prepending opening_tag and appending closing tag and a newline.
+ *
* If unescaped ends in a newline, that newline is ignored. Inserting it causes the returned string to line break inappropriately.
+ *
* Examples:
* escape_text_add_tags("<p>", "5 < 6\n", "</p>", 6) => "<p>5 &lt; 6</p>\n"
* escape_text_add_tags("<p>", "5 < 6", "</p>", 5) => "<p>5 &lt; 6</p>\n"
@@ -132,7 +135,13 @@ char* escape_text_add_tags(const char* opening_tag, const char* unescaped, const
enum linetype{Text, Pre, Pre_toggle, Link, H1, H2, H3, Ul, Quote};
+/* Returns the line type.
+ *
+ * Gemini line type can be quickly determined based on the first three characters of the line.
+ * It's impossible to distinguish between preformatted text and text given only the line, so pre_is_toggled is used as a hint.
+ */
enum linetype getlinetype(const char* line, const bool pre_is_toggled) {
+ /* the order of the if-else statements is important */
if (prefix("```", line)) return Pre_toggle;
else if (pre_is_toggled) return Pre;
else if (prefix("###", line)) return H3;