Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
dd837825
Commit
dd837825
authored
Dec 12, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add line break node
parent
aa3632e2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
0 deletions
+73
-0
block.go
plugin/gomark/ast/block.go
+14
-0
line_break.go
plugin/gomark/parser/line_break.go
+33
-0
parser.go
plugin/gomark/parser/parser.go
+2
-0
parser_test.go
plugin/gomark/parser/parser_test.go
+24
-0
No files found.
plugin/gomark/ast/block.go
View file @
dd837825
...
@@ -3,6 +3,20 @@ package ast
...
@@ -3,6 +3,20 @@ package ast
type
BaseBlock
struct
{
type
BaseBlock
struct
{
}
}
type
LineBreak
struct
{
BaseBlock
}
var
NodeTypeLineBreak
=
NewNodeType
(
"LineBreak"
)
func
NewLineBreak
()
*
LineBreak
{
return
&
LineBreak
{}
}
func
(
*
LineBreak
)
Type
()
NodeType
{
return
NodeTypeLineBreak
}
type
Paragraph
struct
{
type
Paragraph
struct
{
BaseBlock
BaseBlock
...
...
plugin/gomark/parser/line_break.go
0 → 100644
View file @
dd837825
package
parser
import
(
"github.com/usememos/memos/plugin/gomark/ast"
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
)
type
LineBreakParser
struct
{}
var
defaultLineBreakParser
=
&
LineBreakParser
{}
func
NewLineBreakParser
()
*
LineBreakParser
{
return
defaultLineBreakParser
}
func
(
*
LineBreakParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
int
,
bool
)
{
if
len
(
tokens
)
==
0
{
return
0
,
false
}
if
tokens
[
0
]
.
Type
!=
tokenizer
.
Newline
{
return
0
,
false
}
return
1
,
true
}
func
(
p
*
LineBreakParser
)
Parse
(
tokens
[]
*
tokenizer
.
Token
)
ast
.
Node
{
size
,
ok
:=
p
.
Match
(
tokens
)
if
size
==
0
||
!
ok
{
return
nil
}
return
ast
.
NewLineBreak
()
}
plugin/gomark/parser/parser.go
View file @
dd837825
...
@@ -26,7 +26,9 @@ type BlockParser interface {
...
@@ -26,7 +26,9 @@ type BlockParser interface {
func
Parse
(
tokens
[]
*
tokenizer
.
Token
)
[]
ast
.
Node
{
func
Parse
(
tokens
[]
*
tokenizer
.
Token
)
[]
ast
.
Node
{
nodes
:=
[]
ast
.
Node
{}
nodes
:=
[]
ast
.
Node
{}
blockParsers
:=
[]
BlockParser
{
blockParsers
:=
[]
BlockParser
{
NewCodeBlockParser
(),
NewParagraphParser
(),
NewParagraphParser
(),
NewLineBreakParser
(),
}
}
for
len
(
tokens
)
>
0
{
for
len
(
tokens
)
>
0
{
for
_
,
blockParser
:=
range
blockParsers
{
for
_
,
blockParser
:=
range
blockParsers
{
...
...
plugin/gomark/parser/parser_test.go
View file @
dd837825
...
@@ -61,6 +61,30 @@ func TestParser(t *testing.T) {
...
@@ -61,6 +61,30 @@ func TestParser(t *testing.T) {
},
},
},
},
},
},
{
text
:
"Hello **world**!
\n
```javascript
\n
console.log(
\"
Hello world!
\"
);
\n
```"
,
nodes
:
[]
ast
.
Node
{
&
ast
.
Paragraph
{
Children
:
[]
ast
.
Node
{
&
ast
.
Text
{
Content
:
"Hello "
,
},
&
ast
.
Bold
{
Symbol
:
"*"
,
Content
:
"world"
,
},
&
ast
.
Text
{
Content
:
"!"
,
},
},
},
&
ast
.
LineBreak
{},
&
ast
.
CodeBlock
{
Language
:
"javascript"
,
Content
:
"console.log(
\"
Hello world!
\"
);"
,
},
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment