mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: auto link converters
This commit is contained in:
@ -79,7 +79,7 @@ func convertFromASTNode(rawNode ast.Node) *apiv2pb.Node {
|
|||||||
case *ast.Link:
|
case *ast.Link:
|
||||||
node.Node = &apiv2pb.Node_LinkNode{LinkNode: &apiv2pb.LinkNode{Text: n.Text, Url: n.URL}}
|
node.Node = &apiv2pb.Node_LinkNode{LinkNode: &apiv2pb.LinkNode{Text: n.Text, Url: n.URL}}
|
||||||
case *ast.AutoLink:
|
case *ast.AutoLink:
|
||||||
node.Node = &apiv2pb.Node_AutoLinkNode{AutoLinkNode: &apiv2pb.AutoLinkNode{Url: n.URL}}
|
node.Node = &apiv2pb.Node_AutoLinkNode{AutoLinkNode: &apiv2pb.AutoLinkNode{Url: n.URL, IsRawText: n.IsRawText}}
|
||||||
case *ast.Tag:
|
case *ast.Tag:
|
||||||
node.Node = &apiv2pb.Node_TagNode{TagNode: &apiv2pb.TagNode{Content: n.Content}}
|
node.Node = &apiv2pb.Node_TagNode{TagNode: &apiv2pb.TagNode{Content: n.Content}}
|
||||||
case *ast.Strikethrough:
|
case *ast.Strikethrough:
|
||||||
@ -148,7 +148,7 @@ func convertToASTNode(node *apiv2pb.Node) ast.Node {
|
|||||||
case *apiv2pb.Node_LinkNode:
|
case *apiv2pb.Node_LinkNode:
|
||||||
return &ast.Link{Text: n.LinkNode.Text, URL: n.LinkNode.Url}
|
return &ast.Link{Text: n.LinkNode.Text, URL: n.LinkNode.Url}
|
||||||
case *apiv2pb.Node_AutoLinkNode:
|
case *apiv2pb.Node_AutoLinkNode:
|
||||||
return &ast.AutoLink{URL: n.AutoLinkNode.Url}
|
return &ast.AutoLink{URL: n.AutoLinkNode.Url, IsRawText: n.AutoLinkNode.IsRawText}
|
||||||
case *apiv2pb.Node_TagNode:
|
case *apiv2pb.Node_TagNode:
|
||||||
return &ast.Tag{Content: n.TagNode.Content}
|
return &ast.Tag{Content: n.TagNode.Content}
|
||||||
case *apiv2pb.Node_StrikethroughNode:
|
case *apiv2pb.Node_StrikethroughNode:
|
||||||
|
@ -58,9 +58,9 @@ func (p *AutoLinkParser) Parse(tokens []*tokenizer.Token) (ast.Node, error) {
|
|||||||
|
|
||||||
url := tokenizer.Stringify(tokens[:size])
|
url := tokenizer.Stringify(tokens[:size])
|
||||||
isRawText := true
|
isRawText := true
|
||||||
if tokens[0].Type == tokenizer.LessThan && tokens[len(tokens)-1].Type == tokenizer.GreaterThan {
|
if tokens[0].Type == tokenizer.LessThan && tokens[size-1].Type == tokenizer.GreaterThan {
|
||||||
isRawText = false
|
isRawText = false
|
||||||
url = tokenizer.Stringify(tokens[1 : len(tokens)-1])
|
url = tokenizer.Stringify(tokens[1 : size-1])
|
||||||
}
|
}
|
||||||
return &ast.AutoLink{
|
return &ast.AutoLink{
|
||||||
URL: url,
|
URL: url,
|
||||||
|
@ -156,6 +156,7 @@ message LinkNode {
|
|||||||
|
|
||||||
message AutoLinkNode {
|
message AutoLinkNode {
|
||||||
string url = 1;
|
string url = 1;
|
||||||
|
bool is_raw_text = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TagNode {
|
message TagNode {
|
||||||
|
@ -968,6 +968,7 @@
|
|||||||
| Field | Type | Label | Description |
|
| Field | Type | Label | Description |
|
||||||
| ----- | ---- | ----- | ----------- |
|
| ----- | ---- | ----- | ----------- |
|
||||||
| url | [string](#string) | | |
|
| url | [string](#string) | | |
|
||||||
|
| is_raw_text | [bool](#bool) | | |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1476,7 +1476,8 @@ type AutoLinkNode struct {
|
|||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
|
Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`
|
||||||
|
IsRawText bool `protobuf:"varint,2,opt,name=is_raw_text,json=isRawText,proto3" json:"is_raw_text,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *AutoLinkNode) Reset() {
|
func (x *AutoLinkNode) Reset() {
|
||||||
@ -1518,6 +1519,13 @@ func (x *AutoLinkNode) GetUrl() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *AutoLinkNode) GetIsRawText() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsRawText
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type TagNode struct {
|
type TagNode struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@ -1887,9 +1895,11 @@ var file_api_v2_markdown_service_proto_rawDesc = []byte{
|
|||||||
0x08, 0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78,
|
0x08, 0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, 0x78,
|
||||||
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x10, 0x0a,
|
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x10, 0x0a,
|
||||||
0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22,
|
0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22,
|
||||||
0x20, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x6f, 0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f, 0x64, 0x65, 0x12,
|
0x40, 0x0a, 0x0c, 0x41, 0x75, 0x74, 0x6f, 0x4c, 0x69, 0x6e, 0x6b, 0x4e, 0x6f, 0x64, 0x65, 0x12,
|
||||||
0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
|
0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72,
|
||||||
0x6c, 0x22, 0x23, 0x0a, 0x07, 0x54, 0x61, 0x67, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07,
|
0x6c, 0x12, 0x1e, 0x0a, 0x0b, 0x69, 0x73, 0x5f, 0x72, 0x61, 0x77, 0x5f, 0x74, 0x65, 0x78, 0x74,
|
||||||
|
0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x73, 0x52, 0x61, 0x77, 0x54, 0x65, 0x78,
|
||||||
|
0x74, 0x22, 0x23, 0x0a, 0x07, 0x54, 0x61, 0x67, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07,
|
||||||
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,
|
0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,
|
||||||
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x2d, 0x0a, 0x11, 0x53, 0x74, 0x72, 0x69, 0x6b, 0x65,
|
0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x2d, 0x0a, 0x11, 0x53, 0x74, 0x72, 0x69, 0x6b, 0x65,
|
||||||
0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63,
|
0x74, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63,
|
||||||
|
Reference in New Issue
Block a user