Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: update inline parser

Steven47af632c79ae
diff --git a/plugin/gomark/ast/inline.go b/plugin/gomark/ast/inline.go
index 6c4eb9112..8e82c54dc 100644
--- a/plugin/gomark/ast/inline.go
+++ b/plugin/gomark/ast/inline.go
@@ -18,8 +18,8 @@ type Bold struct {
BaseInline
// Symbol is "*" or "_".
- Symbol string
- Content string
+ Symbol string
+ Children []Node
}
func (*Bold) Type() NodeType {
diff --git a/plugin/gomark/parser/bold.go b/plugin/gomark/parser/bold.go
index f1c1603f8..c000631cf 100644
--- a/plugin/gomark/parser/bold.go
+++ b/plugin/gomark/parser/bold.go
@@ -53,8 +53,12 @@ func (p *BoldParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
prefixTokenType := tokens[0].Type
contentTokens := tokens[2 : size-2]
+ children, err := ParseInlineWithParsers(contentTokens, []InlineParser{NewLinkParser(), NewTextParser()})
+ if err != nil {
+ return nil, err
+ }
return &ast.Bold{
- Symbol: prefixTokenType,
- Content: tokenizer.Stringify(contentTokens),
+ Symbol: prefixTokenType,
+ Children: children,
}, nil
}
diff --git a/plugin/gomark/parser/bold_test.go b/plugin/gomark/parser/bold_test.go
index 9ab395b9e..418ce7190 100644
--- a/plugin/gomark/parser/bold_test.go
+++ b/plugin/gomark/parser/bold_test.go
@@ -21,15 +21,23 @@ func TestBoldParser(t *testing.T) {
{
text: "**Hello**",
bold: &ast.Bold{
- Symbol: "*",
- Content: "Hello",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "Hello",
+ },
+ },
},
},
{
text: "** Hello **",
bold: &ast.Bold{
- Symbol: "*",
- Content: " Hello ",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: " Hello ",
+ },
+ },
},
},
{
diff --git a/plugin/gomark/parser/heading_test.go b/plugin/gomark/parser/heading_test.go
index 47cee835c..43c48df7f 100644
--- a/plugin/gomark/parser/heading_test.go
+++ b/plugin/gomark/parser/heading_test.go
@@ -63,8 +63,12 @@ Hello World`,
Level: 3,
Children: []ast.Node{
&ast.Bold{
- Symbol: "*",
- Content: "Hello",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "Hello",
+ },
+ },
},
&ast.Text{
Content: " World",
diff --git a/plugin/gomark/parser/link_test.go b/plugin/gomark/parser/link_test.go
index 6b256406c..24287bdca 100644
--- a/plugin/gomark/parser/link_test.go
+++ b/plugin/gomark/parser/link_test.go
@@ -29,6 +29,13 @@ func TestLinkParser(t *testing.T) {
text: "[alte]( htt ps :/ /example.com)",
link: nil,
},
+ {
+ text: "[your/slash](https://example.com)",
+ link: &ast.Link{
+ Text: "your/slash",
+ URL: "https://example.com",
+ },
+ },
{
text: "[hello world](https://example.com)",
link: &ast.Link{
diff --git a/plugin/gomark/parser/parser.go b/plugin/gomark/parser/parser.go
index 9be62f5a5..a8b09d03f 100644
--- a/plugin/gomark/parser/parser.go
+++ b/plugin/gomark/parser/parser.go
@@ -76,10 +76,14 @@ var defaultInlineParsers = []InlineParser{
}
func ParseInline(tokens []*tokenizer.Token) ([]ast.Node, error) {
+ return ParseInlineWithParsers(tokens, defaultInlineParsers)
+}
+
+func ParseInlineWithParsers(tokens []*tokenizer.Token, inlineParsers []InlineParser) ([]ast.Node, error) {
nodes := []ast.Node{}
var prevNode ast.Node
for len(tokens) > 0 {
- for _, inlineParser := range defaultInlineParsers {
+ for _, inlineParser := range inlineParsers {
size, matched := inlineParser.Match(tokens)
if matched {
node, err := inlineParser.Parse(tokens)
diff --git a/plugin/gomark/parser/parser_test.go b/plugin/gomark/parser/parser_test.go
index 6d9086076..33e14ed29 100644
--- a/plugin/gomark/parser/parser_test.go
+++ b/plugin/gomark/parser/parser_test.go
@@ -32,8 +32,12 @@ func TestParser(t *testing.T) {
&ast.Paragraph{
Children: []ast.Node{
&ast.Bold{
- Symbol: "*",
- Content: "Hello",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "Hello",
+ },
+ },
},
&ast.Text{
Content: " world!",
@@ -51,8 +55,12 @@ func TestParser(t *testing.T) {
Content: "Hello ",
},
&ast.Bold{
- Symbol: "*",
- Content: "world",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "world",
+ },
+ },
},
&ast.Text{
Content: "!",
@@ -78,8 +86,12 @@ func TestParser(t *testing.T) {
Content: "Hello ",
},
&ast.Bold{
- Symbol: "*",
- Content: "world",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "world",
+ },
+ },
},
&ast.Text{
Content: "!",
@@ -150,7 +162,7 @@ func StringifyNode(node ast.Node) string {
case *ast.Text:
return "Text(" + n.Content + ")"
case *ast.Bold:
- return "Bold(" + n.Symbol + n.Content + n.Symbol + ")"
+ return "Bold(" + n.Symbol + StringifyNodes(n.Children) + n.Symbol + ")"
case *ast.Italic:
return "Italic(" + n.Symbol + n.Content + n.Symbol + ")"
case *ast.BoldItalic:
diff --git a/plugin/gomark/parser/unordered_list_test.go b/plugin/gomark/parser/unordered_list_test.go
index 982d58be7..e3a7174c6 100644
--- a/plugin/gomark/parser/unordered_list_test.go
+++ b/plugin/gomark/parser/unordered_list_test.go
@@ -35,8 +35,12 @@ func TestUnorderedListParser(t *testing.T) {
Symbol: tokenizer.Asterisk,
Children: []ast.Node{
&ast.Bold{
- Symbol: "*",
- Content: "Hello",
+ Symbol: "*",
+ Children: []ast.Node{
+ &ast.Text{
+ Content: "Hello",
+ },
+ },
},
},
},
diff --git a/plugin/gomark/render/html/html.go b/plugin/gomark/render/html/html.go
index e8f4235a3..47979ac69 100644
--- a/plugin/gomark/render/html/html.go
+++ b/plugin/gomark/render/html/html.go
@@ -149,7 +149,7 @@ func (r *HTMLRender) renderText(node *ast.Text) {
func (r *HTMLRender) renderBold(node *ast.Bold) {
r.output.WriteString("<strong>")
- r.output.WriteString(node.Content)
+ r.RenderNodes(node.Children)
r.output.WriteString("</strong>")
}
diff --git a/plugin/gomark/render/string/string.go b/plugin/gomark/render/string/string.go
index 72f817d2a..e4d65cbfd 100644
--- a/plugin/gomark/render/string/string.go
+++ b/plugin/gomark/render/string/string.go
@@ -134,7 +134,7 @@ func (r *StringRender) renderText(node *ast.Text) {
}
func (r *StringRender) renderBold(node *ast.Bold) {
- r.output.WriteString(node.Content)
+ r.RenderNodes(node.Children)
}
func (r *StringRender) renderItalic(node *ast.Italic) {
@@ -151,12 +151,12 @@ func (r *StringRender) renderCode(node *ast.Code) {
r.output.WriteString("`")
}
-func (*StringRender) renderImage(*ast.Image) {
- // Do nothing.
+func (r *StringRender) renderImage(node *ast.Image) {
+ r.output.WriteString(node.AltText)
}
-func (*StringRender) renderLink(*ast.Link) {
- // Do nothing.
+func (r *StringRender) renderLink(node *ast.Link) {
+ r.output.WriteString(node.Text)
}
func (r *StringRender) renderTag(node *ast.Tag) {
diff --git a/plugin/gomark/render/string/string_test.go b/plugin/gomark/render/string/string_test.go
index e80f8c63e..28971bbd8 100644
--- a/plugin/gomark/render/string/string_test.go
+++ b/plugin/gomark/render/string/string_test.go
@@ -22,6 +22,10 @@ func TestStringRender(t *testing.T) {
text: "**Hello** world!",
expected: `Hello world!`,
},
+ {
+ text: "**[your/slash](https://example.com)** world!",
+ expected: `your/slash world!`,
+ },
}
for _, test := range tests {
diff --git a/store/db/mysql/seed/10001__user.sql b/store/db/mysql/seed/10001__user.sql
deleted file mode 100644
index 4bd60e841..000000000
--- a/store/db/mysql/seed/10001__user.sql
+++ /dev/null
@@ -1,45 +0,0 @@
-INSERT INTO
- user (
- `id`,
- `username`,
- `role`,
- `email`,
- `nickname`,
- `row_status`,
- `avatar_url`,
- `password_hash`
- )
-VALUES
- (
- 101,
- 'memos-demo',
- 'HOST',
- 'Derobot',
- 'NORMAL',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- ),
- (
- 102,
- 'jack',
- 'USER',
- 'Jack',
- 'NORMAL',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- ),
- (
- 103,
- 'bob',
- 'USER',
- 'Bob',
- 'ARCHIVED',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- );
diff --git a/store/db/mysql/seed/10002__memo.sql b/store/db/mysql/seed/10002__memo.sql
deleted file mode 100644
index 3732babea..000000000
--- a/store/db/mysql/seed/10002__memo.sql
+++ /dev/null
@@ -1,51 +0,0 @@
-INSERT INTO
- memo (`id`, `content`, `creator_id`)
-VALUES
- (
- 1,
- "#Hello πŸ‘‹ Welcome to memos.",
- 101
- );
-
-INSERT INTO
- memo (
- `id`,
- `content`,
- `creator_id`,
- `visibility`
- )
-VALUES
- (
- 2,
- '#TODO
-- [x] Take more photos about **πŸŒ„ sunset**
-- [x] Clean the room
-- [ ] Read *πŸ“– The Little Prince*
-(πŸ‘† click to toggle status)',
- 101,
- 'PROTECTED'
- ),
- (
- 3,
- "**[Slash](https://github.com/yourselfhosted/slash)**: A bookmarking and url shortener, save and share your links very easily.
-**[SQL Chat](https://www.sqlchat.ai)**: Chat-based SQL Client",
- 101,
- 'PUBLIC'
- ),
- (
- 4,
- '#TODO
-- [x] Take more photos about **πŸŒ„ sunset**
-- [ ] Clean the classroom
-- [ ] Watch *πŸ‘¦ The Boys*
-(πŸ‘† click to toggle status)
-',
- 102,
- 'PROTECTED'
- ),
- (
- 5,
- 'δΈ‰δΊΊθ‘ŒοΌŒεΏ…ζœ‰ζˆ‘εΈˆη„‰οΌπŸ‘¨β€πŸ«',
- 102,
- 'PUBLIC'
- );
diff --git a/store/db/mysql/seed/10003__memo_organizer.sql b/store/db/mysql/seed/10003__memo_organizer.sql
deleted file mode 100644
index e1a2c4061..000000000
--- a/store/db/mysql/seed/10003__memo_organizer.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-INSERT INTO
- memo_organizer (`memo_id`, `user_id`, `pinned`)
-VALUES
- (1, 101, 1),
- (3, 101, 1);
diff --git a/store/db/mysql/seed/10004__tag.sql b/store/db/mysql/seed/10004__tag.sql
deleted file mode 100644
index 40a7c7748..000000000
--- a/store/db/mysql/seed/10004__tag.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-INSERT INTO
- tag (`name`, `creator_id`)
-VALUES
- ('Hello', 101),
- ('TODO', 101),
- ('TODO', 102);
diff --git a/store/db/postgres/seed/10001__user.sql b/store/db/postgres/seed/10001__user.sql
deleted file mode 100644
index 45f468d81..000000000
--- a/store/db/postgres/seed/10001__user.sql
+++ /dev/null
@@ -1,44 +0,0 @@
-INSERT INTO "user" (
- id,
- username,
- role,
- email,
- nickname,
- row_status,
- avatar_url,
- password_hash
-)
-VALUES
- (
- 101,
- 'memos-demo',
- 'HOST',
- 'Derobot',
- 'NORMAL',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- ),
- (
- 102,
- 'jack',
- 'USER',
- 'Jack',
- 'NORMAL',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- ),
- (
- 103,
- 'bob',
- 'USER',
- 'Bob',
- 'ARCHIVED',
- '',
- -- raw password: secret
- '$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK'
- );
diff --git a/store/db/postgres/seed/10002__memo.sql b/store/db/postgres/seed/10002__memo.sql
deleted file mode 100644
index 9c70e5c9d..000000000
--- a/store/db/postgres/seed/10002__memo.sql
+++ /dev/null
@@ -1,34 +0,0 @@
-INSERT INTO memo (id, content, creator_id)
-VALUES
- (
- 1,
- '#Hello πŸ‘‹ Welcome to memos.',
- 101
- );
-
-INSERT INTO memo (id, content, creator_id, visibility)
-VALUES
- (
- 2,
- E'#TODO\n- [x] Take more photos about **πŸŒ„ sunset**\n- [x] Clean the room\n- [ ] Read *πŸ“– The Little Prince*\n(πŸ‘† click to toggle status)',
- 101,
- 'PROTECTED'
- ),
- (
- 3,
- E'**[Slash](https://github.com/yourselfhosted/slash)**: A bookmarking and url shortener, save and share your links very easily.\n**[SQL Chat](https://www.sqlchat.ai)**: Chat-based SQL Client',
- 101,
- 'PUBLIC'
- ),
- (
- 4,
- E'#TODO\n- [x] Take more photos about **πŸŒ„ sunset**\n- [ ] Clean the classroom\n- [ ] Watch *πŸ‘¦ The Boys*\n(πŸ‘† click to toggle status)',
- 102,
- 'PROTECTED'
- ),
- (
- 5,
- 'δΈ‰δΊΊθ‘ŒοΌŒεΏ…ζœ‰ζˆ‘εΈˆη„‰οΌπŸ‘¨β€πŸ«',
- 102,
- 'PUBLIC'
- );
diff --git a/store/db/postgres/seed/10003__memo_organizer.sql b/store/db/postgres/seed/10003__memo_organizer.sql
deleted file mode 100644
index e1fd7b8db..000000000
--- a/store/db/postgres/seed/10003__memo_organizer.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-INSERT INTO
- memo_organizer (memo_id, user_id, pinned)
-VALUES
- (1, 101, 1),
- (3, 101, 1);
diff --git a/store/db/postgres/seed/10004__tag.sql b/store/db/postgres/seed/10004__tag.sql
deleted file mode 100644
index a679c1f6e..000000000
--- a/store/db/postgres/seed/10004__tag.sql
+++ /dev/null
@@ -1,6 +0,0 @@
-INSERT INTO
- tag (name, creator_id)
-VALUES
- ('Hello', 101),
- ('TODO', 101),
- ('TODO', 102);