Markwon
Markwon copied to clipboard
Style Spans not applied in editor
- Markwon version: 4.3.1
- As per the demo & instructions, I wrote down code to listen for TextChange and apply the markdown style.
- Even though the asterisk char's color changed, the bold did not get applied.
Here are my dependencies,
implementation "io.noties.markwon:core:$markwon_version"
implementation "io.noties.markwon:editor:$markwon_version"
implementation "io.noties.markwon:ext-strikethrough:$markwon_version"
implementation "io.noties.markwon:ext-tables:$markwon_version"
implementation "io.noties.markwon:ext-tasklist:$markwon_version"
implementation "io.noties.markwon:html:$markwon_version"
implementation "io.noties.markwon:image:$markwon_version"
implementation "io.noties.markwon:image-glide:$markwon_version"
implementation "io.noties.markwon:linkify:$markwon_version"
implementation "io.noties.markwon:simple-ext:$markwon_version"
implementation "io.noties.markwon:inline-parser:$markwon_version"
layout XML,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="none"
android:gravity="start|top"
android:inputType="text|textLongMessage|textMultiLine" />
</RelativeLayout>

Am I doing something wrong...
Hello @shivakumars !
Please share the code that you use to render markdown
Sure,
val markwon = Markwon.create(this@MainActivity)
val mdEditor = MarkwonEditor.create(markwon)
editor.addTextChangedListener(MarkwonEditorTextWatcher.withPreRender(
mdEditor,
Executors.newCachedThreadPool(),
editor))
Please refer to the documentation of how to additionally add styling whilst editing
Firstly, thank you for pointing me with the right way. I followed the document and now I could see the format is applied.
But When a markdown is typed as follows, "**b**" "**c**"
The second line is not getting formatted.
The above image from the APK built from the sample module in this repo.
I debugged the issue and at handleMarkdownSpan
, the span start I get for "**b**\n**c**" is 8. So the matcher tries to match "*c**". Please correct me if I'm wrong.
Hello @shivakumars !
This actually is a bug. I've looked at it briefly and it seems to be caused by a single new-line in markdown to be treated as a space. Text diffing fails (it considers **\n**
to be replaced with a
) and thus second span receives wrong position. This can be solved with markdown treating soft breaks as new lines. For example:
final Markwon markwon = Markwon.builder(this)
/* your other plugins */
.usePlugin(SoftBreakAddsNewLinePlugin.create())
.build();
Of cause this would mean that in display/preview mode this markdown should also treat soft breaks as new lines, otherwise content will be different
It actually is not a bug but a requirement for editor - soft breaks must be rendered as new lines (no matter how they are going to be rendered). Let me think how to seamlessly integrate it into editor