Skip to content

Commit

Permalink
🐛 上下标无法解析 +- 问题 siyuan-note/siyuan#853
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Dec 30, 2020
1 parent 460780f commit e6e550d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
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.

18 changes: 14 additions & 4 deletions parse/delimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,16 @@ func (t *Tree) scanDelims(ctx *InlineContext) *delimiter {

afterIsWhitespace := lex.IsUnicodeWhitespace(tokenAfter)
afterIsPunct := unicode.IsPunct(tokenAfter) || unicode.IsSymbol(tokenAfter)
if (lex.ItemAsterisk == token && '~' == tokenAfter) || (lex.ItemTilde == token && '*' == tokenAfter) {
if (lex.ItemAsterisk == token && '~' == tokenAfter) || (lex.ItemTilde == token && '*' == tokenAfter) ||
(lex.ItemCaret == token && ('+' == tokenAfter || '-' == tokenAfter)) ||
(lex.ItemTilde == token && ('+' == tokenAfter || '-' == tokenAfter)) {
afterIsPunct = false
}
beforeIsWhitespace := lex.IsUnicodeWhitespace(tokenBefore)
beforeIsPunct := unicode.IsPunct(tokenBefore) || unicode.IsSymbol(tokenBefore)
if (lex.ItemAsterisk == token && '~' == tokenBefore) || (lex.ItemTilde == token && '*' == tokenBefore) {
if (lex.ItemAsterisk == token && '~' == tokenBefore) || (lex.ItemTilde == token && '*' == tokenBefore) ||
(lex.ItemCaret == token && ('+' == tokenBefore || '-' == tokenBefore)) ||
(lex.ItemTilde == token && ('+' == tokenBefore || '-' == tokenBefore)) {
beforeIsPunct = false
}

Expand All @@ -350,10 +354,16 @@ func (t *Tree) scanDelims(ctx *InlineContext) *delimiter {
canOpen = isLeftFlanking && (!isRightFlanking || beforeIsPunct)
canClose = isRightFlanking && (!isLeftFlanking || afterIsPunct)
} else {
if lex.ItemEqual == token && 2 != delimitersCount { // ==Mark== 标记使用两个等号
if t.Context.ParseOption.Mark && lex.ItemEqual == token && 2 != delimitersCount { // ==Mark== 标记使用两个等号
canOpen = false
canClose = false
} else if lex.ItemCrosshatch == token && 1 != delimitersCount { // #Tag# 标记使用一个井号
} else if t.Context.ParseOption.Tag && lex.ItemCrosshatch == token && 1 != delimitersCount { // #Tag# 标记使用一个井号
canOpen = false
canClose = false
} else if t.Context.ParseOption.Sup && lex.ItemCaret == token && 1 != delimitersCount { // ^Sup^ 标记使用一个 ^
canOpen = false
canClose = false
} else if t.Context.ParseOption.Sub && lex.ItemTilde == token && 1 != delimitersCount { // ~Sub~ 标记使用一个 ~
canOpen = false
canClose = false
} else {
Expand Down
5 changes: 5 additions & 0 deletions test/supsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (

var supsubTests = []parseTest{

{"9", "foo~-bar~baz", "<p>foo<sub>-bar</sub>baz</p>\n"},
{"8", "foo~-~", "<p>foo<sub>-</sub></p>\n"},
{"7", "foo~+~", "<p>foo<sub>+</sub></p>\n"},
{"6", "foo^-^", "<p>foo<sup>-</sup></p>\n"},
{"5", "foo^+^", "<p>foo<sup>+</sup></p>\n"},
{"4", "foo^b~ar^ba~z", "<p>foo<sup>b~ar</sup>ba~z</p>\n"},
{"3", "foo^barbaz", "<p>foo^barbaz</p>\n"},
{"2", "foo*^bar^*baz", "<p>foo*<sup>bar</sup>*baz</p>\n"},
Expand Down

0 comments on commit e6e550d

Please sign in to comment.