Giter Site home page Giter Site logo

felixdivo / multiplatform-markdown-renderer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikepenz/multiplatform-markdown-renderer

0.0 0.0 0.0 448 KB

Markdown renderer for Kotlin Multiplatform Projects (Android, iOS, Desktop), using Compose.

Home Page: https://blog.mikepenz.dev

License: Apache License 2.0

Ruby 2.68% Kotlin 97.32%

multiplatform-markdown-renderer's Introduction

Kotlin Multiplatform Markdown Renderer

... a Kotlin Multiplatform Markdown Renderer. (Android, Desktop, ...) powered by Compose Multiplatform



What's included ๐Ÿš€ โ€ข Setup ๐Ÿ› ๏ธ โ€ข Usage ๐Ÿ› ๏ธ โ€ข License ๐Ÿ““


What's included ๐Ÿš€

  • Super simple setup
  • Cross-platform ready
  • Lightweight

Setup

Using Gradle

Multiplatform

For multiplatform projects specify this single dependency:

dependencies {
    implementation("com.mikepenz:multiplatform-markdown-renderer:${version}")

    // Offers Material 2 defaults for Material 3 themed apps (com.mikepenz.markdown.m2.Markdown)
    implementation("com.mikepenz:multiplatform-markdown-renderer-m2:${version}")

    // Offers Material 3 defaults for Material 3 themed apps (com.mikepenz.markdown.m3.Markdown)
    implementation("com.mikepenz:multiplatform-markdown-renderer-m3:${version}")
}

JVM

To use the library on JVM, you have to include:

dependencies {
    implementation("com.mikepenz:multiplatform-markdown-renderer-jvm:${version}")
}

Android

For Android a special dependency is available:

dependencies {
    implementation("com.mikepenz:multiplatform-markdown-renderer-android:${version}")
}

Tip

Since 0.13.0 the core library does not depend on a Material theme anymore. Include the -m2 or -m3 module to get access to the defaults.


Usage

val markdown = """
### What's included ๐Ÿš€

- Super simple setup
- Cross-platform ready
- Lightweight
""".trimIndent()

//
Markdown(markdown)
Advanced Usage

The library offers the ability to modify different behaviour when rendering the markdown.

Provided custom style

Markdown(
    content,
    colors = markdownColors(text = Color.Red),
    typography = markdownTypography(h1 = MaterialTheme.typography.body1)
)

Adjust List Ordering

// Use the bullet list symbol from the original markdown
CompositionLocalProvider(LocalBulletListHandler provides { "$it " }) {
    Markdown(content)
}

// Replace the ordered list symbol with `A.)` instead.
CompositionLocalProvider(LocalOrderedListHandler provides { "A.) " }) {
    Markdown(content, Modifier.fillMaxSize().padding(16.dp).verticalScroll(scrollState))
}

Custom Components

Since v0.9.0 it is possible to provide custom components, instead of the default ones. This can be done by providing the components MarkdownComponents to the Markdown composable.

Use the markdownComponents() to keep defaults for non overwritten components.

The MarkdownComponent will expose access to the content: String, node: ASTNode, typography: MarkdownTypography, offering full flexibility.

// Simple adjusted paragraph with different Modifier.
val customParagraphComponent: MarkdownComponent = {
    MarkdownParagraph(it.content, it.node, Modifier.align(Alignment.End))
}

// Full custom paragraph example
val customParagraphComponent: MarkdownComponent = {
    // build a styled paragraph. (util function provided by the library)
    val styledText = buildAnnotatedString {
        pushStyle(LocalMarkdownTypography.current.paragraph.toSpanStyle())
        buildMarkdownAnnotatedString(content, it.node)
        pop()
    }

    // define the `Text` composable
    Text(
        styledText,
        modifier = Modifier.align(Alignment.End),
        textAlign = TextAlign.End
    )
}

// Define the `Markdown` composable and pass in the custom paragraph component
Markdown(
    content,
    components = markdownComponents(
        paragraph = customParagraphComponent
    )
)

Dependency

This project uses JetBrains markdown Multiplatform Markdown processor as dependency to parse the markdown content.

Developed By

Contributors

This free, open source software was also made possible by a group of volunteers that put many hours of hard work into it. See the CONTRIBUTORS.md file for details.

Credits

Big thanks to Erik Hellman and his awesome article on Rendering Markdown with Jetpack Compose, and the related source MarkdownComposer.

Fork License

Copyright for portions of the code are held by [Erik Hellman, 2020] as part of project MarkdownComposer under the MIT license. All other copyright for project multiplatform-markdown-renderer are held by [Mike Penz, 2023] under the Apache License, Version 2.0.

License

Copyright 2024 Mike Penz

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.

multiplatform-markdown-renderer's People

Contributors

mikepenz avatar programistich avatar nonproto avatar psuzn avatar dependabot[bot] avatar msfjarvis avatar sroebert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.