Skip to main content

Documentation 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.

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 custom 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 Markwon MarkwonAdapter 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 Markwon theme.
MCBFC replaces the default 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:
FileRole
markdown.ktWrapper 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.ktA 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.xmlThe custom item layout for fenced code blocks — a HorizontalScrollView containing a monospaced TextView, with an ImageButton overlaid for the copy action.
adapter_default_entry.xmlThe fallback item layout used by MarkwonAdapter.builderTextViewIsRoot(...) for all non-code nodes (headings, paragraphs, lists, etc.).
MainActivity wires everything together in two lines:
val mark = markdown(this, findViewById(R.id.recyclerMark))
mark.sett(getRawTest())
getRawTest() reads a raw markdown file from res/raw/test_markdown and passes it to sett(), which calls adapter.setMarkdown() followed by notifyDataSetChanged().

Requirements

RequirementValue
Minimum SDKAPI 24 (Android 7.0 Nougat)
Target SDKAPI 36
LanguageKotlin (Java 11 source/target compatibility)
JDK21 (must include Kotlin toolchain)
Gradle9.4.1 — or use the included Gradle wrapper (gradlew)
IDEAndroid Studio (recommended) or any CLI with the Gradle wrapper

License

MCBFC is licensed under the GNU General Public License v3.0. You are free to use, modify, and distribute the code under the terms of that license.

Build docs developers (and LLMs) love