diff --git a/markup/lexer.go b/markup/lexer.go index cad18d7..cfa6f96 100644 --- a/markup/lexer.go +++ b/markup/lexer.go @@ -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("%s", 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( - "
%s
", state.id, line[7:])) + addHeading(6) case startsWith("##### "): - addLine(fmt.Sprintf( - "
%s
", state.id, line[6:])) + addHeading(5) case startsWith("#### "): - addLine(fmt.Sprintf( - "

%s

", state.id, line[5:])) + addHeading(4) case startsWith("### "): - addLine(fmt.Sprintf( - "

%s

", state.id, line[4:])) + addHeading(3) case startsWith("## "): - addLine(fmt.Sprintf( - "

%s

", state.id, line[3:])) + addHeading(2) case startsWith("# "): - addLine(fmt.Sprintf( - "

%s

", state.id, line[2:])) + addHeading(1) case startsWith(">"): addLine(fmt.Sprintf( diff --git a/metarrhiza b/metarrhiza index d78a907..8d595c9 160000 --- a/metarrhiza +++ b/metarrhiza @@ -1 +1 @@ -Subproject commit d78a90718ae9c36f7a114901ddad84b0e23221b3 +Subproject commit 8d595c930664f271e58d3cfb3fa12c6feabfec3c diff --git a/mime_test.go b/mime_test.go deleted file mode 100644 index 05b2d08..0000000 --- a/mime_test.go +++ /dev/null @@ -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)) -}