• Stars
    star
    764
  • Rank 57,199 (Top 2 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rich text editor library for both Jetpack Compose and Compose Multiplatform, fully customizable and supports the common rich text editor features.

Compose Rich Editor


License API Profile Maven Central

Compose Rich Editor

A rich text editor library for both Jetpack Compose and Compose Multiplatform, fully customizable and supports the common rich text editor features

  • Multiplatform: Compose Rich Editor supports Compose Multiplatform (Android, iOS, Desktop, Web).
  • Easy to use: Compose Rich Editor's API leverages Kotlin's language features for simplicity and minimal boilerplate.
  • WYSIWYG: Compose Rich Editor is a WYSIWYG editor that supports the most common text styling features.

Download

Maven Central

Compose Rich Editor is available on mavenCentral().

implementation("com.mohamedrejeb.richeditor:richeditor-compose:1.0.0-beta03")

Quick Start

RichTextState

Use RichTextEditor composable to create a rich text editor.

The RichTextEditor composable requires a RichTextState to manage the editor's state.

To create a RichTextState, use the rememberRichTextState function:

val state = rememberRichTextState()

RichTextEditor(
    state = state,
)

Styling Spans

To style spans, RichTextState provides toggleSpanStyle method:

// Toggle a span style.
richTextState.toggleSpanStyle(SpanStyle(fontWeight = FontWeight.Bold))

To get the current span style of the selection, use RichTextState.currentSpanStyle:

// Get the current span style.
val currentSpanStyle = richTextState.currentSpanStyle
val isBold = currentSpanStyle.fontWeight = FontWeight.Bold

Styling Paragraphs

To style paragraphs, RichTextState provides toggleParagraphStyle method:

// Toggle a paragraph style.
richTextState.toggleParagraphStyle(ParagraphStyle(textAlign = TextAlign.Center))

To get the current paragraph style of the selection, use RichTextState.currentParagraphStyle:

// Get the current paragraph style.
val currentParagraphStyle = richTextState.currentParagraphStyle
val isCentered = currentParagraphStyle.textAlign = TextAlign.Center

Add links

To add links, RichTextState provides addLink method:

// Add link after selection.
richTextState.addLink(
    text = "Compose Rich Editor",
    url = "https://github.com/MohamedRejeb/Compose-Rich-Editor"
)

To get if the current selection is a link, use RichTextState.isLink:

// Get if the current selection is a link.
val isLink = richTextState.isLink

Add Code Blocks

To add code blocks, RichTextState provides toggleCode method:

// Toggle code block.
richTextState.toggleCode()

To get if the current selection is a code block, use RichTextState.isCode:

// Get if the current selection is a code block.
val isCode = richTextState.isCode

Ordered and Unordered Lists

You can add ordered and unordered lists using RichTextState:

// Toggle ordered list.
richTextState.toggleOrderedList()

// Toggle unordered list.
richTextState.toggleUnorderedList()

You can get if the current selection is an ordered or unordered list, using RichTextState:

// Get if the current selection is an ordered list.
val isOrderedList = richTextState.isOrderedList

// Get if the current selection is an unordered list.
val isUnorderedList = richTextState.isUnorderedList

Customizing the rich text configuration

Some of the rich text editor's features can be customized, such as the color of the links and the code blocks.

richTextState.setConfig(
    linkColor = Color.Blue,
    linkTextDecoration = TextDecoration.Underline,
    codeColor = Color.Yellow,
    codeBackgroundColor = Color.Transparent,
    codeStrokeColor = Color.LightGray,
)

HTML import and export

To convert HTML to RichTextState, use RichTextState.setHtml method:

val html = "<p><b>Compose Rich Editor</b></p>"
richTextState.setHtml(html)

To convert RichTextState to HTML, use RichTextState.toHtml method:

val html = richTextState.toHtml()

Markdown import and export

To convert Markdown to RichTextState, use RichTextState.setMarkdown method:

val markdown = "**Compose** *Rich* Editor"
richTextState.setMarkdown(markdown)

To convert RichTextState to Markdown, use RichTextState.toMarkdown method:

val markdown = richTextState.toMarkdown()

Check out Compose Rich Editor's full documentation for more details.

Web live demo

You can try out the web demo here.

Contribution

If you've found an error in this sample, please file an issue.
Feel free to help out by sending a pull request ❤️.

Code of Conduct

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐
Also, follow me on GitHub for more libraries! 🤩

You can always

License

Copyright 2023 Mohamed Rejeb

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

Calf

Calf is a library that allows you to easily create adaptive UIs for your Compose Multiplatform apps.
Kotlin
604
star
2

Pokedex

Pokedex - a Kotlin Multiplatform app, built with Compose multiplatform, Coroutines, Flow, Koin, Ktor, SqlDelight, Decompose, MVIKotlin, and Material 3 based on MVI architecture
Kotlin
593
star
3

Ksoup

Ksoup is a lightweight Kotlin Multiplatform library for parsing HTML, extracting HTML tags, attributes, and text, and encoding and decoding HTML entities.
Kotlin
308
star
4

compose-dnd

Compose DND is a library that allows you to easily add drag and drop functionality to your Jetpack Compose or Compose Multiplatform projects.
Kotlin
203
star
5

Card-Game-Animation

Sample card game app made using Jetpack Compose. Contains some complex animations.
Kotlin
124
star
6

Compose-Youtube-Motion-Layout

Compose Youtube Motion Layout App
Kotlin
81
star
7

Animated-Circular-Download-Button

Animated Circular Download Button
Kotlin
80
star
8

Compose-Geometry-Playground

Geometry playground app made using Compose multiplatform that works for both android and desktop.
Kotlin
67
star
9

Compose-Interactive-Gamepad

Interactive gamepad made using jetpack compose
Kotlin
46
star
10

Dino-Game

Simple Dino Game 🎮 made using Compose multiplatform ( There's no Dino but who cares 🤣 ) I used Kotlin multiplatform with Compose multiplatform, for now the game works for android and desktop (IOS and Web soon ⏳ ).
Kotlin
26
star
11

cmp-clean-architecture

Clean Architecture App with Kotlin and Compose Multiplatform.
Kotlin
18
star
12

Pencil-Loader-Animation

Custom Pencil Loader Animation made using Jetpack compose and canvas.
Kotlin
17
star
13

drawing-android-app

Drawing native android app using Kotlin and XML
Kotlin
16
star
14

cmp-youtube-tutorial

Kotlin
9
star
15

android_logo_compose_canvas

A simple android logo made using compose canvas
Kotlin
6
star
16

JudoApp

Python
5
star
17

MohamedRejeb

5
star
18

Notes-App

Kotlin
4
star
19

Compose-Infinite-Pager

Kotlin
4
star
20

Compose-Dynamic-Text

Compose UI Dynamic Text component that enables you to change the text depending on the available width
Kotlin
4
star
21

Kpen

Objective-C
3
star
22

Compose-Snake-Game

Kotlin
3
star
23

looker-app

Kotlin
2
star
24

CleanArchitectureSample

Clean architecture android app made using jetpack compose and firebase
Kotlin
2
star
25

aoc-kotlin-2023

Advent of Code Kotlin 2023
Kotlin
2
star
26

CMP-3685

Kotlin
2
star
27

Android-Clock-Component

1
star
28

CMPIssue4380

Kotlin
1
star
29

Color-Picker-App

1
star
30

Android-Kts-Starter

Kotlin
1
star
31

Travel-App

Clean architecture travel android app
Kotlin
1
star
32

Android-clean-architecture-sample

1
star
33

Koltin-Introduction

Kotlin
1
star
34

storybook-compose

Nothing interesting here yet!
Kotlin
1
star