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
309fab22
Commit
309fab22
authored
Jan 27, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: implement nested blockquote
parent
1dc4f02b
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
76 additions
and
36 deletions
+76
-36
blockquote.go
plugin/gomark/parser/blockquote.go
+27
-14
blockquote_test.go
plugin/gomark/parser/blockquote_test.go
+33
-1
bold.go
plugin/gomark/parser/bold.go
+1
-1
bold_italic.go
plugin/gomark/parser/bold_italic.go
+1
-1
code_block.go
plugin/gomark/parser/code_block.go
+2
-2
escaping_character.go
plugin/gomark/parser/escaping_character.go
+1
-1
horizontal_rule.go
plugin/gomark/parser/horizontal_rule.go
+1
-1
line_break.go
plugin/gomark/parser/line_break.go
+1
-1
math_block.go
plugin/gomark/parser/math_block.go
+2
-2
table.go
plugin/gomark/parser/table.go
+1
-1
tokenizer.go
plugin/gomark/parser/tokenizer/tokenizer.go
+3
-3
tokenizer_test.go
plugin/gomark/parser/tokenizer/tokenizer_test.go
+1
-1
html.go
plugin/gomark/renderer/html/html.go
+2
-7
No files found.
plugin/gomark/parser/blockquote.go
View file @
309fab22
...
@@ -12,25 +12,38 @@ func NewBlockquoteParser() *BlockquoteParser {
...
@@ -12,25 +12,38 @@ func NewBlockquoteParser() *BlockquoteParser {
}
}
func
(
*
BlockquoteParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
func
(
*
BlockquoteParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
matchedTokens
:=
tokenizer
.
GetFirstLine
(
tokens
)
rows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
NewLine
)
if
len
(
matchedTokens
)
<
3
{
contentRows
:=
[][]
*
tokenizer
.
Token
{}
return
nil
,
0
for
_
,
row
:=
range
rows
{
if
len
(
row
)
<
3
||
row
[
0
]
.
Type
!=
tokenizer
.
GreaterThan
||
row
[
1
]
.
Type
!=
tokenizer
.
Space
{
break
}
contentRows
=
append
(
contentRows
,
row
)
}
}
if
matchedTokens
[
0
]
.
Type
!=
tokenizer
.
GreaterThan
||
matchedTokens
[
1
]
.
Type
!=
tokenizer
.
Space
{
if
len
(
contentRows
)
==
0
{
return
nil
,
0
return
nil
,
0
}
}
contentTokens
:=
matchedTokens
[
2
:
]
children
:=
[]
ast
.
Node
{}
children
,
err
:=
ParseInlineWithParsers
(
contentTokens
,
[]
InlineParser
{
NewLinkParser
(),
NewTextParser
()})
size
:=
0
for
index
,
row
:=
range
contentRows
{
contentTokens
:=
row
[
2
:
]
nodes
,
err
:=
ParseBlockWithParsers
(
contentTokens
,
[]
BlockParser
{
NewBlockquoteParser
(),
NewParagraphParser
()})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
return
nil
,
0
}
}
if
len
(
nodes
)
!=
1
{
return
nil
,
0
}
children
=
append
(
children
,
nodes
[
0
])
size
+=
len
(
row
)
if
index
!=
len
(
contentRows
)
-
1
{
size
+=
1
// NewLine.
}
}
return
&
ast
.
Blockquote
{
return
&
ast
.
Blockquote
{
Children
:
[]
ast
.
Node
{
&
ast
.
Paragraph
{
Children
:
children
,
Children
:
children
,
},
},
size
},
},
len
(
matchedTokens
)
}
}
plugin/gomark/parser/blockquote_test.go
View file @
309fab22
...
@@ -48,7 +48,7 @@ func TestBlockquoteParser(t *testing.T) {
...
@@ -48,7 +48,7 @@ func TestBlockquoteParser(t *testing.T) {
},
},
},
},
{
{
text
:
"> Hello
\n
world"
,
text
:
"> Hello
\n
>
world"
,
blockquote
:
&
ast
.
Blockquote
{
blockquote
:
&
ast
.
Blockquote
{
Children
:
[]
ast
.
Node
{
Children
:
[]
ast
.
Node
{
&
ast
.
Paragraph
{
&
ast
.
Paragraph
{
...
@@ -58,6 +58,38 @@ func TestBlockquoteParser(t *testing.T) {
...
@@ -58,6 +58,38 @@ func TestBlockquoteParser(t *testing.T) {
},
},
},
},
},
},
&
ast
.
Paragraph
{
Children
:
[]
ast
.
Node
{
&
ast
.
Text
{
Content
:
"world"
,
},
},
},
},
},
},
{
text
:
"> Hello
\n
> > world"
,
blockquote
:
&
ast
.
Blockquote
{
Children
:
[]
ast
.
Node
{
&
ast
.
Paragraph
{
Children
:
[]
ast
.
Node
{
&
ast
.
Text
{
Content
:
"Hello"
,
},
},
},
&
ast
.
Blockquote
{
Children
:
[]
ast
.
Node
{
&
ast
.
Paragraph
{
Children
:
[]
ast
.
Node
{
&
ast
.
Text
{
Content
:
"world"
,
},
},
},
},
},
},
},
},
},
},
},
...
...
plugin/gomark/parser/bold.go
View file @
309fab22
...
@@ -29,7 +29,7 @@ func (*BoldParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -29,7 +29,7 @@ func (*BoldParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
cursor
,
matched
:=
2
,
false
cursor
,
matched
:=
2
,
false
for
;
cursor
<
len
(
matchedTokens
)
-
1
;
cursor
++
{
for
;
cursor
<
len
(
matchedTokens
)
-
1
;
cursor
++
{
token
,
nextToken
:=
matchedTokens
[
cursor
],
matchedTokens
[
cursor
+
1
]
token
,
nextToken
:=
matchedTokens
[
cursor
],
matchedTokens
[
cursor
+
1
]
if
token
.
Type
==
tokenizer
.
New
line
||
nextToken
.
Type
==
tokenizer
.
Newl
ine
{
if
token
.
Type
==
tokenizer
.
New
Line
||
nextToken
.
Type
==
tokenizer
.
NewL
ine
{
return
nil
,
0
return
nil
,
0
}
}
if
token
.
Type
==
prefixTokenType
&&
nextToken
.
Type
==
prefixTokenType
{
if
token
.
Type
==
prefixTokenType
&&
nextToken
.
Type
==
prefixTokenType
{
...
...
plugin/gomark/parser/bold_italic.go
View file @
309fab22
...
@@ -28,7 +28,7 @@ func (*BoldItalicParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -28,7 +28,7 @@ func (*BoldItalicParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
cursor
,
matched
:=
3
,
false
cursor
,
matched
:=
3
,
false
for
;
cursor
<
len
(
matchedTokens
)
-
2
;
cursor
++
{
for
;
cursor
<
len
(
matchedTokens
)
-
2
;
cursor
++
{
token
,
nextToken
,
endToken
:=
matchedTokens
[
cursor
],
matchedTokens
[
cursor
+
1
],
matchedTokens
[
cursor
+
2
]
token
,
nextToken
,
endToken
:=
matchedTokens
[
cursor
],
matchedTokens
[
cursor
+
1
],
matchedTokens
[
cursor
+
2
]
if
token
.
Type
==
tokenizer
.
New
line
||
nextToken
.
Type
==
tokenizer
.
Newline
||
endToken
.
Type
==
tokenizer
.
Newl
ine
{
if
token
.
Type
==
tokenizer
.
New
Line
||
nextToken
.
Type
==
tokenizer
.
NewLine
||
endToken
.
Type
==
tokenizer
.
NewL
ine
{
return
nil
,
0
return
nil
,
0
}
}
if
token
.
Type
==
prefixTokenType
&&
nextToken
.
Type
==
prefixTokenType
&&
endToken
.
Type
==
prefixTokenType
{
if
token
.
Type
==
prefixTokenType
&&
nextToken
.
Type
==
prefixTokenType
&&
endToken
.
Type
==
prefixTokenType
{
...
...
plugin/gomark/parser/code_block.go
View file @
309fab22
...
@@ -17,7 +17,7 @@ func NewCodeBlockParser() *CodeBlockParser {
...
@@ -17,7 +17,7 @@ func NewCodeBlockParser() *CodeBlockParser {
}
}
func
(
*
CodeBlockParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
func
(
*
CodeBlockParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
rows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
l
ine
)
rows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
L
ine
)
if
len
(
rows
)
<
3
{
if
len
(
rows
)
<
3
{
return
nil
,
0
return
nil
,
0
}
}
...
@@ -59,7 +59,7 @@ func (*CodeBlockParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -59,7 +59,7 @@ func (*CodeBlockParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
contentTokens
=
append
(
contentTokens
,
row
...
)
contentTokens
=
append
(
contentTokens
,
row
...
)
if
index
!=
len
(
contentRows
)
-
1
{
if
index
!=
len
(
contentRows
)
-
1
{
contentTokens
=
append
(
contentTokens
,
&
tokenizer
.
Token
{
contentTokens
=
append
(
contentTokens
,
&
tokenizer
.
Token
{
Type
:
tokenizer
.
New
l
ine
,
Type
:
tokenizer
.
New
L
ine
,
Value
:
"
\n
"
,
Value
:
"
\n
"
,
})
})
}
}
...
...
plugin/gomark/parser/escaping_character.go
View file @
309fab22
...
@@ -18,7 +18,7 @@ func (*EscapingCharacterParser) Match(tokens []*tokenizer.Token) (ast.Node, int)
...
@@ -18,7 +18,7 @@ func (*EscapingCharacterParser) Match(tokens []*tokenizer.Token) (ast.Node, int)
if
tokens
[
0
]
.
Type
!=
tokenizer
.
Backslash
{
if
tokens
[
0
]
.
Type
!=
tokenizer
.
Backslash
{
return
nil
,
0
return
nil
,
0
}
}
if
tokens
[
1
]
.
Type
==
tokenizer
.
New
l
ine
||
tokens
[
1
]
.
Type
==
tokenizer
.
Space
||
tokens
[
1
]
.
Type
==
tokenizer
.
Text
||
tokens
[
1
]
.
Type
==
tokenizer
.
Number
{
if
tokens
[
1
]
.
Type
==
tokenizer
.
New
L
ine
||
tokens
[
1
]
.
Type
==
tokenizer
.
Space
||
tokens
[
1
]
.
Type
==
tokenizer
.
Text
||
tokens
[
1
]
.
Type
==
tokenizer
.
Number
{
return
nil
,
0
return
nil
,
0
}
}
return
&
ast
.
EscapingCharacter
{
return
&
ast
.
EscapingCharacter
{
...
...
plugin/gomark/parser/horizontal_rule.go
View file @
309fab22
...
@@ -16,7 +16,7 @@ func (*HorizontalRuleParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -16,7 +16,7 @@ func (*HorizontalRuleParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
if
len
(
matchedTokens
)
<
3
{
if
len
(
matchedTokens
)
<
3
{
return
nil
,
0
return
nil
,
0
}
}
if
len
(
matchedTokens
)
>
3
&&
matchedTokens
[
3
]
.
Type
!=
tokenizer
.
New
l
ine
{
if
len
(
matchedTokens
)
>
3
&&
matchedTokens
[
3
]
.
Type
!=
tokenizer
.
New
L
ine
{
return
nil
,
0
return
nil
,
0
}
}
if
matchedTokens
[
0
]
.
Type
!=
matchedTokens
[
1
]
.
Type
||
matchedTokens
[
0
]
.
Type
!=
matchedTokens
[
2
]
.
Type
||
matchedTokens
[
1
]
.
Type
!=
matchedTokens
[
2
]
.
Type
{
if
matchedTokens
[
0
]
.
Type
!=
matchedTokens
[
1
]
.
Type
||
matchedTokens
[
0
]
.
Type
!=
matchedTokens
[
2
]
.
Type
||
matchedTokens
[
1
]
.
Type
!=
matchedTokens
[
2
]
.
Type
{
...
...
plugin/gomark/parser/line_break.go
View file @
309fab22
...
@@ -15,7 +15,7 @@ func (*LineBreakParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -15,7 +15,7 @@ func (*LineBreakParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
if
len
(
tokens
)
==
0
{
if
len
(
tokens
)
==
0
{
return
nil
,
0
return
nil
,
0
}
}
if
tokens
[
0
]
.
Type
!=
tokenizer
.
New
l
ine
{
if
tokens
[
0
]
.
Type
!=
tokenizer
.
New
L
ine
{
return
nil
,
0
return
nil
,
0
}
}
return
&
ast
.
LineBreak
{},
1
return
&
ast
.
LineBreak
{},
1
...
...
plugin/gomark/parser/math_block.go
View file @
309fab22
...
@@ -12,7 +12,7 @@ func NewMathBlockParser() *MathBlockParser {
...
@@ -12,7 +12,7 @@ func NewMathBlockParser() *MathBlockParser {
}
}
func
(
*
MathBlockParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
func
(
*
MathBlockParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
rows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
l
ine
)
rows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
L
ine
)
if
len
(
rows
)
<
3
{
if
len
(
rows
)
<
3
{
return
nil
,
0
return
nil
,
0
}
}
...
@@ -42,7 +42,7 @@ func (*MathBlockParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
...
@@ -42,7 +42,7 @@ func (*MathBlockParser) Match(tokens []*tokenizer.Token) (ast.Node, int) {
contentTokens
=
append
(
contentTokens
,
row
...
)
contentTokens
=
append
(
contentTokens
,
row
...
)
if
index
!=
len
(
contentRows
)
-
1
{
if
index
!=
len
(
contentRows
)
-
1
{
contentTokens
=
append
(
contentTokens
,
&
tokenizer
.
Token
{
contentTokens
=
append
(
contentTokens
,
&
tokenizer
.
Token
{
Type
:
tokenizer
.
New
l
ine
,
Type
:
tokenizer
.
New
L
ine
,
Value
:
"
\n
"
,
Value
:
"
\n
"
,
})
})
}
}
...
...
plugin/gomark/parser/table.go
View file @
309fab22
...
@@ -12,7 +12,7 @@ func NewTableParser() *TableParser {
...
@@ -12,7 +12,7 @@ func NewTableParser() *TableParser {
}
}
func
(
*
TableParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
func
(
*
TableParser
)
Match
(
tokens
[]
*
tokenizer
.
Token
)
(
ast
.
Node
,
int
)
{
rawRows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
l
ine
)
rawRows
:=
tokenizer
.
Split
(
tokens
,
tokenizer
.
New
L
ine
)
if
len
(
rawRows
)
<
3
{
if
len
(
rawRows
)
<
3
{
return
nil
,
0
return
nil
,
0
}
}
...
...
plugin/gomark/parser/tokenizer/tokenizer.go
View file @
309fab22
...
@@ -26,7 +26,7 @@ const (
...
@@ -26,7 +26,7 @@ const (
Colon
TokenType
=
":"
Colon
TokenType
=
":"
Caret
TokenType
=
"^"
Caret
TokenType
=
"^"
Backslash
TokenType
=
"
\\
"
Backslash
TokenType
=
"
\\
"
New
l
ine
TokenType
=
"
\n
"
New
L
ine
TokenType
=
"
\n
"
Space
TokenType
=
" "
Space
TokenType
=
" "
)
)
...
@@ -97,7 +97,7 @@ func Tokenize(text string) []*Token {
...
@@ -97,7 +97,7 @@ func Tokenize(text string) []*Token {
case
'\\'
:
case
'\\'
:
tokens
=
append
(
tokens
,
NewToken
(
Backslash
,
`\`
))
tokens
=
append
(
tokens
,
NewToken
(
Backslash
,
`\`
))
case
'\n'
:
case
'\n'
:
tokens
=
append
(
tokens
,
NewToken
(
New
l
ine
,
"
\n
"
))
tokens
=
append
(
tokens
,
NewToken
(
New
L
ine
,
"
\n
"
))
case
' '
:
case
' '
:
tokens
=
append
(
tokens
,
NewToken
(
Space
,
" "
))
tokens
=
append
(
tokens
,
NewToken
(
Space
,
" "
))
default
:
default
:
...
@@ -175,7 +175,7 @@ func FindUnescaped(tokens []*Token, target TokenType) int {
...
@@ -175,7 +175,7 @@ func FindUnescaped(tokens []*Token, target TokenType) int {
func
GetFirstLine
(
tokens
[]
*
Token
)
[]
*
Token
{
func
GetFirstLine
(
tokens
[]
*
Token
)
[]
*
Token
{
for
i
,
token
:=
range
tokens
{
for
i
,
token
:=
range
tokens
{
if
token
.
Type
==
New
l
ine
{
if
token
.
Type
==
New
L
ine
{
return
tokens
[
:
i
]
return
tokens
[
:
i
]
}
}
}
}
...
...
plugin/gomark/parser/tokenizer/tokenizer_test.go
View file @
309fab22
...
@@ -57,7 +57,7 @@ func TestTokenize(t *testing.T) {
...
@@ -57,7 +57,7 @@ func TestTokenize(t *testing.T) {
Value
:
" "
,
Value
:
" "
,
},
},
{
{
Type
:
New
l
ine
,
Type
:
New
L
ine
,
Value
:
"
\n
"
,
Value
:
"
\n
"
,
},
},
{
{
...
...
plugin/gomark/renderer/html/html.go
View file @
309fab22
...
@@ -122,14 +122,9 @@ func (r *HTMLRenderer) renderHorizontalRule(_ *ast.HorizontalRule) {
...
@@ -122,14 +122,9 @@ func (r *HTMLRenderer) renderHorizontalRule(_ *ast.HorizontalRule) {
}
}
func
(
r
*
HTMLRenderer
)
renderBlockquote
(
node
*
ast
.
Blockquote
)
{
func
(
r
*
HTMLRenderer
)
renderBlockquote
(
node
*
ast
.
Blockquote
)
{
prevSibling
,
nextSibling
:=
ast
.
FindPrevSiblingExceptLineBreak
(
node
),
ast
.
FindNextSiblingExceptLineBreak
(
node
)
if
prevSibling
==
nil
||
prevSibling
.
Type
()
!=
ast
.
BlockquoteNode
{
r
.
output
.
WriteString
(
"<blockquote>"
)
r
.
output
.
WriteString
(
"<blockquote>"
)
}
r
.
RenderNodes
(
node
.
Children
)
r
.
RenderNodes
(
node
.
Children
)
if
nextSibling
==
nil
||
nextSibling
.
Type
()
!=
ast
.
BlockquoteNode
{
r
.
output
.
WriteString
(
"</blockquote>"
)
r
.
output
.
WriteString
(
"</blockquote>"
)
}
}
}
func
(
r
*
HTMLRenderer
)
renderTaskList
(
node
*
ast
.
TaskList
)
{
func
(
r
*
HTMLRenderer
)
renderTaskList
(
node
*
ast
.
TaskList
)
{
...
...
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