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.

The markdown class (package com.srm.markdown_render) is a convenience wrapper that consolidates all Markwon setup into a single, reusable object. On construction it builds a Markwon instance via Markwon.builder(ctx).build(), creates a MarkwonAdapter configured with the custom BlockCodeEntry for fenced code blocks, and fully wires both to the supplied RecyclerView — setting its layoutManager, itemAnimator, and adapter in one shot.

Constructor

class markdown(val ctx: Context, view: RecyclerView)
ctx
Context
required
The Android Context used to build the Markwon instance and passed directly to BlockCodeEntry so its Holder can access ClipboardManager and display Toast messages when the copy button is tapped.
view
RecyclerView
required
The RecyclerView that will display the rendered markdown. The constructor assigns a LinearLayoutManager, a DefaultItemAnimator, and the internally created MarkwonAdapter to this view — no additional setup is required on the call site.

Methods

sett(text: String)

Parses and renders a new markdown document into the RecyclerView.
text
String
required
The raw markdown string to parse and display. The string is handed directly to adapter.setMarkdown(mark, text), which splits the document into individual AST nodes — each rendered by the appropriate Entry (either the root TextView or BlockCodeEntry for fenced code blocks). After updating the data set, adapter.notifyDataSetChanged() is called to invalidate and redraw all items.
Usage example
val renderer = markdown(this, recyclerView)
renderer.sett("# Hello\n```kotlin\nprintln(\"world\")\n```")

Internal fields

mark
Markwon
Built once in the init block via Markwon.builder(ctx).build(). Holds the configured Markwon instance responsible for parsing CommonMark text and converting AST nodes into Android Spanned text. Passed to the adapter methods setMarkdown and setParsedMarkdown.
adapter
MarkwonAdapter
Built with MarkwonAdapter.builderTextViewIsRoot(R.layout.adapter_default_entry), which designates adapter_default_entry.xml as the default item layout for all non-code nodes. A BlockCodeEntry is registered via .include<FencedCodeBlock>(FencedCodeBlock::class.java, BlockCodeEntry(ctx)) so every FencedCodeBlock AST node is inflated and bound using the custom fenced-code layout instead. Assigned to the RecyclerView at the end of init.

Full source

markdown.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.Context
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.noties.markwon.Markwon
import io.noties.markwon.recycler.MarkwonAdapter
import org.commonmark.node.FencedCodeBlock

class markdown(val ctx: Context, view: RecyclerView) {
    private var mark: Markwon = Markwon.builder(ctx).build()
    private var adapter: MarkwonAdapter

    init {

        adapter = MarkwonAdapter
            .builderTextViewIsRoot(R.layout.adapter_default_entry)
            .include<FencedCodeBlock>(FencedCodeBlock::class.java, BlockCodeEntry(ctx))
            .build()
        view.layoutManager = LinearLayoutManager(ctx)
        view.itemAnimator = DefaultItemAnimator()
        view.adapter = adapter

    }

    fun sett(text: String) {
        this.adapter.setMarkdown(this.mark, text)
        this.adapter.notifyDataSetChanged()
    }
}

Build docs developers (and LLMs) love