diff --git a/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt b/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt index 4bb60f1ac5c..7bda9d0bbaf 100644 --- a/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt +++ b/plugins/base/src/main/kotlin/translators/parseWithNormalisedSpaces.kt @@ -44,7 +44,13 @@ internal fun String.parseHtmlEncodedWithNormalisedSpaces( */ internal fun String.parseWithNormalisedSpaces( renderWhiteCharactersAsSpaces: Boolean -): List = - //parsing it using jsoup is required to get codePoints, otherwise they are interpreted separately, as chars - //But we dont need to do it for java as it is already parsed with jsoup - Jsoup.parseBodyFragment(this).body().wholeText().parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces) \ No newline at end of file +): List { + if (!requiresHtmlEncoding()) { + return parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces) + } + // parsing it using jsoup is required to get codePoints, otherwise they are interpreted separately, as chars + // But we dont need to do it for java as it is already parsed with jsoup + return Jsoup.parseBodyFragment(this).body().wholeText().parseHtmlEncodedWithNormalisedSpaces(renderWhiteCharactersAsSpaces) +} + +private fun String.requiresHtmlEncoding(): Boolean = indexOf('&') != -1