diff --git a/org/inline.go b/org/inline.go index b1bb28c..b91d6b8 100644 --- a/org/inline.go +++ b/org/inline.go @@ -371,19 +371,30 @@ func (d *Document) parseEmphasis(input string, start int, isRaw bool) (int, Node // see org-emphasis-regexp-components (emacs elisp variable) func hasValidPreAndBorderChars(input string, i int) bool { - return (i+1 >= len(input) || isValidBorderChar(rune(input[i+1]))) && (i == 0 || isValidPreChar(rune(input[i-1]))) + return isValidBorderChar(nextRune(input, i)) && isValidPreChar(prevRune(input, i)) } func hasValidPostAndBorderChars(input string, i int) bool { - return (i == 0 || isValidBorderChar(rune(input[i-1]))) && (i+1 >= len(input) || isValidPostChar(rune(input[i+1]))) + return (isValidPostChar(nextRune(input, i))) && isValidBorderChar(prevRune(input, i)) +} + +func prevRune(input string, i int) rune { + r, _ := utf8.DecodeLastRuneInString(input[:i]) + return r +} + +func nextRune(input string, i int) rune { + _, c := utf8.DecodeRuneInString(input[i:]) + r, _ := utf8.DecodeRuneInString(input[i+c:]) + return r } func isValidPreChar(r rune) bool { - return unicode.IsSpace(r) || strings.ContainsRune(`-({'"`, r) + return r == utf8.RuneError || unicode.IsSpace(r) || strings.ContainsRune(`-({'"`, r) } func isValidPostChar(r rune) bool { - return unicode.IsSpace(r) || strings.ContainsRune(`-.,:!?;'")}[`, r) + return r == utf8.RuneError || unicode.IsSpace(r) || strings.ContainsRune(`-.,:!?;'")}[`, r) } func isValidBorderChar(r rune) bool { return !unicode.IsSpace(r) } diff --git a/org/testdata/inline.html b/org/testdata/inline.html index b0b886d..383fd81 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -5,6 +5,7 @@ also hard line breaks not followed by a newline get ignored, see \\
  • .emphasis with dot border chars.
  • emphasis with a slash/inside
  • emphasis followed by raw text with slash /
  • +
  • emphasis ending with a "difficult" multibyte character 习
  • ->/not an emphasis/<-
  • links with slashes do not become emphasis: https://somelinkshouldntrenderaccidentalemphasis.com/ emphasis
  • underlined bold verbatim code strikethrough
  • diff --git a/org/testdata/inline.org b/org/testdata/inline.org index a2b486a..8e2fd78 100644 --- a/org/testdata/inline.org +++ b/org/testdata/inline.org @@ -4,6 +4,7 @@ - /.emphasis with dot border chars./ - /emphasis with a slash/inside/ - /emphasis/ followed by raw text with slash / +- *emphasis ending with a "difficult" multibyte character 习* - ->/not an emphasis/<- - links with slashes do not become /emphasis/: [[https://somelinkshouldntrenderaccidentalemphasis.com]]/ /emphasis/ - _underlined_ *bold* =verbatim= ~code~ +strikethrough+ diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org index dfd0b6a..b6275fb 100644 --- a/org/testdata/inline.pretty_org +++ b/org/testdata/inline.pretty_org @@ -4,6 +4,7 @@ - /.emphasis with dot border chars./ - /emphasis with a slash/inside/ - /emphasis/ followed by raw text with slash / +- *emphasis ending with a "difficult" multibyte character 习* - ->/not an emphasis/<- - links with slashes do not become /emphasis/: [[https://somelinkshouldntrenderaccidentalemphasis.com]]/ /emphasis/ - _underlined_ *bold* =verbatim= ~code~ +strikethrough+