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.
BlockCodeEntry is the core customization point in MCBFC. It tells MarkwonAdapter how to create and bind a ViewHolder whenever it encounters a FencedCodeBlock node in the parsed CommonMark AST. Without it, fenced code blocks would fall through to the default TextView entry and lose the horizontal scrolling container and copy button that make code blocks genuinely usable on a narrow phone screen.
MarkwonAdapter.Entry contract
Every customEntry must implement two methods:
createHolder(inflater, parent)— called once per new item view. Inflate your custom XML layout here and wrap the resulting root view in yourHoldersubclass.MarkwonAdaptercaches holders via the standardRecyclerViewrecycling mechanism, so this method is only called as many times as needed to fill the screen plus a small buffer.bindHolder(markwon, holder, node)— called every time an existing holder is bound to a (possibly different)FencedCodeBlocknode. Usemarkwon.setParsedMarkdown(textView, markwon.render(node))to convert the raw AST node into AndroidSpannedtext and apply it to theTextView. This is also where you would update any other views in the holder (language labels, line counts, etc.).
BlockCodeEntry source
BlockCodeEntry.kt
Creating the ViewHolder
createHolder inflates R.layout.fenced_code_view with attachToRoot = false (the third argument) and hands the resulting root view to BlockCodeEntry.Holder along with the Context needed for clipboard access.
fenced_code_view.xml
FrameLayout as its root so both the ImageButton and the HorizontalScrollView occupy the same space and can be layered independently via their elevation attributes. The horizontal scroll view lets long lines of code scroll left and right without wrapping, which is essential for readability on narrow screens.
Binding markdown to the ViewHolder
bindHolder receives the live Markwon instance (p0), the recycled Holder (p1), and the FencedCodeBlock AST node (p2). The single call:
p0.render(p2)— walks theFencedCodeBlocknode and produces aSpannedstring that carries all Markwon style spans (monospace font, syntax-highlight colours if a highlight plugin is installed, etc.).p0.setParsedMarkdown(p1.commandText, …)— sets theSpannedtext oncommandTextand triggers any Markwon post-processors that need a live view reference (image loaders, async tasks, etc.).
The Holder class
BlockCodeEntry.Holder extends MarkwonAdapter.Holder and holds two view references resolved at construction time:
commandText— theTextViewnested inside theHorizontalScrollView. This is where the formatted code text is displayed.btnCopy— theImageButtonfloating above the scroll view. Its click listener is wired once ininitand remains active for the lifetime of the holder, correctly picking up whatever code text has been bound most recently because it readscommandText.textat click time rather than capturing the text at bind time.
requireView<T>(id) is a helper method provided by MarkwonAdapter.Holder. Unlike findViewById, which returns null when the view is missing, requireView throws an IllegalStateException immediately during Holder construction if the requested id is not found. This fail-fast behaviour surfaces layout mismatches at development time rather than as a silent NullPointerException when a user taps the button.