mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Support consecutive lines in paragraphs
This commit is contained in:
parent
1d5e2e515c
commit
987dc5b20f
@ -51,6 +51,13 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) {
|
|||||||
addLine := func(text interface{}) {
|
addLine := func(text interface{}) {
|
||||||
*ast = append(*ast, Line{id: state.id, contents: text})
|
*ast = append(*ast, Line{id: state.id, contents: text})
|
||||||
}
|
}
|
||||||
|
addParagraphIfNeeded := func() {
|
||||||
|
if state.where == "p" {
|
||||||
|
state.where = ""
|
||||||
|
addLine(fmt.Sprintf("<p id='%d'>%s</p>", state.id, strings.ReplaceAll(ParagraphToHtml(state.name, state.buf), "\n", "<br>")))
|
||||||
|
state.buf = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Process empty lines depending on the current state
|
// Process empty lines depending on the current state
|
||||||
if "" == strings.TrimSpace(line) {
|
if "" == strings.TrimSpace(line) {
|
||||||
@ -66,6 +73,8 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) {
|
|||||||
case "launchpad":
|
case "launchpad":
|
||||||
state.where = ""
|
state.where = ""
|
||||||
addLine(state.buf + "</ul>")
|
addLine(state.buf + "</ul>")
|
||||||
|
case "p":
|
||||||
|
addParagraphIfNeeded()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -91,7 +100,7 @@ func lineToAST(line string, state *GemLexerState, ast *[]Line) {
|
|||||||
goto numberState
|
goto numberState
|
||||||
case "launchpad":
|
case "launchpad":
|
||||||
goto launchpadState
|
goto launchpadState
|
||||||
default:
|
default: // "p" or ""
|
||||||
goto normalState
|
goto normalState
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,43 +184,57 @@ normalState:
|
|||||||
switch {
|
switch {
|
||||||
|
|
||||||
case startsWith("```"):
|
case startsWith("```"):
|
||||||
|
addParagraphIfNeeded()
|
||||||
state.where = "pre"
|
state.where = "pre"
|
||||||
state.buf = fmt.Sprintf("<pre id='%d' alt='%s' class='codeblock'><code>", state.id, strings.TrimPrefix(line, "```"))
|
state.buf = fmt.Sprintf("<pre id='%d' alt='%s' class='codeblock'><code>", state.id, strings.TrimPrefix(line, "```"))
|
||||||
case startsWith("* "):
|
case startsWith("* "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
state.where = "list"
|
state.where = "list"
|
||||||
state.buf = fmt.Sprintf("<ul id='%d'>\n", state.id)
|
state.buf = fmt.Sprintf("<ul id='%d'>\n", state.id)
|
||||||
goto listState
|
goto listState
|
||||||
case startsWith("*. "):
|
case startsWith("*. "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
state.where = "number"
|
state.where = "number"
|
||||||
state.buf = fmt.Sprintf("<ol id='%d'>\n", state.id)
|
state.buf = fmt.Sprintf("<ol id='%d'>\n", state.id)
|
||||||
goto numberState
|
goto numberState
|
||||||
|
|
||||||
case startsWith("###### "):
|
case startsWith("###### "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(6)
|
addHeading(6)
|
||||||
case startsWith("##### "):
|
case startsWith("##### "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(5)
|
addHeading(5)
|
||||||
case startsWith("#### "):
|
case startsWith("#### "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(4)
|
addHeading(4)
|
||||||
case startsWith("### "):
|
case startsWith("### "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(3)
|
addHeading(3)
|
||||||
case startsWith("## "):
|
case startsWith("## "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(2)
|
addHeading(2)
|
||||||
case startsWith("# "):
|
case startsWith("# "):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addHeading(1)
|
addHeading(1)
|
||||||
|
|
||||||
case startsWith(">"):
|
case startsWith(">"):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addLine(fmt.Sprintf(
|
addLine(fmt.Sprintf(
|
||||||
"<blockquote id='%d'>%s</blockquote>", state.id, remover(">")(line)))
|
"<blockquote id='%d'>%s</blockquote>", state.id, remover(">")(line)))
|
||||||
case startsWith("=>"):
|
case startsWith("=>"):
|
||||||
|
addParagraphIfNeeded()
|
||||||
state.where = "launchpad"
|
state.where = "launchpad"
|
||||||
state.buf = fmt.Sprintf("<ul class='launchpad' id='%d'>\n", state.id)
|
state.buf = fmt.Sprintf("<ul class='launchpad' id='%d'>\n", state.id)
|
||||||
goto launchpadState
|
goto launchpadState
|
||||||
|
|
||||||
case startsWith("<="):
|
case startsWith("<="):
|
||||||
|
addParagraphIfNeeded()
|
||||||
addLine(parseTransclusion(line, state.name))
|
addLine(parseTransclusion(line, state.name))
|
||||||
case line == "----":
|
case line == "----":
|
||||||
|
addParagraphIfNeeded()
|
||||||
*ast = append(*ast, Line{id: -1, contents: "<hr/>"})
|
*ast = append(*ast, Line{id: -1, contents: "<hr/>"})
|
||||||
case MatchesImg(line):
|
case MatchesImg(line):
|
||||||
|
addParagraphIfNeeded()
|
||||||
img, shouldGoBackToNormal := ImgFromFirstLine(line, state.name)
|
img, shouldGoBackToNormal := ImgFromFirstLine(line, state.name)
|
||||||
if shouldGoBackToNormal {
|
if shouldGoBackToNormal {
|
||||||
addLine(*img)
|
addLine(*img)
|
||||||
@ -220,9 +243,14 @@ normalState:
|
|||||||
state.img = img
|
state.img = img
|
||||||
}
|
}
|
||||||
case MatchesTable(line):
|
case MatchesTable(line):
|
||||||
|
addParagraphIfNeeded()
|
||||||
state.where = "table"
|
state.where = "table"
|
||||||
state.table = TableFromFirstLine(line, state.name)
|
state.table = TableFromFirstLine(line, state.name)
|
||||||
|
|
||||||
|
case state.where == "p":
|
||||||
|
state.buf += "\n" + line
|
||||||
default:
|
default:
|
||||||
addLine(fmt.Sprintf("<p id='%d'>%s</p>", state.id, ParagraphToHtml(state.name, line)))
|
state.where = "p"
|
||||||
|
state.buf = line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 95f48bfd7a7cfef17d56cef207a770767d727950
|
Subproject commit b67144cc770900104a652483c11cabfecc7325aa
|
Loading…
Reference in New Issue
Block a user