MCBFC (Markwon Copy Button for Fenced Code) is an Android reference and demo project — not a published library artifact — that shows how to extend the Markwon v4.6.2 RecyclerView adapter with a completely customDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/mcbfc/llms.txt
Use this file to discover all available pages before exploring further.
ViewHolder for fenced code blocks. The source is meant to be read, understood, and copied directly into your own app. It lives in the com.srm.markdown_render package and is built around two focused Kotlin classes and two XML layouts.
MCBFC is a reference implementation, not a library you add as a dependency. Clone the repository, study the code, then copy the relevant files into your own project and adapt them to fit your needs.
What problem does it solve?
The default MarkwonMarkwonAdapter renders every node — including fenced code blocks — as a plain TextView backed by adapter_default_entry.xml. That works fine for prose, but for code blocks it means:
- Long lines overflow or wrap unreadably with no horizontal scroll.
- There is no copy affordance — users cannot tap to copy code snippets.
- The block has no visual distinction from surrounding paragraph text unless you style the full
Markwontheme.
FencedCodeBlock rendering with a custom layout (fenced_code_view.xml) that wraps the code TextView inside a HorizontalScrollView — so long lines scroll instead of wrapping — and overlays an ImageButton copy icon. Tapping the button copies the entire block text to the system clipboard and shows a confirmation Toast.
Key capabilities
RecyclerView-based rendering
Renders markdown in a
RecyclerView via MarkwonAdapter, giving you smooth scrolling and efficient view recycling for arbitrarily long documents.Custom fenced code layout
Replaces the default code-block
ViewHolder with a HorizontalScrollView-wrapped TextView so wide code lines scroll horizontally rather than wrapping.One-tap clipboard copy
An overlay
ImageButton in every code block copies its full text to the system ClipboardManager with a single tap and shows a Toast confirmation.Minimal dependencies
Only two Markwon artifacts (
core and recycler at 4.6.2) on top of the standard AndroidX stack — no extra runtime required.How it works (overview)
The demo is built from two Kotlin classes and two XML layouts that work together:| File | Role |
|---|---|
markdown.kt | Wrapper class that owns the Markwon instance and the MarkwonAdapter. It registers BlockCodeEntry as the handler for every FencedCodeBlock node, configures the RecyclerView with a LinearLayoutManager, and exposes a single sett(text: String) method to parse and display markdown. |
BlockCodeEntry.kt | A MarkwonAdapter.Entry<FencedCodeBlock, BlockCodeEntry.Holder> that inflates fenced_code_view.xml for every code block. Its inner Holder class holds references to the TextView (R.id.command) and ImageButton (R.id.copyCommand) and wires up the copy-to-clipboard click listener. |
fenced_code_view.xml | The custom item layout for fenced code blocks — a HorizontalScrollView containing a monospaced TextView, with an ImageButton overlaid for the copy action. |
adapter_default_entry.xml | The fallback item layout used by MarkwonAdapter.builderTextViewIsRoot(...) for all non-code nodes (headings, paragraphs, lists, etc.). |
MainActivity wires everything together in two lines:
getRawTest() reads a raw markdown file from res/raw/test_markdown and passes it to sett(), which calls adapter.setMarkdown() followed by notifyDataSetChanged().
Requirements
| Requirement | Value |
|---|---|
| Minimum SDK | API 24 (Android 7.0 Nougat) |
| Target SDK | API 36 |
| Language | Kotlin (Java 11 source/target compatibility) |
| JDK | 21 (must include Kotlin toolchain) |
| Gradle | 9.4.1 — or use the included Gradle wrapper (gradlew) |
| IDE | Android Studio (recommended) or any CLI with the Gradle wrapper |