diff --git a/scanner/scanner.go b/scanner/scanner.go index 9151bb6..caa722c 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -121,6 +121,8 @@ func (s *Scanner) Parse() { tokenKind = UNDERSCORE case '*': tokenKind = STAR + case '?': + tokenKind = QUESTIONMARK case '\n': s.addToken(NEWLINE, "") s.advanceLine() @@ -145,7 +147,7 @@ func (s *Scanner) Parse() { out: for { switch s.curChar { - case '\n', '!', '#', '_', '*', '-', '[', ']', '(', ')', '`', '>': + case '\n', '!', '#', '_', '*', '-', '[', ']', '(', ')', '`', '>', '?': break out } @@ -155,6 +157,14 @@ func (s *Scanner) Parse() { // skip empty texts if res.Len() != 0 { + result := res.String() + if result[0] == 'i' && strings.HasPrefix(result, "include") { + split := strings.Split(result, " ") + if len(split) >= 2 { + s.addToken(INCLUDE, split[1]) + continue + } + } s.addToken(TEXT, res.String()) } // INFO: this skips adding the text again diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 2f62786..2681358 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -77,13 +77,22 @@ func TestHeadings(t *testing.T) { STRAIGHTBRACECLOSE, PARENOPEN, TEXT, + QUESTIONMARK, + TEXT, PARENCLOSE, NEWLINE, BACKTICK, TEXT, BACKTICK, NEWLINE, + QUESTIONMARK, + INCLUDE, + NEWLINE, + QUESTIONMARK, + TEXT, + NEWLINE, } + s.PrintTokens() if len(tokens) != len(expectedTokens) { t.Errorf("expected %d tokens, got: %d", len(expectedTokens), len(tokens)) } diff --git a/scanner/tests/markdown.md b/scanner/tests/markdown.md index f5bb327..22a6751 100644 --- a/scanner/tests/markdown.md +++ b/scanner/tests/markdown.md @@ -20,3 +20,6 @@ ![xnacly](https://avatars.githubusercontent.com/u/47723417?v=4) `inline code` + +?include test.md +?include diff --git a/scanner/tokens.go b/scanner/tokens.go index 6f4e28a..8c3134f 100644 --- a/scanner/tokens.go +++ b/scanner/tokens.go @@ -21,6 +21,8 @@ const ( BACKTICK GREATERTHAN BANG + QUESTIONMARK + INCLUDE ) var TOKEN_LOOKUP_MAP = map[uint]string{ @@ -35,6 +37,8 @@ var TOKEN_LOOKUP_MAP = map[uint]string{ PARENCLOSE: "PARENCLOSE", GREATERTHAN: "GREATERTHAN", BACKTICK: "BACKTICK", + QUESTIONMARK: "QUESTIONMARK", + INCLUDE: "INCLUDE", TEXT: "TEXT", BANG: "BANG", }