mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-07 10:20:26 +00:00
Replace old method with new that is a little overcomplicated
This commit is contained in:
parent
8dfd2fcf9b
commit
62c616985d
34
markup/hr.go
Normal file
34
markup/hr.go
Normal 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
|
||||||
|
}
|
@ -235,7 +235,7 @@ normalState:
|
|||||||
case startsWith("<="):
|
case startsWith("<="):
|
||||||
addParagraphIfNeeded()
|
addParagraphIfNeeded()
|
||||||
addLine(parseTransclusion(line, state.name))
|
addLine(parseTransclusion(line, state.name))
|
||||||
case line[:4] == "----":
|
case MatchesHorizontalLine(line):
|
||||||
addParagraphIfNeeded()
|
addParagraphIfNeeded()
|
||||||
*ast = append(*ast, Line{id: -1, contents: "<hr/>"})
|
*ast = append(*ast, Line{id: -1, contents: "<hr/>"})
|
||||||
case MatchesImg(line):
|
case MatchesImg(line):
|
||||||
|
Loading…
Reference in New Issue
Block a user