Anchor inline regexps and improve sub/super-script
The regexps are meant to extract a match immediately following the cursor - the anchor should have been there from the beginning... Also empty sub/superscript doesn't make sense - nested sub/superscript does make sense but yagni.
This commit is contained in:
parent
ab9d87fbc8
commit
d1054063cf
4 changed files with 12 additions and 8 deletions
|
@ -35,13 +35,13 @@ type RegularLink struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var validURLCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;="
|
var validURLCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;="
|
||||||
var autolinkProtocols = regexp.MustCompile(`(https?|ftp|file)`)
|
var autolinkProtocols = regexp.MustCompile(`^(https?|ftp|file)$`)
|
||||||
var imageExtensionRegexp = regexp.MustCompile(`^[.](png|gif|jpe?g|svg|tiff?)$`)
|
var imageExtensionRegexp = regexp.MustCompile(`^[.](png|gif|jpe?g|svg|tiff?)$`)
|
||||||
var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
|
var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
|
||||||
|
|
||||||
var subScriptSuperScriptRegexp = regexp.MustCompile(`([_^])\{(.*?)\}`)
|
var subScriptSuperScriptRegexp = regexp.MustCompile(`^([_^]){([^{}]+?)}`)
|
||||||
var footnoteRegexp = regexp.MustCompile(`\[fn:([\w-]+?)(:(.*?))?\]`)
|
var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]+?)(:(.*?))?\]`)
|
||||||
var statisticsTokenRegexp = regexp.MustCompile(`\[(\d+/\d+|\d+%)\]`)
|
var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`)
|
||||||
|
|
||||||
func (d *Document) parseInline(input string) (nodes []Node) {
|
func (d *Document) parseInline(input string) (nodes []Node) {
|
||||||
previous, current := 0, 0
|
previous, current := 0, 0
|
||||||
|
@ -179,7 +179,11 @@ func (d *Document) parseAutoLink(input string, start int) (int, int, Node) {
|
||||||
return 0, 0, nil
|
return 0, 0, nil
|
||||||
}
|
}
|
||||||
protocolStart, protocol := start-1, ""
|
protocolStart, protocol := start-1, ""
|
||||||
for ; protocolStart > 0 && unicode.IsLetter(rune(input[protocolStart])); protocolStart-- {
|
for ; protocolStart > 0; protocolStart-- {
|
||||||
|
if !unicode.IsLetter(rune(input[protocolStart])) {
|
||||||
|
protocolStart++
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if m := autolinkProtocols.FindStringSubmatch(input[protocolStart:start]); m != nil {
|
if m := autolinkProtocols.FindStringSubmatch(input[protocolStart:start]); m != nil {
|
||||||
protocol = m[1]
|
protocol = m[1]
|
||||||
|
|
2
org/testdata/inline.html
vendored
2
org/testdata/inline.html
vendored
|
@ -61,7 +61,7 @@ empty emphasis markers like ++ // __ and so on are ignored
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<p>
|
<p>
|
||||||
subscript<sub>sub</sub> and superscript<sup>super</sup>
|
use _{} for subscript<sub>sub</sub> and ^{} for superscript<sup>super</sup>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
2
org/testdata/inline.org
vendored
2
org/testdata/inline.org
vendored
|
@ -17,7 +17,7 @@
|
||||||
is
|
is
|
||||||
not emphasized/
|
not emphasized/
|
||||||
- empty emphasis markers like ++ // __ and so on are ignored
|
- empty emphasis markers like ++ // __ and so on are ignored
|
||||||
- subscript_{sub} and superscript^{super}
|
- use _{} for subscript_{sub} and ^{} for superscript^{super}
|
||||||
- links
|
- links
|
||||||
1. regular link [[https://example.com]] link without description
|
1. regular link [[https://example.com]] link without description
|
||||||
2. regular link [[https://example.com][example.com]] link with description
|
2. regular link [[https://example.com][example.com]] link with description
|
||||||
|
|
2
org/testdata/inline.pretty_org
vendored
2
org/testdata/inline.pretty_org
vendored
|
@ -17,7 +17,7 @@
|
||||||
is
|
is
|
||||||
not emphasized/
|
not emphasized/
|
||||||
- empty emphasis markers like ++ // __ and so on are ignored
|
- empty emphasis markers like ++ // __ and so on are ignored
|
||||||
- subscript_{sub} and superscript^{super}
|
- use _{} for subscript_{sub} and ^{} for superscript^{super}
|
||||||
- links
|
- links
|
||||||
1. regular link [[https://example.com]] link without description
|
1. regular link [[https://example.com]] link without description
|
||||||
2. regular link [[https://example.com][example.com]] link with description
|
2. regular link [[https://example.com][example.com]] link with description
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue