mikepenz/multiplatform-markdown-renderer

Feature request: TextAlign

Stuart-campbell opened this issue · 2 comments

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

Apologies for the late answer.

Yes, this is already possible with the current version of the library. You can define the TextStyle used for all the used components. E.g. for all paragraphs for example.

Here is a short example:

Markdown(
    content,
    typography = markdownTypography(
        paragraph = MaterialTheme.typography.body1.copy(
            textAlign = TextAlign.End
        )
    ),
    modifier = Modifier.fillMaxSize().padding(16.dp).verticalScroll(scrollState),
)

It is worth noting, text is not filling the full line, so if you want the text itself to align on the right side of the view, you very likely want to define a custom markdown components.

So something like this (this will require 0.11.0 as before that the MarkdownParagraph had internal visibility):

val customParagraphComponent: MarkdownComponent = {
    MarkdownParagraph(it.content, it.node, Modifier.align(Alignment.End), it.typography.paragraph)
}

Markdown(
    content,
    modifier = Modifier.fillMaxSize().padding(16.dp).verticalScroll(scrollState),
    components = markdownComponents(
        paragraph = customParagraphComponent
    )
)

v0.11.0 was released, and v0.12.0 will later today.

I hope that answers your question.