Update sample project

This commit is contained in:
chengjunzhang61 2021-12-09 04:57:57 -08:00
parent 677ad9dc55
commit 687c67a12b
2 changed files with 47 additions and 35 deletions

View File

@ -6,6 +6,7 @@ import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.View import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.annotation.NonNull import androidx.annotation.NonNull
@ -22,13 +23,18 @@ import io.noties.markwon.app.utils.ReadMeUtils
import io.noties.markwon.app.utils.hidden import io.noties.markwon.app.utils.hidden
import io.noties.markwon.app.utils.loadReadMe import io.noties.markwon.app.utils.loadReadMe
import io.noties.markwon.app.utils.textOrHide import io.noties.markwon.app.utils.textOrHide
import io.noties.markwon.core.CorePlugin
import io.noties.markwon.emoji.ext.EmojiPlugin
import io.noties.markwon.emoji.ext.EmojiSpanProvider
import io.noties.markwon.ext.inlinelatex.InLineLatexPlugIn import io.noties.markwon.ext.inlinelatex.InLineLatexPlugIn
import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathPlugin
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin import io.noties.markwon.ext.strikethrough.StrikethroughPlugin
import io.noties.markwon.ext.tasklist.TaskListPlugin import io.noties.markwon.ext.tasklist.TaskListPlugin
import io.noties.markwon.html.HtmlPlugin import io.noties.markwon.html.HtmlPlugin
import io.noties.markwon.iframe.ext.IFramePlugIn import io.noties.markwon.iframe.ext.IFramePlugIn
import io.noties.markwon.image.ImageClickResolver
import io.noties.markwon.image.ImagesPlugin import io.noties.markwon.image.ImagesPlugin
import io.noties.markwon.image.glide.GlideImagesPlugin
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin
import io.noties.markwon.recycler.MarkwonAdapter import io.noties.markwon.recycler.MarkwonAdapter
import io.noties.markwon.recycler.SimpleEntry import io.noties.markwon.recycler.SimpleEntry
@ -69,36 +75,42 @@ class ReadMeActivity : Activity() {
private val markwon: Markwon private val markwon: Markwon
get() = Markwon.builder(this) get() = Markwon.builder(this)
.usePlugin(ImagesPlugin.create()) .usePlugin(CorePlugin.create().addImageClickResolver(object: ImageClickResolver {
.usePlugin(HtmlPlugin.create()) override fun clickResolve(view: View, link: String) {
.usePlugin(TableEntryPlugin.create(this)) Log.d("ImageClick", link)
.usePlugin(SyntaxHighlightPlugin.create(Prism4j(GrammarLocatorDef()), Prism4jThemeDefault.create(0))) }
.usePlugin(TaskListPlugin.create(this)) }))
.usePlugin(StrikethroughPlugin.create()) .usePlugin(HtmlPlugin.create())
.usePlugin(ReadMeImageDestinationPlugin(intent.data)) .usePlugin(TableEntryPlugin.create(this))
.usePlugin(IFramePlugIn.create()) .usePlugin(SyntaxHighlightPlugin.create(Prism4j(GrammarLocatorDef()), Prism4jThemeDefault.create(0)))
.usePlugin(InLineLatexPlugIn.create(46.0f, 1080)) .usePlugin(TaskListPlugin.create(this))
.usePlugin(MarkwonInlineParserPlugin.create()) .usePlugin(StrikethroughPlugin.create())
.usePlugin(JLatexMathPlugin.create(46.0f)) .usePlugin(ReadMeImageDestinationPlugin(intent.data))
.usePlugin(object : AbstractMarkwonPlugin() { .usePlugin(IFramePlugIn.create())
override fun configureVisitor(builder: MarkwonVisitor.Builder) { .usePlugin(GlideImagesPlugin.create(this))
builder.on(FencedCodeBlock::class.java) { visitor, block -> .usePlugin(EmojiPlugin.create(EmojiSpanProvider.create(this, 36.0f)))
// we actually won't be applying code spans here, as our custom view will .usePlugin(InLineLatexPlugIn.create(46.0f, 1080))
// draw background and apply mono typeface .usePlugin(MarkwonInlineParserPlugin.create())
// .usePlugin(JLatexMathPlugin.create(46.0f))
// NB the `trim` operation on literal (as code will have a new line at the end) .usePlugin(object : AbstractMarkwonPlugin() {
val code = visitor.configuration() override fun configureVisitor(builder: MarkwonVisitor.Builder) {
.syntaxHighlight() builder.on(FencedCodeBlock::class.java) { visitor, block ->
.highlight(block.info, block.literal.trim()) // we actually won't be applying code spans here, as our custom view will
visitor.builder().append(code) // draw background and apply mono typeface
} //
// NB the `trim` operation on literal (as code will have a new line at the end)
val code = visitor.configuration()
.syntaxHighlight()
.highlight(block.info, block.literal.trim())
visitor.builder().append(code)
} }
}
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) { override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
builder.linkResolver(ReadMeLinkResolver()) builder.linkResolver(ReadMeLinkResolver())
} }
}) })
.build() .build()
private fun initAppBar(data: Uri?) { private fun initAppBar(data: Uri?) {
val appBar = findViewById<View>(R.id.app_bar) val appBar = findViewById<View>(R.id.app_bar)

View File

@ -16,13 +16,13 @@ include ':markwon-core',
':markwon-recycler-table', ':markwon-recycler-table',
':markwon-simple-ext', ':markwon-simple-ext',
':markwon-syntax-highlight', ':markwon-syntax-highlight',
':markwon-test-span' ':markwon-test-span',
':markwon-iframe-ext',
':markwon-emoji',
':markwon-span-ext',
':markwon-ext-inline-latex',
':markwon-ext-inline',
':markwon-round-textview'
include ':app-sample' include ':app-sample'
include ':sample-utils:processor' include ':sample-utils:processor'
include ':markwon-iframe-ext'
include ':markwon-emoji'
include ':markwon-span-ext'
include ':markwon-ext-inline-latex'
include ':markwon-ext-inline'
include ':markwon-round-textview'