Fix: UTF-8 in formatWord

main
Leonid Maslakov 5 months ago
parent 8f9424b616
commit df631c6f0f
  1. 4
      highlight_share_openclose.go
  2. 26
      highlight_share_word.go
  3. 5
      highlight_share_word_test.go

@ -26,8 +26,8 @@ func formatOpenClose(text string, openStr string, closeStr string, styleClass st
textRune := []rune(text)
textLen := len(textRune)
openLen := len(openStr)
closeLen := len(closeStr)
openLen := len([]rune(openStr))
closeLen := len([]rune(closeStr))
spanTagOpen := false
otherSpanTagOpen := 0

@ -50,7 +50,7 @@ func formatWord(text string, command string, cmdStartChars []string, cmdEndChars
textRune := []rune(text)
textLen := len(textRune)
commandLen := len(command)
commandLen := len([]rune(command))
otherSpanTagOpen := 0
skip := 0
@ -101,30 +101,12 @@ func formatWord(text string, command string, cmdStartChars []string, cmdEndChars
// Check sub string
if subLine == command && otherSpanTagOpen == 0 {
okStart := false
okEnd := false
// Check command start char
for _, ch := range cmdStartChars {
if ch == lastChar {
okStart = true
break
}
}
// Check command end char
for _, ch := range cmdEndChars {
if ch == cmdEndChar {
okEnd = true
break
}
}
// Save
if okStart == true && okEnd == true {
// OK
if isInStrList(cmdStartChars, lastChar) && isInStrList(cmdEndChars, cmdEndChar) {
result = result + "<span class='" + styleClass + "'>" + command + "</span>"
skip = commandLen - 1
// Not OK
} else {
result = result + char
}

@ -68,7 +68,6 @@ func TestShareFormatWordKeyword(t *testing.T) {
runTest(testFunc, testData, t)
}
func TestShareFormatWordOperator(t *testing.T) {
testData := []testDataType{
{
@ -85,11 +84,11 @@ func TestShareFormatWordOperator(t *testing.T) {
},
{
Input: "a=2+1",
ExpectResult: "a<span class='"+StyleOperator+"'>=</span>2<span class='"+StyleOperator+"'>+</span>1",
ExpectResult: "a<span class='" + StyleOperator + "'>=</span>2<span class='" + StyleOperator + "'>+</span>1",
},
{
Input: "c=a+b",
ExpectResult: "c<span class='"+StyleOperator+"'>=</span>a<span class='"+StyleOperator+"'>+</span>b",
ExpectResult: "c<span class='" + StyleOperator + "'>=</span>a<span class='" + StyleOperator + "'>+</span>b",
},
}

Loading…
Cancel
Save