trying to handle escape characters now

main
Nick Dumas 1 year ago
parent 5e12c32fc5
commit b9049f340e

@ -36,6 +36,7 @@ const (
Alias = "|"
Heading = "#"
BlockRef = "#^"
EscapeChar = `\`
)
func Lex(name, input string, level zapcore.Level) *Lexer {

@ -9,7 +9,19 @@ import (
"code.ndumas.com/ndumas/obsidian-markdown"
)
var SingleWikilink = []tc{
var wikilinkWithEscapeCharacters = []tc{
{
name: "wikilink",
in: `[[wiki\]link]]`,
expected: []markdown.Lexeme{
{Typ: markdown.LexOpenLink, Val: "[["},
{Typ: markdown.LexIdent, Val: `wiki\]link`},
{Typ: markdown.LexCloseLink, Val: "]]"},
},
},
}
var singleWikilink = []tc{
{
name: "wikilink",
in: "[[wikilink]]",
@ -197,8 +209,25 @@ var SingleWikilink = []tc{
},
}
func Test_ObsidianWikilinks_LinksWithEscapeCharacters(t *testing.T) {
for _, tc := range wikilinkWithEscapeCharacters {
mut, test := mutateTestCase(
tc,
"",
"",
[]markdown.Lexeme{
{Typ: markdown.LexText, Val: ""},
},
[]markdown.Lexeme{
{Typ: markdown.LexText, Val: ""},
},
)
t.Run(mut.name, test)
}
}
func Test_ObsidianWikilinks_LinksEndOfMultiLineInput(t *testing.T) {
for _, tc := range SingleWikilink {
for _, tc := range singleWikilink {
mut, test := mutateTestCase(
tc,
" test data please ignore.\nbling blonk more lines\nbling blong\nthis is a",
@ -219,7 +248,7 @@ func Test_ObsidianWikilinks_LinksEndOfMultiLineInput(t *testing.T) {
}
func Test_ObsidianWikilinks_LinksStartOfMultiLineInput(t *testing.T) {
for _, tc := range SingleWikilink {
for _, tc := range singleWikilink {
mut, test := mutateTestCase(
tc,
"",
@ -240,7 +269,7 @@ func Test_ObsidianWikilinks_LinksStartOfMultiLineInput(t *testing.T) {
}
func Test_ObsidianWikilinks_LinksStartOfInput(t *testing.T) {
for _, tc := range SingleWikilink {
for _, tc := range singleWikilink {
mut, test := mutateTestCase(
tc,
"",
@ -258,7 +287,7 @@ func Test_ObsidianWikilinks_LinksStartOfInput(t *testing.T) {
}
func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
for _, tc := range SingleWikilink {
for _, tc := range singleWikilink {
mut, test := mutateTestCase(
tc,
"this is a ",
@ -276,7 +305,7 @@ func Test_ObsidianWikilinks_LinksEndOfInput(t *testing.T) {
func Test_ObsidianWikilinks_Basic(t *testing.T) {
for _, tc := range SingleWikilink {
for _, tc := range singleWikilink {
mut, test := mutateTestCase(
tc,
"",

@ -26,15 +26,19 @@ func isBlockRef(s string) bool {
return strings.HasPrefix(s, BlockRef)
}
func isEscape(s string) bool {
return strings.HasPrefix(s, EscapeChar)
}
func lexIdent(l *Lexer) stateFn {
for {
L := l.L.Named("lexIdent")
for {
s := l.input[l.GetPos():]
L.Debug("stepping through lexIdent")
if s[0] == '\\' { // i think this will handle escape characters?
break
}
switch {
case isEscape(s):
l.next()
continue
case isCloseLink(s):
L.Debug("found CloseLink")
l.emit(LexIdent)
@ -85,10 +89,17 @@ func lexAlias(l *Lexer) stateFn {
func lexText(l *Lexer) stateFn {
L := l.L.Named("lexText")
for {
if isOpenLink(l.input[l.GetPos():]) {
s := l.input[l.GetPos():]
L.Debug("stepping through lexText")
switch {
case isEscape(s):
l.next()
continue
case isOpenLink(s):
L.Debug("found openLink")
l.emit(LexText)
return lexOpenLink
}
r := l.next()
switch {

Loading…
Cancel
Save