Skip to content

Commit

Permalink
Merge pull request #161 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Fix html entities encoding and decoding
  • Loading branch information
MohamedRejeb authored Dec 28, 2023
2 parents fcaf15c + 065aa13 commit 54bfd15
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ nexus-publish = "2.0.0-rc-1"
# For sample
compose-compiler = "1.5.4"
activity-compose = "1.8.1"
voyager = "1.0.0-rc10"
voyager = "1.0.0"
richeditor = "1.0.0-beta05"
android-minSdk = "21"
android-compileSdk = "34"

[libraries]
ksoup = { module = "com.mohamedrejeb.ksoup:ksoup-html", version.ref = "ksoup" }
ksoup-html = { module = "com.mohamedrejeb.ksoup:ksoup-html", version.ref = "ksoup" }
ksoup-entities = { module = "com.mohamedrejeb.ksoup:ksoup-entities", version.ref = "ksoup" }
jetbrains-markdown = { module = "org.jetbrains:markdown", version.ref = "jetbrainsMarkdown" }

nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.gradle-nexus.publish-plugin.gradle.plugin", version.ref = "nexus-publish" }
Expand Down
3 changes: 2 additions & 1 deletion richeditor-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ kotlin {
implementation(compose.material3)

// HTML parsing library
implementation(libs.ksoup)
implementation(libs.ksoup.html)
implementation(libs.ksoup.entities)

// Markdown parsing library
implementation(libs.jetbrains.markdown)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mohamedrejeb.richeditor.parser.html

import androidx.compose.ui.text.SpanStyle
import com.mohamedrejeb.ksoup.entities.KsoupEntities
import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlHandler
import com.mohamedrejeb.ksoup.html.parser.KsoupHtmlParser
import com.mohamedrejeb.richeditor.model.*
Expand Down Expand Up @@ -30,9 +31,11 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
val lastOpenedTag = openedTags.lastOrNull()?.first
if (lastOpenedTag in skippedHtmlElements) return@onText

val addedText = removeHtmlTextExtraSpaces(
input = it,
trimStart = stringBuilder.lastOrNull() == ' ' || stringBuilder.lastOrNull() == '\n',
val addedText = KsoupEntities.decodeHtml(
removeHtmlTextExtraSpaces(
input = it,
trimStart = stringBuilder.lastOrNull() == ' ' || stringBuilder.lastOrNull() == '\n',
)
)
if (addedText.isEmpty()) return@onText

Expand Down Expand Up @@ -253,7 +256,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
}

// Append text
stringBuilder.append(richSpan.text)
stringBuilder.append(KsoupEntities.encodeHtml(richSpan.text))

// Append children
richSpan.children.fastForEach { child ->
Expand Down

0 comments on commit 54bfd15

Please sign in to comment.