1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-18 22:52:50 +00:00

Support formatting in headings

This commit is contained in:
bouncepaw 2020-11-12 23:21:49 +05:00
parent 8bc3fb9821
commit c111e95468
3 changed files with 10 additions and 32 deletions

View File

@ -59,6 +59,9 @@ func geminiLineToAST(line string, state *GemLexerState, ast *[]Line) {
startsWith := func(token string) bool {
return strings.HasPrefix(line, token)
}
addHeading := func(i int) {
addLine(fmt.Sprintf("<h%d id='%d'>%s</h%d>", i, state.id, ParagraphToHtml(state.name, line[i+1:]), i))
}
// Beware! Usage of goto. Some may say it is considered evil but in this case it helped to make a better-structured code.
switch state.where {
@ -142,23 +145,17 @@ normalState:
goto numberState
case startsWith("###### "):
addLine(fmt.Sprintf(
"<h6 id='%d'>%s</h6>", state.id, line[7:]))
addHeading(6)
case startsWith("##### "):
addLine(fmt.Sprintf(
"<h5 id='%d'>%s</h5>", state.id, line[6:]))
addHeading(5)
case startsWith("#### "):
addLine(fmt.Sprintf(
"<h4 id='%d'>%s</h4>", state.id, line[5:]))
addHeading(4)
case startsWith("### "):
addLine(fmt.Sprintf(
"<h3 id='%d'>%s</h3>", state.id, line[4:]))
addHeading(3)
case startsWith("## "):
addLine(fmt.Sprintf(
"<h2 id='%d'>%s</h2>", state.id, line[3:]))
addHeading(2)
case startsWith("# "):
addLine(fmt.Sprintf(
"<h1 id='%d'>%s</h1>", state.id, line[2:]))
addHeading(1)
case startsWith(">"):
addLine(fmt.Sprintf(

@ -1 +1 @@
Subproject commit d78a90718ae9c36f7a114901ddad84b0e23221b3
Subproject commit 8d595c930664f271e58d3cfb3fa12c6feabfec3c

View File

@ -1,19 +0,0 @@
package main
import (
"testing"
)
func TestMimeData(t *testing.T) {
check := func(ext string, expectedIsText bool, expectedMimeId int) {
isText, mimeId := mimeData(ext)
if isText != expectedIsText || mimeId != expectedMimeId {
t.Error(ext, isText, mimeId)
}
}
check(".txt", true, int(TextPlain))
check(".gmi", true, int(TextGemini))
check(".bin", false, int(BinaryOctet))
check(".jpg", false, int(BinaryJpeg))
check(".bin", false, int(BinaryOctet))
}