Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix html entities encoding and decoding #161

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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