Skip to content

Commit

Permalink
🔖 跟进 CommonMark 0.30 Fix #148
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jun 21, 2021
1 parent e9df32d commit d0befa5
Show file tree
Hide file tree
Showing 11 changed files with 4,454 additions and 4,307 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ require (
github.com/alecthomas/chroma v0.9.2
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c // indirect
github.com/gopherjs/gopherjs v0.0.0-20210614142143-03070f63dd63
github.com/gopherjs/gopherjs v0.0.0-20210619142842-05447a1fa367
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988 // indirect
golang.org/x/text v0.3.6
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20210614142143-03070f63dd63 h1:IxKfgP3jODaJyBERaZlpcoGLXjtH0tYsYdzIPzRxjN0=
github.com/gopherjs/gopherjs v0.0.0-20210614142143-03070f63dd63/go.mod h1:MtKwTfDNYAP5EtbQSMYjTSqvj1aXJKQRASWq3bwaP+g=
github.com/gopherjs/gopherjs v0.0.0-20210619142842-05447a1fa367 h1:7x3XlN7ZRUUHFybdLftf4ZFpi1JYR1w6WL7RPFlWqMM=
github.com/gopherjs/gopherjs v0.0.0-20210619142842-05447a1fa367/go.mod h1:MtKwTfDNYAP5EtbQSMYjTSqvj1aXJKQRASWq3bwaP+g=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
Expand Down Expand Up @@ -286,6 +286,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
2 changes: 1 addition & 1 deletion 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: 2 additions & 2 deletions parse/html_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (context *Context) htmlBlockFinalize(html *ast.Node) {
}

var (
htmlBlockTags1 = [][]byte{util.StrToBytes("<script"), util.StrToBytes("<pre"), util.StrToBytes("<style")}
htmlBlockCloseTags1 = [][]byte{util.StrToBytes("</script>"), util.StrToBytes("</pre>"), util.StrToBytes("</style>")}
htmlBlockTags1 = [][]byte{util.StrToBytes("<script"), util.StrToBytes("<pre"), util.StrToBytes("<style"), util.StrToBytes("<textarea")}
htmlBlockCloseTags1 = [][]byte{util.StrToBytes("</script>"), util.StrToBytes("</pre>"), util.StrToBytes("</style>"), util.StrToBytes("</textarea>")}
htmlBlockTags6 = [][]byte{
util.StrToBytes("<address"), util.StrToBytes("<article"), util.StrToBytes("<aside"), util.StrToBytes("<base"), util.StrToBytes("<basefont"), util.StrToBytes("<blockquote"), util.StrToBytes("<body"), util.StrToBytes("<caption"), util.StrToBytes("<center"), util.StrToBytes("<col"), util.StrToBytes("<colgroup"), util.StrToBytes("<dd"), util.StrToBytes("<details"), util.StrToBytes("<dialog"), util.StrToBytes("<dir"), util.StrToBytes("<div"), util.StrToBytes("<dl"), util.StrToBytes("<dt"), util.StrToBytes("<fieldset"), util.StrToBytes("<figcaption"), util.StrToBytes("<figure"), util.StrToBytes("<footer"), util.StrToBytes("<form"), util.StrToBytes("<frame"), util.StrToBytes("<frameset"), util.StrToBytes("<h1"), util.StrToBytes("<h2"), util.StrToBytes("<h3"), util.StrToBytes("<h4"), util.StrToBytes("<h5"), util.StrToBytes("<h6"), util.StrToBytes("<head"), util.StrToBytes("<header"), util.StrToBytes("<hr"), util.StrToBytes("<html"), util.StrToBytes("<iframe"), util.StrToBytes("<legend"), util.StrToBytes("<li"), util.StrToBytes("<link"), util.StrToBytes("<main"), util.StrToBytes("<menu"), util.StrToBytes("<menuitem"), util.StrToBytes("<nav"), util.StrToBytes("<noframes"), util.StrToBytes("<ol"), util.StrToBytes("<optgroup"), util.StrToBytes("<option"), util.StrToBytes("<p"), util.StrToBytes("<param"), util.StrToBytes("<section"), util.StrToBytes("<source"), util.StrToBytes("<summary"), util.StrToBytes("<table"), util.StrToBytes("<tbody"), util.StrToBytes("<td"), util.StrToBytes("<tfoot"), util.StrToBytes("<th"), util.StrToBytes("<thead"), util.StrToBytes("<title"), util.StrToBytes("<tr"), util.StrToBytes("<track"), util.StrToBytes("<ul"), util.StrToBytes("<video"), util.StrToBytes("<audio"),
util.StrToBytes("</address"), util.StrToBytes("</article"), util.StrToBytes("</aside"), util.StrToBytes("</base"), util.StrToBytes("</basefont"), util.StrToBytes("</blockquote"), util.StrToBytes("</body"), util.StrToBytes("</caption"), util.StrToBytes("</center"), util.StrToBytes("</col"), util.StrToBytes("</colgroup"), util.StrToBytes("</dd"), util.StrToBytes("</details"), util.StrToBytes("</dialog"), util.StrToBytes("</dir"), util.StrToBytes("</div"), util.StrToBytes("</dl"), util.StrToBytes("</dt"), util.StrToBytes("</fieldset"), util.StrToBytes("</figcaption"), util.StrToBytes("</figure"), util.StrToBytes("</footer"), util.StrToBytes("</form"), util.StrToBytes("</frame"), util.StrToBytes("</frameset"), util.StrToBytes("</h1"), util.StrToBytes("</h2"), util.StrToBytes("</h3"), util.StrToBytes("</h4"), util.StrToBytes("</h5"), util.StrToBytes("</h6"), util.StrToBytes("</head"), util.StrToBytes("</header"), util.StrToBytes("</hr"), util.StrToBytes("</html"), util.StrToBytes("</iframe"), util.StrToBytes("</legend"), util.StrToBytes("</li"), util.StrToBytes("</link"), util.StrToBytes("</main"), util.StrToBytes("</menu"), util.StrToBytes("</menuitem"), util.StrToBytes("</nav"), util.StrToBytes("</noframes"), util.StrToBytes("</ol"), util.StrToBytes("</optgroup"), util.StrToBytes("</option"), util.StrToBytes("</p"), util.StrToBytes("</param"), util.StrToBytes("</section"), util.StrToBytes("</source"), util.StrToBytes("</summary"), util.StrToBytes("</table"), util.StrToBytes("</tbody"), util.StrToBytes("</td"), util.StrToBytes("</tfoot"), util.StrToBytes("</th"), util.StrToBytes("</thead"), util.StrToBytes("</title"), util.StrToBytes("</tr"), util.StrToBytes("</track"), util.StrToBytes("</ul"), util.StrToBytes("</video"), util.StrToBytes("</audio"),
Expand Down
25 changes: 2 additions & 23 deletions parse/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
package parse

import (
"bytes"
"unicode/utf8"

"github.com/88250/lute/ast"
"github.com/88250/lute/html"
"github.com/88250/lute/lex"
"github.com/88250/lute/util"
"unicode/utf8"
)

func (context *Context) parseLinkRefDef(tokens []byte) []byte {
Expand Down Expand Up @@ -95,27 +95,6 @@ func (context *Context) parseLinkRefDef(tokens []byte) []byte {
return remains
}

func (t *Tree) FindLinkRefDefLink(label []byte) (link *ast.Node) {
if !t.Context.ParseOption.LinkRef {
return
}

if t.Context.ParseOption.VditorIR || t.Context.ParseOption.VditorSV || t.Context.ParseOption.VditorWYSIWYG || t.Context.ParseOption.ProtyleWYSIWYG {
label = bytes.ReplaceAll(label, util.CaretTokens, nil)
}
ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeLinkRefDef != n.Type {
return ast.WalkContinue
}
if bytes.EqualFold(n.Tokens, label) {
link = n.FirstChild
return ast.WalkStop
}
return ast.WalkContinue
})
return
}

func (context *Context) parseLinkTitle(tokens []byte) (validTitle bool, passed, remains, title []byte) {
if 1 > len(tokens) {
return true, nil, tokens, nil
Expand Down
47 changes: 47 additions & 0 deletions parse/linkrefdef_case_fold.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Lute - 一款结构化的 Markdown 引擎,支持 Go 和 JavaScript
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

// +build !javascript

package parse

import (
"bytes"

"github.com/88250/lute/ast"
"github.com/88250/lute/util"
"golang.org/x/text/cases"
)

func (t *Tree) FindLinkRefDefLink(label []byte) (link *ast.Node) {
if !t.Context.ParseOption.LinkRef {
return
}

if t.Context.ParseOption.VditorIR || t.Context.ParseOption.VditorSV || t.Context.ParseOption.VditorWYSIWYG || t.Context.ParseOption.ProtyleWYSIWYG {
label = bytes.ReplaceAll(label, util.CaretTokens, nil)
}
ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeLinkRefDef != n.Type {
return ast.WalkContinue
}
if bytes.EqualFold(n.Tokens, label) {
link = n.FirstChild
return ast.WalkStop
}

if c := cases.Fold(); bytes.EqualFold(c.Bytes(label), n.Tokens) || bytes.EqualFold(c.Bytes(n.Tokens), label) {
link = n.FirstChild
return ast.WalkStop
}
return ast.WalkContinue
})
return
}
43 changes: 43 additions & 0 deletions parse/linkrefdef_case_foldjs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Lute - 一款结构化的 Markdown 引擎,支持 Go 和 JavaScript
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

// +build javascript

package parse

import (
"bytes"

"github.com/88250/lute/ast"
"github.com/88250/lute/util"
)

func (t *Tree) FindLinkRefDefLink(label []byte) (link *ast.Node) {
if !t.Context.ParseOption.LinkRef {
return
}

if t.Context.ParseOption.VditorIR || t.Context.ParseOption.VditorSV || t.Context.ParseOption.VditorWYSIWYG || t.Context.ParseOption.ProtyleWYSIWYG {
label = bytes.ReplaceAll(label, util.CaretTokens, nil)
}
ast.Walk(t.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || ast.NodeLinkRefDef != n.Type {
return ast.WalkContinue
}
if bytes.EqualFold(n.Tokens, label) {
link = n.FirstChild
return ast.WalkStop
}
// JS 版不支持 Unicode case fold https://spec.commonmark.org/0.30/#example-539
// 因为引入 golang.org/x/text/cases 后打包体积太大
return ast.WalkContinue
})
return
}
Loading

0 comments on commit d0befa5

Please sign in to comment.