1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00

Fix some lexer bugs

This commit is contained in:
bouncepaw 2020-11-03 21:10:17 +05:00
parent a58baa64c3
commit 55597dddf2

View File

@ -53,14 +53,14 @@ func wikilink(src string, state *GemLexerState) (href, text, class string) {
hyphaName := canonicalName(path.Join( hyphaName := canonicalName(path.Join(
state.name, strings.TrimPrefix(href, "./"))) state.name, strings.TrimPrefix(href, "./")))
if !HyphaExists(hyphaName) { if !HyphaExists(hyphaName) {
class = "wikilink_new" class += " wikilink_new"
} }
href = path.Join("/page", hyphaName) href = path.Join("/page", hyphaName)
case strings.HasPrefix(href, "../"): case strings.HasPrefix(href, "../"):
hyphaName := canonicalName(path.Join( hyphaName := canonicalName(path.Join(
path.Dir(state.name), strings.TrimPrefix(href, "../"))) path.Dir(state.name), strings.TrimPrefix(href, "../")))
if !HyphaExists(hyphaName) { if !HyphaExists(hyphaName) {
class = "wikilink_new" class += " wikilink_new"
} }
href = path.Join("/page", hyphaName) href = path.Join("/page", hyphaName)
case strings.HasPrefix(href, "/"): case strings.HasPrefix(href, "/"):
@ -68,6 +68,9 @@ func wikilink(src string, state *GemLexerState) (href, text, class string) {
class = "wikilink_external" class = "wikilink_external"
default: default:
href = path.Join("/page", href) href = path.Join("/page", href)
if !HyphaExists(href) {
class += " wikilink_new"
}
} }
return href, strings.TrimSpace(text), class return href, strings.TrimSpace(text), class
} }
@ -88,7 +91,7 @@ func geminiLineToAST(line string, state *GemLexerState, ast *[]Line) {
} }
if "" == strings.TrimSpace(line) { if "" == strings.TrimSpace(line) {
if state.where == "list" { if state.where == "list" || state.where == "number" {
state.where = "" state.where = ""
addLine(state.buf + "</ul>") addLine(state.buf + "</ul>")
} }
@ -151,7 +154,7 @@ listState:
numberState: numberState:
switch { switch {
case startsWith("*. "): case startsWith("*. "):
state.buf += fmt.Sprintf("\t<li>%s</li>\n", ParagraphToHtml(line[2:])) state.buf += fmt.Sprintf("\t<li>%s</li>\n", ParagraphToHtml(line[3:]))
case startsWith("```"): case startsWith("```"):
state.where = "pre" state.where = "pre"
addLine(state.buf + "</ol>") addLine(state.buf + "</ol>")