Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 10, 2020
1 parent 3aa3f21 commit 8121b78
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ func (n *Node) ChildrenByType(childType NodeType) (ret []*Node) {
// Text 返回 n 及其文本子节点的文本值。
func (n *Node) Text() (ret string) {
Walk(n, func(n *Node, entering bool) WalkStatus {
if (NodeText == n.Type || NodeLinkText == n.Type || NodeBlockRefText == n.Type || NodeBlockEmbedText == n.Type) && entering {
if !entering {
return WalkContinue
}
switch n.Type {
case NodeText, NodeLinkText, NodeBlockRefText, NodeBlockEmbedText, NodeFootnotesRef:
ret += util.BytesToStr(n.Tokens)
}
return WalkContinue
Expand Down
6 changes: 3 additions & 3 deletions javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions parse/footnotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package parse
import (
"bytes"
"github.com/88250/lute/ast"
"github.com/88250/lute/util"
)

func FootnotesContinue(footnotesDef *ast.Node, context *Context) int {
Expand All @@ -30,6 +31,9 @@ func FootnotesContinue(footnotesDef *ast.Node, context *Context) int {

func (t *Tree) FindFootnotesDef(label []byte) (pos int, def *ast.Node) {
pos = 0
if t.Context.Option.VditorIR || t.Context.Option.VditorSV || t.Context.Option.VditorWYSIWYG {
label = bytes.ReplaceAll(label, util.CaretTokens, nil)
}
ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeFootnotesDef != n.Type {
return ast.WalkContinue
Expand Down
2 changes: 1 addition & 1 deletion parse/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (t *Tree) parseCloseBracket(ctx *InlineContext) *ast.Node {
if 0 < refsLen {
refId += ":" + strconv.Itoa(refsLen+1)
}
ref := &ast.Node{Type: ast.NodeFootnotesRef, Tokens: reflabel, FootnotesRefId: refId, FootnotesRefLabel: reflabel}
ref := &ast.Node{Type: ast.NodeFootnotesRef, Tokens: reflabel, FootnotesRefId: refId, FootnotesRefLabel: bytes.ReplaceAll(reflabel, util.CaretTokens, nil)}
footnotesDef.FootnotesRefs = append(footnotesDef.FootnotesRefs, ref)
return ref
}
Expand Down
2 changes: 2 additions & 0 deletions test/spinv_ir_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

var spinVditorIRBlockDOMTests = []*parseTest{

{"62", "<p data-block=\"0\" data-node-id=\"20201110094505-32insti\" data-type=\"p\">foo<sup data-type=\"footnotes-ref\" class=\"vditor-ir__node b3-tooltips b3-tooltips__s\" aria-label=\"foo\" data-footnotes-label=\"^bar\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">^bar<wbr></span></sup>​</p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201110094515-09taip8\" data-type=\"p\">foo</p></div></div>", "<p data-block=\"0\" data-node-id=\"20201110094505-32insti\" data-type=\"p\">foo[^bar<wbr></p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201110094515-09taip8\" data-type=\"p\">foo</p></div></div>"},
{"61", "<p data-block=\"0\" data-node-id=\"20201110094505-32insti\" data-type=\"p\">foo[^bar<wbr>]</p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201110094515-09taip8\" data-type=\"p\">foo</p></div></div>", "<p data-block=\"0\" data-node-id=\"20201110094505-32insti\" data-type=\"p\">foo<sup data-type=\"footnotes-ref\" class=\"vditor-ir__node vditor-ir__node--expand b3-tooltips b3-tooltips__s\" aria-label=\"foo\" data-footnotes-label=\"^bar\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">^bar<wbr></span><span class=\"vditor-ir__marker--hide\" data-render=\"1\">1</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span></sup>\u200b</p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201110094515-09taip8\" data-type=\"p\">foo</p></div></div>"},
{"60", "<p data-block=\"0\" data-node-id=\"20201109231947-ql351ot\" data-type=\"p\"><span data-type=\"link-ref\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span>text</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">[foo]</span></span></p><div data-block=\"0\" data-type=\"link-ref-defs-block\"><span><span>[foo]: </span>bar\n</span></div><div data-block=\"0\" data-type=\"link-ref-defs-block\"><span><wbr><br></span></div>", "<p data-block=\"0\" data-node-id=\"20201109231947-ql351ot\" data-type=\"p\"><span data-type=\"link-ref\" class=\"vditor-ir__node\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span>text</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">[foo]</span></span></p><div data-block=\"0\" data-type=\"link-ref-defs-block\"><span><span>[foo]: </span>bar\n</span></div><p data-block=\"0\" data-node-id=\"20060102150405-1a2b3c4\" data-type=\"p\"><wbr></p>"},
{"59", "<p data-block=\"0\" data-node-id=\"20201108202934-60lz8qy\" data-type=\"p\">[^foo]<wbr></p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^foo]: </span><p data-block=\"0\" data-node-id=\"20201108213050-f6lbjws\" data-type=\"p\">foo</p></div><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201108204215-k4ua23v\" data-type=\"p\">bar</p></div></div>", "<p data-block=\"0\" data-node-id=\"20201108202934-60lz8qy\" data-type=\"p\">\u200b<sup data-type=\"footnotes-ref\" class=\"vditor-ir__node b3-tooltips b3-tooltips__s\" aria-label=\"foo\" data-footnotes-label=\"^foo\"><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">[</span><span class=\"vditor-ir__marker vditor-ir__marker--link\">^foo</span><span class=\"vditor-ir__marker--hide\" data-render=\"1\">1</span><span class=\"vditor-ir__marker vditor-ir__marker--bracket\">]</span></sup>\u200b<wbr></p><div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^foo]: </span><p data-block=\"0\" data-node-id=\"20201108213050-f6lbjws\" data-type=\"p\">foo</p></div><div data-type=\"footnotes-def\"><span>[^bar]: </span><p data-block=\"0\" data-node-id=\"20201108204215-k4ua23v\" data-type=\"p\">bar</p></div></div>"},
{"58", "<div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^fn]: </span><p data-block=\"0\" data-node-id=\"20201107230538-uemlzcf\" data-type=\"p\">​f<wbr></p></div></div>", "<div data-block=\"0\" data-type=\"footnotes-block\"><div data-type=\"footnotes-def\"><span>[^fn]: </span><p data-block=\"0\" data-node-id=\"20201107230538-uemlzcf\" data-type=\"p\">f<wbr></p></div></div>"},
Expand Down
12 changes: 9 additions & 3 deletions vditor_ir_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,15 @@ func (lute *Lute) genASTByVditorIRBlockDOM(n *html.Node, tree *parse.Tree) {

text := lute.domText(n)
if "footnotes-ref" == dataType {
node.Type = ast.NodeFootnotesRef
node.Tokens = []byte(text[1 : len(text)-1])
tree.Context.Tip.AppendChild(node)
if strings.HasPrefix(text, "[^") && strings.HasSuffix(text, "]") {
node.Type = ast.NodeFootnotesRef
node.Tokens = []byte(text[1 : len(text)-1])
tree.Context.Tip.AppendChild(node)
} else {
node.Type = ast.NodeText
node.Tokens = []byte(text)
tree.Context.Tip.AppendChild(node)
}
} else {
node.Type = ast.NodeInlineHTML
text := lute.domText(n)
Expand Down

0 comments on commit 8121b78

Please sign in to comment.