Coder Social home page Coder Social logo

mikepenz / multiplatform-markdown-renderer Goto Github PK

View Code? Open in Web Editor NEW
305.0 5.0 23.0 542 KB

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

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

License: Apache License 2.0

Ruby 1.86% Kotlin 98.14%
markdown kotlin kotlin-multiplatform android jvm hacktoberfest compose

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 2 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)
)

Extended spans

Starting with 0.16.0 the library includes support for extended-spans.

The library was integrated to to make it multiplatform compatible. All credits for its functionality goes to Saket Narayan.

It is not enabled by default, however you can enable it quickly by configuring the extendedSpans for your Markdown composeable. Define the ExtendedSpans you want to apply (including optionally your own custom ones) and return it.

Markdown(
    content,
    extendedSpans = markdownExtendedSpans {
        val animator = rememberSquigglyUnderlineAnimator()
        remember {
            ExtendedSpans(
                RoundedCornerSpanPainter(),
                SquigglyUnderlineSpanPainter(animator = animator)
            )
        }
    }
)

Extend Annotated string handling

The library already handles a significant amount of different tokens, however not all. To allow special integrations expand this, you can pass in a custom annotator to the Markdown composeable. This annotator allows you to customize existing handled tokens, but also add new ones.

Markdown(
    content,
    annotator = markdownAnnotator { content, child ->
        if (child.type == GFMElementTypes.STRIKETHROUGH) {
            append("Replaced you :)")
            true // return true to consume this ASTNode child
        } else false
    }
)

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
    )
)

Image Loading

In the current versions of the library, image loading is included in different variants.

  • Android: Uses coil to load images (Default configuration). The global ImageLoader is respected.
  • JVM: Load image as HTTPUrlConnection and set to the view
  • JS / Native: No image loading provided at this time

Provide your own ImageTransformer to the Markdown compose function to modify this behavior.

Note

It is planned to update to coil3 for all platforms once it reaches a more stable release cycle.

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.

Also huge thanks to Saket Narayan for his great work on the extended-spans project. Ported into this project to make it multiplatform.

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

androidacy-user avatar dependabot[bot] avatar felixdivo avatar mikepenz avatar msfjarvis avatar nonproto avatar programistich avatar psuzn avatar sroebert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

multiplatform-markdown-renderer's Issues

Some features

About this issue

What u think about create data class Typography/Color with text style for all item in markdown?
And I think great point for custom padding

Library doesn't handle unconventional ordered lists

About this issue

The library only handles ordered lists with numbers that are correctly ordered. Such as
1.
2.
3.

If you try to do a valid ordered list like
1.
1.
1.
instead of the expected output of
1.
2.
3.

you get the same output as put in.

Reference links parsing breaks [] text

Currently if I have a markdown text with double [] such as

[This should work][This is not a link] this is just text 

Yada yadada
The end

The library assumes it's a reference link when parsing causing the output to be wrong and it becomes a clickable link to nothing.

Links with URLs as their label do not render

About this issue

Given a link that looks like this: [https://example.com](https://github.com/mikepenz), the library renders nothing on screen. Expected behavior would be for it to show https://example.com.

Details

  • Used library version: 0.1.0
  • Used platform: Compose Desktop
  • Used support library version: 1.0.0-alpha4-build398
  • Used gradle build tools version: Gradle 7.2
  • Used tooling / Android Studio version: IntelliJ IDEA 2021.3 EAP, reproducible without an IDE.
  • Other used libraries, potential conflicting libraries: None, this is reproducible in the Compose Desktop sample.

Checklist

bug: no links in header

About this issue

  • Briefly describe the issue:

Links can't be used in Headers

Image:

image

  • How can the issue be reproduced / sample code
    val markdown = """
    # [This doesnt work](https://github.com/)
    [This works](https://github.com/)""".trimIndent()

    Markdown(
        content = markdown,
        colors = markdownColor(
            text = MaterialTheme.colorScheme.onSurfaceVariant,
            codeBackground = MaterialTheme.colorScheme.secondaryContainer,
            codeText = MaterialTheme.colorScheme.onSecondaryContainer
        ),
        typography = markdownTypography(
            h1 = MaterialTheme.typography.headlineSmall.copy(fontWeight = FontWeight.Bold),
            h2 = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold),
            h3 = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold),
            text = MaterialTheme.typography.bodyMedium,
            list = MaterialTheme.typography.bodyMedium
        )
    )

Details

  • v0.8.0
  • Android

Checklist

Compose Desktop Don't work

Multiplatform
For multiplatform projects specify this single dependency:

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

Use Markdown("", Modifier.fillMaxSize())

Exception in thread "AWT-EventQueue-0" java.lang.IncompatibleClassChangeError: Found class androidx.compose.runtime.Composer, but interface was expected
at com.mikepenz.markdown.MarkdownKt.Markdown(Markdown.kt:51)

Images are rendered using only remote paths

About this issue

You can make images using remote links (https, http), but you can't specify local path to render local image
i've tried ./path/img.png, path/img.png, file:///path/img.png but none worked so far
and by the looks of imagePainter in ImagePainterProvider - it won't, because it fetches image always through http

Credited project could use local image paths

Details

  • [multiplatform-markdown-renderer 0.4.0]
  • [Desktop]
  • [Compose 1.1.1]
  • [Gradle 7.2]
  • [JDK 17]

Feature request: More contextual color controls

About this issue

I'd like to feature request more color controls for some contexts. Some examples:

  • Ability to use different text colors for inline code text and code block text, since their backgrounds can be different.
  • Ability to apply color transformations to quoted content (usually quoted content is a lighter color than usual text). Scratch this one, we can control this 👍

Details

  •  Used library version - 0.14.0
  •  Used platform - Desktop
  •  Used support library version
  •  Used gradle build tools version - N/A
  •  Used tooling / Android Studio version - N/A
  •  Other used libraries, potential conflicting libraries - Jewel

Checklist

how fix it

java.lang.IllegalStateException:
FocusRequester is not initialized. Here are some possible fixes:

                                                                                                   1. Remember the FocusRequester: val focusRequester = remember { FocusRequester() }
                                                                                                   2. Did you forget to add a Modifier.focusRequester() ?
                                                                                                   3. Are you attempting to request focus during composition? Focus requests should be made in
                                                                                                   response to some event. Eg Modifier.clickable { focusRequester.requestFocus() }

Markdown-it flavour

Would love a flavor that is configurable with html tags. Notice [test <test>](https://test.com/) actually rendering the in the output.

sample

IndexOutOfBounds when trying to render the incomplete markdown code

About this issue

Code to reproduce:

Markdown(content = "```")

Proposed fix

@Composable
private fun MarkdownCodeFence(
    content: String,
    node: ASTNode,
    modifier: Modifier = Modifier,
    colors: MarkdownColors
) {
    val start = node.children[2].startOffset  // <----- probably need to check if length is not less than 3
    val end = node.children[node.children.size - 2].endOffset
    Code(content.subSequence(start, end).toString().replaceIndent(), modifier, colors)
}

Documentation: How to use custom components

About this issue

There was functionality added to allow the ability to create custom components, however, (afaik) there is no documentation explaining how to use this new feature.

Request

Perhaps under the advanced usage section in the readme.md, could there be an example added of how to handle setting the regex and the component to replace the matched text with.
I am unsure if the feature allows for adding multiple custom components, or if it's limited to only customizing preexisting markdown components.

If it would be too hard to include a broad enough example to get an initial setup for adding custom components, any answers or details to the feature's usage would be greatly appreciated. Thank you for the project regardless!

bug: v0.9.0 does not support iOS

About this issue

  • Briefly describe the issue
    I'm working on a KMM project. I can't run the iosApp if I use v0.9.0 of markdown-renderer, while v0.7.2 works fine. It seems because the iOS target was deleted accidentally when upgraded to compose 1.5.4
> Could not resolve com.mikepenz:multiplatform-markdown-renderer:0.9.0.
     Required by:
         project :shared
      > No matching variant of com.mikepenz:multiplatform-markdown-renderer:0.9.0 was found. The consumer was configured to find a library for use during 'kotlin-metadata', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64' but:
          - Variant 'iosSimulatorArm64ApiElements-published' capability com.mikepenz:multiplatform-markdown-renderer:0.9.0 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_x64'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)

Details

  • [ 0.9.0 ] Used library version

SelectionContainer prevents clicks on links

About this issue

Link is not clickable when SelectionContainer is used. For example:

SelectionContainer {
    Markdown(content = "[test](https://exampmle.com)")
}

It is possible to solve that by using onPointerEvent() with PointerEventPass.Initial. Probably checking if click has finished at the same position as started would do the trick. Could you take a look, please?

Details

version: 0.10.0

Feature request: TextAlign

About this issue

Do you think it would be possible to allow passing in TextAlign? I pose it as a question because for a simple text with some bold, I'm sure it's easy but I'm not sure if it would make sense for a more complex markdown example.

Details

  • 0.10.0 Used library version
  • Android/JS Used platform

Checklist

Tables and dividers don't render properly

About this issue

This doesn't seem to render hrules/divider or tables properly..otherwise, it works great!

Example markdown:

--------------------------------------------------------------------------
A/B Test Cells (All) number is percentage of crashes with user in test cell:
----------------------------------------------------------------------------

|Test ID|Cell|% users|
|-------|----|-------
| 55977 | 6 | 15% |
| 55085 | 4 | 14% |
| 56835 | 10 | 13% |
| 57360 | 9 | 12% |

The hrule/divider makes the text within get rendered at a very large size. And the table doesn't show up:
Screenshot 2024-01-05 at 10 28 56 AM

I checked the IntelliJ library that this library uses and it appears to support tables so I'm guessing this library doesn't handle them? If so, it should be documented in the Readme.md.

Details

  • [ 0.10.0 ] Used library version
  • [ Compose Multiplatform 1.5.11 ] Used platform
  • [ N/A ] Used support library version
  • [ 8.5 ] Used gradle build tools version
  • [ Iguana ] Used tooling / Android Studio version
  •  Other used libraries, potential conflicting libraries

Checklist

Markdown links using the reference pattern are not rendered

About this issue

The CommonMark spec for it can be found here.

Changing the text rendered by the compose-desktop sample to either of the ones given below reproduces the issue.

First reproducer
### Getting Started

To get started you will need GPG on your computer to create a new key pair. 

Usually I go with the [GPG Suite][1], which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

![Image](https://avatars.githubusercontent.com/u/1476232?v=4)

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key. 
[1]: https://gpgtools.org/
Second reproducer
### Getting Started

To get started you will need GPG on your computer to create a new key pair. 

Usually I go with the [GPG Suite], which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

![Image](https://avatars.githubusercontent.com/u/1476232?v=4)

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key. 
[GPG Suite]: https://gpgtools.org/

Details

  • Used library version: 0.1.0
  • Used platform: Compose Desktop
  • Used support library version: 1.0.0-alpha4-build398
  • Used gradle build tools version: Gradle 7.2
  • Used tooling / Android Studio version: IntelliJ IDEA 2021.3 EAP, reproducible without an IDE.
  • Other used libraries, potential conflicting libraries: None, this is reproducible in the Compose Desktop sample.

Checklist

Add JS support

About this issue

  • Briefly describe the issue

  • How can the issue be reproduced / sample code
    Hi, I'm using Compose for Web as a kotlin("js") project and I installed the library in multiplatform, but I still can't use it in my project, I'm in Compose 1.2.0-apha01-dev753 using Kotlin 1.7.0 with Gradle 7.5.0 and the library in 0.6.1 with Intellij 2022.2.

Checklist

NoSuchMethodError thrown using newer GFM versions

About this issue

When running Markdown() with a newer version of intellij's markdown dependency (0.4.1), the following error occurs at runtime

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor: method 'void <init>(boolean, boolean, int, kotlin.jvm.internal.DefaultConstructorMarker)' not found
	at com.mikepenz.markdown.MarkdownKt.Markdown(Markdown.kt:66)
	at dev.zacsweers.ComposableSingletons$DesktopKt$lambda-1$1.invoke(Desktop.kt:30)
	at dev.zacsweers.ComposableSingletons$DesktopKt$lambda-1$1.invoke(Desktop.kt:17)

Details

  • Used library version - 0.6.1
  • Used platform - Desktop
  • Used gradle build tools version - 8.3-rc-3
  • Used tooling / Android Studio version - IntelliJ
  • Other used libraries, potential conflicting libraries - clikt, which brings in a newer markdown dep version

Checklist

Bullet lists are not colored correctly

Based off the code from what I can tell passing a custom MarkdownColors with the text color set should render things in text color. Bullet lists however always stay black.

Add support for IOS simulator target

About this issue

  • Briefly describe the issue
    I'm working on a project that targets Android, IOS and desktop(JVM). I have an IOS simulator as one of the targets to test the app on the simulator and I'm not able to add the markdown renderer without removing the IOS simulator from the targets.
 Could not resolve com.mikepenz:multiplatform-markdown-renderer:0.7.1.
  Required by:
      project :shared
   > No matching variant of com.mikepenz:multiplatform-markdown-renderer:0.7.1 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64' but:
       - Variant 'iosArm64ApiElements-published' capability com.mikepenz:multiplatform-markdown-renderer:0.7.1 declares a library for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
           - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64'
           - Other compatible attribute:
               - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
       - Variant 'iosArm64MetadataElements-published' capability com.mikepenz:multiplatform-markdown-renderer:0.7.1 declares a library, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native':
           - Incompatible because this component declares a component for use during 'kotlin-metadata', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.native.target' with value 'ios_simulator_arm64'
           - Other compatible attribute:
               - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)

  • How can the issue be reproduced / sample code
  1. Specify iosSimulator as the target
  2. Add multiplatform-markdown-renderer as a dependency on the common module
// build.gradle.kts

kotlin {
    android()
    jvm("desktop")
    ios()
    iosSimulatorArm64()
    ...
    sourceSets {
        val commonMain by getting {
            dependencies {
                ...
                implementation("com.mikepenz:multiplatform-markdown-renderer:0.7.1")
            }
        }
    }
}

Details

  • [0.7.1] Used library version
  • [ iosSimulatorArm64] Used platform
  • [-] Used support library version
  • [Gradle 8.1 W/ AGP 8.1.0] Used gradle build tools version
  • [- ] Used tooling / Android Studio version
  • [-] Other used libraries, potential conflicting libraries

Checklist

Incorrect markdown nested rendering

Thanks a lot for having such a good markdown rendering library! 👍 It basically parses most markdown content, and is also highly customizable, but in some text, it takes the outermost syntax of the markdown with it, resulting in a nested markdown text, which it can't render properly.

Here is a reproducible text:


Sure, here is a sample complex markdown text with code snippets:

```
# Markdown Sample

This is an example of a complex markdown text that includes code snippets:

## Code Snippet in Python

```python
def greet(name):
print(f"Hello, {name}!")

greet("Alice")
```

## Code Snippet in JavaScript

```javascript
function greet(name) {
console.log(Hello, ${name}!);
}

greet("Bob");
```

You can format code in markdown using triple backticks followed by the language name.

```
Feel free to modify and use this markdown text as needed.


In github, it will render as:

image

but the library will render as:

image

Feature request: Support strikethrough

About this issue

Currently, strikethrough nodes are omitted from the rendered markdown.

~~This is strikethrough~~

Details

  •  Used library version - 0.14.0
  •  Used platform - Desktop
  •  Used support library version
  •  Used gradle build tools version - N/A
  •  Used tooling / Android Studio version - N/A
  •  Other used libraries, potential conflicting libraries - Jewel

Checklist

Drop MaterialTheme

About this issue

Can you drop the MaterialTheme and provide a custom theme?

Suggested code rendering improvements

About this issue

I wanted to suggest/offer to PR a couple of small improvements to code rendering.

  1. Inline code snippets are lacking a bit of padding. Consider the below from this library
image

Vs how it looks in github

image

Similarly,

  1. Inline code snippets could use some corner padding similar to how code blocks do.

Details

  •  Used library version - 0.14.0
  •  Used platform - Desktop
  •  Used support library version
  •  Used gradle build tools version - N/A
  •  Used tooling / Android Studio version - N/A
  •  Other used libraries, potential conflicting libraries - Jewel

Checklist

[question/enhancement] override default markdownComponents recursively

About this issue

This is not a real issue but more of a question or enhancement proposal, because either I am not getting it (despite having checked the "Advanced usage" section in the README multiple times), or what I would like to do can not be done actually with the current version and from this discussion new evolution proposals can come. I candidate myself to help out if needed.

First of all, thanks for this awesome library: I am following the project since year and I think this is one of the "missing pieces" that are crucial for Kotlin Multiplatform development. Also, I really appreciated the possibility to provide custom MarkdownComponents that was introduced with 0.9.0, because it was really difficult to support Markdown dialectal extensions (e.g. spoilers with the ::: spoiler <title>\n<content>\n::: syntax).

But, from what I see, the user-provided components are used only at the top level and there is no easy way to use the newly provided component as a subcomponent of another one. Let me explain with an example: suppose I am providing my custom MarkdownComponent to render images, this works fine to handle an IMAGE element but if a TEXT element contains an inline image the default Image is used and not the custom one because MarkdownText directly uses the built-in Image Composable. Similarly, if I provide a custom MarkdownComponent to render TEXT blocks, this is not called inside a PARAGRAPH because MarkdownParagraph internally calls the default MarkdownText and custom components are only queried in the handleElement function which is running of every node of the AST.

Shouldn't it be possible to retrieve MarkdownComponents from composition locals?
Feel free to close if not relevant and thank you in the meantime for this great project.

I'm currently using library version 0.12.0, Compose multiplatform 1.5.12, Gradle 8.6 with AGP 8.2.2

Details

  •  Used library version
  •  Used platform
  •  Used support library version
  •  Used gradle build tools version
  •  Used tooling / Android Studio version
  •  Other used libraries, potential conflicting libraries

Checklist

Bug report: dividers are never rendered

About this issue

If I render the following snippet in markdown, I never see horizontal lines rendered

This is a divider

---

The above is a divider

Will render like so

image

Details

  •  Used library version - 0.14.0
  •  Used platform - Desktop
  •  Used support library version
  •  Used gradle build tools version - N/A
  •  Used tooling / Android Studio version - N/A
  •  Other used libraries, potential conflicting libraries - Jewel

Checklist

Use outside of a compose app

About this issue

Hi! We have no interest in using Compose, whereas your library seems to mandate the use of Compose.

Also, unfortunately for us, your library seems to be one of the only libraries for rendering markdown that's decently maintained.

Perhaps we are missing how to use it without compose (Markdown(text) does not work, outside of a composable function), or is there plans to support non compose Android apps?

Details

  •  Used library version 0.12.0
  •  Used platform
  •  Used support library version
  •  Used gradle build tools version 8.2.2
  •  Used tooling / Android Studio version Android Gradle Plugin 8.2.2
  •  Other used libraries, potential conflicting libraries

Checklist

![Image](ImageURL) rendered by PARAGRAPH

About this issue

ASTNode.handleElement for ![Image](Image URL's) section are handled by a paragraph and not MarkdownElementTypes.IMAGE
This is causing images to appear with a fixed size of 180.dp since Placeholders aren't supporting flexibility here.

Details

  •   0.2.4
  •  Android, Desktop(Linux)
  •  7.0.4
  •  IDEA-U

Android Compose library without Material

About this issue

Markdown() composable has a strong dependency on material components like androidx.compose.material.MaterialTheme.

For Wear these should be avoided and instead use Wear Material versions.

See https://developer.android.com/training/wearables/compose#different

Is it feasible to pull these Color and Typography factories that default to mobile material to a separate dependency?

Details

0.11
Wear (Android)

Checklist

Images are invisible

About this issue

Hello! When trying to render markdown, images do not show. However, if they are linked, clicking on the empty space where they should be opens the link

Details

  •  Used library version 0.13.0
  •  Used platform Android, via ComposeView
  •  Used support library version
  •  Used gradle build tools version 8.3.1
  •  Used tooling / Android Studio version Iguana 2023.2.1
  •  Other used libraries, potential conflicting libraries

Checklist

Set-up snapshot tests

About this issue

  • set-up snapshot tests using paparazzi

Details

  •  Used library version
  •  Used platform
  •  Used support library version
  •  Used gradle build tools version
  •  Used tooling / Android Studio version
  •  Other used libraries, potential conflicting libraries

Checklist

Feature: Allow to use custom components.

About this issue

It would be nice if I could use my own components for rendering.

Use Cases:

  • Render only a subset of components (e.g. only headings for a table of contents)
  • Decorate a component (e.g. add a "copy to clipboard" button to code)
  • Add custom logic (e.g. resolve relative URLs in links anmd images)

CompositionLocal ReferenceLinkHandler not present

About this issue

Using this composable to customize the text style appeareance, because just the Markdown composable does not look change as needed:

MarkdownText(
   modifier = Modifier
       .padding(
           start = 5.dp,
       ),
    content = "content",
    style = TextStyle(
        fontFamily = myCustomFontFamily
    )
)

the executions produces this trace:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: CompositionLocal ReferenceLinkHandler not present
	at com.mikepenz.markdown.compose.ComposeLocalKt$LocalReferenceLinkHandler$1.invoke(ComposeLocal.kt:25)
	at com.mikepenz.markdown.compose.ComposeLocalKt$LocalReferenceLinkHandler$1.invoke(ComposeLocal.kt:24)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:29)
	at androidx.compose.runtime.LazyValueHolder.getValue(ValueHolders.kt:31)
	at androidx.compose.runtime.CompositionLocalMapKt.read(CompositionLocalMap.kt:90)
	at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:2136)
	at com.mikepenz.markdown.compose.elements.MarkdownTextKt.MarkdownText(MarkdownText.kt:106)
	at com.mikepenz.markdown.compose.elements.MarkdownTextKt.MarkdownText(MarkdownText.kt:33

Details

  • [0.13.0] Used library version
  • [ Desktop] Used platform
  • [-m3 ] Used support library version

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.