summaryrefslogtreecommitdiff
path: root/gemini/gemtext/parse_line.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-04-29 18:10:50 -0600
committertjpcc <tjp@ctrl-c.club>2023-04-29 18:10:50 -0600
commit3ff04cf88571f8ed1aca78da4efe4929ad583ca6 (patch)
treebb2bc248f4049d3c7833a8d6661d17c91f03e642 /gemini/gemtext/parse_line.go
parent9e09825537e4ae91119987f979ec4272d1727a2e (diff)
spartan =: prompt line support in gemtext
Diffstat (limited to 'gemini/gemtext/parse_line.go')
-rw-r--r--gemini/gemtext/parse_line.go43
1 files changed, 41 insertions, 2 deletions
diff --git a/gemini/gemtext/parse_line.go b/gemini/gemtext/parse_line.go
index 39187a8..e31e5b6 100644
--- a/gemini/gemtext/parse_line.go
+++ b/gemini/gemtext/parse_line.go
@@ -10,10 +10,16 @@ func ParseLine(line []byte) Line {
switch line[0] {
case '=':
- if len(line) == 1 || line[1] != '>' {
+ if len(line) == 1 {
break
}
- return parseLinkLine(line)
+ if line[1] == '>' {
+ return parseLinkLine(line)
+ }
+ if line[1] == ':' {
+ return parsePromptLine(line)
+ }
+ break
case '`':
if len(line) < 3 || line[1] != '`' || line[2] != '`' {
break
@@ -73,6 +79,39 @@ func parseLinkLine(raw []byte) LinkLine {
return line
}
+func parsePromptLine(raw []byte) PromptLine {
+ line := PromptLine{raw: raw}
+
+ // move past =:[<whitespace>]
+ raw = bytes.TrimLeft(raw[2:], " \t")
+
+ // find the next space or tab
+ spIdx := bytes.IndexByte(raw, ' ')
+ tbIdx := bytes.IndexByte(raw, '\t')
+ idx := spIdx
+ if idx == -1 {
+ idx = tbIdx
+ }
+ if tbIdx >= 0 && tbIdx < idx {
+ idx = tbIdx
+ }
+
+ if idx < 0 {
+ line.url = bytes.TrimRight(raw, "\r\n")
+ return line
+ }
+
+ line.url = raw[:idx]
+ raw = raw[idx+1:]
+
+ label := bytes.TrimRight(bytes.TrimLeft(raw, " \t"), "\r\n")
+ if len(label) > 0 {
+ line.label = label
+ }
+
+ return line
+}
+
func parsePreformatToggleLine(raw []byte) PreformatToggleLine {
line := PreformatToggleLine{raw: raw}