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.

BlockCodeEntry (package com.srm.markdown_render) extends MarkwonAdapter.Entry<FencedCodeBlock, BlockCodeEntry.Holder> and tells MarkwonAdapter how to inflate and bind the custom fenced_code_view.xml layout for every FencedCodeBlock node encountered in a parsed markdown document. It is responsible for both inflating the view hierarchy and wiring the copy-to-clipboard ImageButton at bind time via the nested Holder.

Class constructor

class BlockCodeEntry(val ctx: Context) :
    MarkwonAdapter.Entry<FencedCodeBlock, BlockCodeEntry.Holder>()
ctx
Context
required
The Android Context stored as a public property on the class. It is forwarded to every Holder instance created by createHolder so the click listener inside Holder.init can call ctx.getSystemService(Context.CLIPBOARD_SERVICE) to obtain a ClipboardManager and Toast.makeText(ctx, …) to display confirmation feedback to the user.

createHolder

Overrides MarkwonAdapter.Entry.createHolder to inflate the fenced-code item layout and wrap it in a Holder.
override fun createHolder(p0: LayoutInflater, p1: ViewGroup): BlockCodeEntry.Holder
The method calls p0.inflate(R.layout.fenced_code_view, p1, false) to produce a non-attached root View, then passes that view together with ctx into Holder(…). The resulting Holder is returned to MarkwonAdapter, which retains it in the RecyclerView pool for reuse.

bindHolder

Overrides MarkwonAdapter.Entry.bindHolder to render the FencedCodeBlock AST node into the Holder’s TextView.
override fun bindHolder(p0: Markwon, p1: Holder, p2: FencedCodeBlock)
Calls p0.setParsedMarkdown(p1.commandText, p0.render(p2))p0.render(p2) converts the FencedCodeBlock node into Android Spanned text (applying Markwon’s code-block spans), and setParsedMarkdown applies that Spanned result directly to p1.commandText without triggering another parse pass.

Holder class

BlockCodeEntry.Holder extends MarkwonAdapter.Holder and owns the two interactive views inside fenced_code_view.xml.
class Holder(itemView: View, val ctx: Context) : MarkwonAdapter.Holder(itemView)

Fields

commandText
TextView
Bound to R.id.command via requireView<TextView>(R.id.command). Receives the rendered Spanned code text in bindHolder and its .text property is read by the copy button click listener.
btnCopy
ImageButton
Bound to R.id.copyCommand via requireView<ImageButton>(R.id.copyCommand). The copy action OnClickListener is attached to this button inside the init block.

init block — copy button wiring

The init block calls btnCopy.setOnClickListener { v -> … } with the following steps:
  1. Reads commandText.text.trim() to obtain the code text with leading/trailing whitespace removed.
  2. Obtains ClipboardManager via ctx.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager.
  3. Creates a ClipData with ClipData.newPlainText("Command", text).
  4. Calls clipBoard.setPrimaryClip(textClip) to write to the system clipboard.
  5. Shows a confirmation Toast with Toast.LENGTH_LONG that includes the first 7 characters of the copied text: "Code copied to clipboard! ${text.subSequence(1..7)} ...".

Full source

BlockCodeEntry.kt
/*
 * Copyright (c) 2026 tutosrive. All rights reserved.
 *
 * Author: tutosrive
 * GitHub: https://github.com/tutosrive
 *
 * This source code is PROPRIETARY and CONFIDENTIAL.
 * Unauthorized copying, modification, or distribution of this file,
 * via any medium, is strictly prohibited.
 *
 * This software is provided "as is", without warranty of any kind.
 * In no event shall the author be liable for any claim or damages.
 */

package com.srm.markdown_render

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import io.noties.markwon.Markwon
import io.noties.markwon.recycler.MarkwonAdapter
import org.commonmark.node.FencedCodeBlock

class BlockCodeEntry(val ctx: Context) :
    MarkwonAdapter.Entry<FencedCodeBlock, BlockCodeEntry.Holder>() {
    override fun createHolder(p0: LayoutInflater, p1: ViewGroup): BlockCodeEntry.Holder {
        return Holder(
            p0.inflate(
                R.layout.fenced_code_view,
                p1,
                false
            ),
            ctx
        )
    }

    override fun bindHolder(
        p0: Markwon,
        p1: Holder,
        p2: FencedCodeBlock
    ) {
        p0.setParsedMarkdown(p1.commandText, p0.render(p2))
    }

    class Holder(itemView: View, val ctx: Context) : MarkwonAdapter.Holder(itemView) {
        var commandText: TextView = requireView<TextView>(R.id.command)
        var btnCopy: ImageButton = requireView<ImageButton>(R.id.copyCommand)

        init {
            btnCopy.setOnClickListener { v ->
                val text = commandText.text.trim()
                val clipBoard = ctx.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
                val textClip = ClipData.newPlainText("Command", text)
                clipBoard.setPrimaryClip(textClip)
                Toast.makeText(
                    ctx,
                    "Code copied to clipboard! ${text.subSequence(1..7)} ...",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }
}

Build docs developers (and LLMs) love