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

Merge pull request #34 from hugmouse/0.13

Fix lexer for "----" (<hr/>) case
This commit is contained in:
Timur Ismagilov 2021-03-05 13:53:27 +05:00 committed by GitHub
commit b45be35247
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

34
markup/hr.go Normal file
View File

@ -0,0 +1,34 @@
package markup
import (
"unicode"
)
// MatchesHorizontalLine checks if the string can be interpreted as suitable for rendering as <hr/>.
//
// The rule is: if there are more than 4 characters "-" in the string, then make it a horizontal line.
// Otherwise it is a paragraph (<p>).
func MatchesHorizontalLine(line string) bool {
counter := 0
// Check initially that the symbol is "-". If it is not a "-", it is most likely a space or another character.
// With unicode.IsLetter() we can separate spaces and characters.
for _, ch := range line {
if ch == '-' {
counter++
continue
}
// If we bump into any other character (letter) in the line, it is immediately an incorrect horizontal line.
// There is no point in counting further, we end the loop.
if unicode.IsLetter(ch) {
counter = 0
break
}
}
if counter >= 4 {
return true
}
return false
}

View File

@ -238,7 +238,7 @@ normalState:
case startsWith("<="):
addParagraphIfNeeded()
addLine(parseTransclusion(line, state.name))
case line == "----":
case MatchesHorizontalLine(line):
addParagraphIfNeeded()
*ast = append(*ast, Line{id: -1, contents: "<hr/>"})
case MatchesImg(line):