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

Add Image support to RichText #305

Merged
merged 7 commits into from
Jul 20, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove empty HTML blocks
  • Loading branch information
MohamedRejeb committed Jul 20, 2024
commit 599873de9518081e8002ee6e0ca746167fe26838
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
val openedTags = mutableListOf<Pair<String, Map<String, String>>>()
val stringBuilder = StringBuilder()
val richParagraphList = mutableListOf<RichParagraph>()
val lineBreakParagraphIndexSet = mutableSetOf<Int>()
var currentRichSpan: RichSpan? = null
var lastClosedTag: String? = null

Expand Down Expand Up @@ -168,6 +169,7 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
else
RichParagraph(paragraphStyle = richParagraphList.last().paragraphStyle)
richParagraphList.add(newParagraph)
lineBreakParagraphIndexSet.add(richParagraphList.lastIndex)
currentRichSpan = null
}

Expand All @@ -192,6 +194,16 @@ internal object RichTextStateHtmlParser : RichTextStateParser<String> {
parser.write(input)
parser.end()

for (i in richParagraphList.lastIndex downTo 0) {
// Keep empty paragraphs if they are line breaks
if (i in lineBreakParagraphIndexSet)
continue

// Remove empty paragraphs
if (richParagraphList[i].isBlank())
richParagraphList.removeAt(i)
}

return RichTextState(
initialRichParagraphList = richParagraphList,
)
Expand Down
Loading