Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown libraries don't support a single \n in android

I tried a couple of markdown support libraries and they all seem to work except for one fact which they all have in common. They don't recognize a single \n , unless I enter \n\n. The libraries I have used are commonmark/ markwon/ bypass. No luck with any of them yet. Anyone else had a similar issue? P.S: the text I am applying a markdown on is uneditable and returned from an API ,

something like "text" = __this__: __name__  \n __that__ : __name__ 

Any idea how to go about that?


2 Answers

I had the same problem and found a solution.

I used the Markwon library with the following plugin, as mentioned in the Markwon Docs.

Since 4.3.0 there is a dedicated plugin to insert a new line for markdown soft breaks - SoftBreakAddsNewLinePlugin:

   final Markwon markwon = Markwon.builder(this)
        .usePlugin(SoftBreakAddsNewLinePlugin.create())
        .build();

This works because a /n is parsed as a softbreak according to the CommonMark Spec.

like image 82
Darvan42 Avatar answered Mar 09 '26 22:03

Darvan42


A single newline has no meaning in Markdown.

For example, the first sentence that I typed into this answer really looks like:

A
single
newline
has
no
meaning
in
Markdown.

A blank line (e.g., two newlines) serves as a block separator for paragraphs, etc.

like image 35
CommonsWare Avatar answered Mar 09 '26 20:03

CommonsWare