Gogledd-Orllewin

Archive

Programs

Merkja

Repository: Merkja-master.zip

This was an old Android (pre Compose) little class that rendered Markdown files.

Old description

A very simple single class Markdown renderer for when you only need the basic syntax and don't want to add a 3rd-party dependency. Warning: Contains hacky regex and span mangling, I have no idea how unoptimised it is. There is no error checking and if you pass anything other than really simple markdown it will break. It's not meant to be a replacement for a full-featured library, if you need full Markdown support use Markwon This isn't a library, just copy the Merkja class to your project.

Simple

text_view.text = markdownString
Merkja(text_view).render()

Handling Links and Images

text_view.text = markdownString
        
val merkja = Merkja(text_view) { matchEvent ->

    when (matchEvent.schemeType){
        Merkja.SCHEME_IMAGE -> loadImage(matchEvent)
        Merkja.SCHEME_LINK -> handleLink(matchEvent)
    }
}
merkja.render()

...

fun loadImage(matchEvent: MatchEvent){
    val imageUrl = matchEvent.value
    //fetch image async then:
    runOnUiThread {
        merkja.insertImage(bitmap, matchEvent)
    }
}