MohamedRejeb / compose-rich-editor

A Rich text editor library for both Jetpack Compose and Compose Multiplatform, fully customizable, supports HTML and Markdown.
https://mohamedrejeb.github.io/compose-rich-editor/
Apache License 2.0
1.12k stars 69 forks source link

Add supporting <h1> to <h6> Tags #301

Closed GimazDo closed 1 month ago

GimazDo commented 3 months ago

At the moment I have only found support for inserting html code into richState. Is there any plan to support changing the current paragraph style? Like state.toggleParagraphStyle( style = Header1 )

MohamedRejeb commented 3 months ago

Hi, In Compose we have SpanStyle so you after parsing HTML, h1 to h6 tags are converted to SpanStyle. Here's the SpanStyle for each tag, you can copy this code and use it in your project:

https://github.com/MohamedRejeb/Compose-Rich-Editor/blob/eccef2bcadebc6477059c8ddd3d0789fa6d667ea/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/utils/ElementsSpanStyle.kt#L22

internal val H1SpanStyle = SpanStyle(fontSize = 2.em, fontWeight = FontWeight.Bold)

state.toggleSpanStyle(H1SpanStyle)