diff --git a/org/inline.go b/org/inline.go index a678072..fcab00d 100644 --- a/org/inline.go +++ b/org/inline.go @@ -35,13 +35,13 @@ type RegularLink struct { } 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 videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`) -var subScriptSuperScriptRegexp = regexp.MustCompile(`([_^])\{(.*?)\}`) -var footnoteRegexp = regexp.MustCompile(`\[fn:([\w-]+?)(:(.*?))?\]`) -var statisticsTokenRegexp = regexp.MustCompile(`\[(\d+/\d+|\d+%)\]`) +var subScriptSuperScriptRegexp = regexp.MustCompile(`^([_^]){([^{}]+?)}`) +var footnoteRegexp = regexp.MustCompile(`^\[fn:([\w-]+?)(:(.*?))?\]`) +var statisticsTokenRegexp = regexp.MustCompile(`^\[(\d+/\d+|\d+%)\]`) func (d *Document) parseInline(input string) (nodes []Node) { previous, current := 0, 0 @@ -179,7 +179,11 @@ func (d *Document) parseAutoLink(input string, start int) (int, int, Node) { return 0, 0, nil } 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 { protocol = m[1] diff --git a/org/testdata/inline.html b/org/testdata/inline.html index f964b77..eedcbd5 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -61,7 +61,7 @@ empty emphasis markers like ++ // __ and so on are ignored
  • -subscriptsub and superscriptsuper +use _{} for subscriptsub and ^{} for superscriptsuper

  • diff --git a/org/testdata/inline.org b/org/testdata/inline.org index 0068516..6466578 100644 --- a/org/testdata/inline.org +++ b/org/testdata/inline.org @@ -17,7 +17,7 @@ is not emphasized/ - empty emphasis markers like ++ // __ and so on are ignored -- subscript_{sub} and superscript^{super} +- use _{} for subscript_{sub} and ^{} for superscript^{super} - links 1. regular link [[https://example.com]] link without description 2. regular link [[https://example.com][example.com]] link with description diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org index 0068516..6466578 100644 --- a/org/testdata/inline.pretty_org +++ b/org/testdata/inline.pretty_org @@ -17,7 +17,7 @@ is not emphasized/ - empty emphasis markers like ++ // __ and so on are ignored -- subscript_{sub} and superscript^{super} +- use _{} for subscript_{sub} and ^{} for superscript^{super} - links 1. regular link [[https://example.com]] link without description 2. regular link [[https://example.com][example.com]] link with description