aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mardown/ast.go2
-rw-r--r--mardown/ast_paragraph.go3
-rw-r--r--mardown/lexer.go14
-rw-r--r--mardown/lexer_test.go6
4 files changed, 14 insertions, 11 deletions
diff --git a/mardown/ast.go b/mardown/ast.go
index 37d670d..3794ff1 100644
--- a/mardown/ast.go
+++ b/mardown/ast.go
@@ -90,7 +90,7 @@ func getBlock(lxs *lexers, newLine bool) (block, error) {
} else {
b, err = code(lxs)
}
- case lexerLiteral, lexerEscape, lexerModifier:
+ case lexerLiteral, lexerModifier:
b, err = paragraph(lxs, false)
case lexerBreak: // do nothing
default:
diff --git a/mardown/ast_paragraph.go b/mardown/ast_paragraph.go
index 2e8895d..ee71794 100644
--- a/mardown/ast_paragraph.go
+++ b/mardown/ast_paragraph.go
@@ -64,9 +64,6 @@ func paragraph(lxs *lexers, oneLine bool) (*astParagraph, error) {
return nil, err
}
tree.content = append(tree.content, mod)
- case lexerEscape:
- n = 0
- //TODO: handle
case lexerExternal:
n = 0
if lxs.Current().Value == "!" {
diff --git a/mardown/lexer.go b/mardown/lexer.go
index c056460..64fa78b 100644
--- a/mardown/lexer.go
+++ b/mardown/lexer.go
@@ -7,8 +7,6 @@ type lexerType string
const (
lexerBreak lexerType = "break"
- lexerEscape lexerType = "escape"
-
lexerModifier lexerType = "modifier"
lexerCode lexerType = "code"
@@ -75,7 +73,17 @@ func lex(s string) *lexers {
currentType = t
previous += string(c)
}
+ literalNext := false
for _, c := range []rune(s) {
+ if literalNext {
+ fn(c, lexerLiteral)
+ literalNext = false
+ continue
+ }
+ if c == '\\' {
+ literalNext = true
+ continue
+ }
switch c {
case '*', '_':
if (currentType != lexerModifier && len(previous) > 0) ||
@@ -96,8 +104,6 @@ func lex(s string) *lexers {
fn(c, lexerQuote)
case '[', ']', '(', ')', '!':
fn(c, lexerExternal)
- case '\\':
- fn(c, lexerEscape)
case '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.':
fn(c, lexerList)
default:
diff --git a/mardown/lexer_test.go b/mardown/lexer_test.go
index f6a06d5..c9ec349 100644
--- a/mardown/lexer_test.go
+++ b/mardown/lexer_test.go
@@ -15,12 +15,12 @@ func TestLex(t *testing.T) {
if lxs.String() != "Lexers[header(#) literal( bonjour les gens) break(\n) literal(Comment ça va ?) ]" {
t.Errorf("invalid lex, got %s", lxs)
}
- lxs = lex("**hey**, what's up?")
- if lxs.String() != "Lexers[modifier(**) literal(hey) modifier(**) literal(, what's up?) ]" {
+ lxs = lex("***hey***, what's up?")
+ if lxs.String() != "Lexers[modifier(**) modifier(*) literal(hey) modifier(*) modifier(**) literal(, what's up?) ]" {
t.Errorf("invalid lex, got %s", lxs)
}
lxs = lex(`Xxx\_DarkEmperor\_xxX`)
- if lxs.String() != `Lexers[literal(Xxx) escape(\) modifier(_) literal(DarkEmperor) escape(\) modifier(_) literal(xxX) ]` {
+ if lxs.String() != `Lexers[literal(Xxx_DarkEmperor_xxX) ]` {
t.Errorf("invalid lex, got %s", lxs)
}
}