Skip to content

Commit

Permalink
Add markdown extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Aug 25, 2024
1 parent b9d249a commit 0bc951a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
extra.apply {
set("groupId", "com.kylecorry.andromeda")
set("versionName", "10.0.0")
set("versionName", "10.1.0")
set("targetVersion", 35)
set("compileVersion", 35)
}
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tensorflow-lite-support = { module = "org.tensorflow:tensorflow-lite-support", v
markwon = { module = "io.noties.markwon:core", version.ref = "markwonVersion" }
markwon-linkify = { module = "io.noties.markwon:linkify", version.ref = "markwonVersion" }
markwon-image = { module = "io.noties.markwon:image", version.ref = "markwonVersion" }
markwon-simple = { module = "io.noties.markwon:simple-ext", version.ref = "markwonVersion" }
gson = { module = "com.google.code.gson:gson", version.ref = "gsonVersion" }
junit = { module = "junit:junit", version.ref = "junitVersion" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junitJupiterApiVersion" }
Expand Down
1 change: 1 addition & 0 deletions markdown/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies {
implementation libs.markwon
implementation libs.markwon.linkify
implementation libs.markwon.image
implementation libs.markwon.simple
coreLibraryDesugaring libs.desugar
androidTestImplementation libs.androidx.junit
androidTestImplementation libs.androidx.espresso.core
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kylecorry.andromeda.markdown

import android.text.Spannable

class MarkdownExtension(
val length: Int,
val openingCharacter: Char,
val closingCharacter: Char = openingCharacter,
val spanProducer: () -> Any
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Rect
import android.text.Spanned
import android.widget.TextView
import androidx.core.text.util.LinkifyCompat
import io.noties.markwon.AbstractMarkwonPlugin
import io.noties.markwon.Markwon
import io.noties.markwon.MarkwonConfiguration
Expand All @@ -16,11 +15,13 @@ import io.noties.markwon.image.ImageSizeResolverDef
import io.noties.markwon.image.ImagesPlugin
import io.noties.markwon.image.file.FileSchemeHandler
import io.noties.markwon.linkify.LinkifyPlugin
import io.noties.markwon.simple.ext.SimpleExtPlugin
import org.commonmark.node.ListItem

class MarkdownService(
private val context: Context,
private val autoLink: Boolean = true
private val autoLink: Boolean = true,
private val extensions: List<MarkdownExtension> = emptyList()
) {
private val markwon by lazy {
val builder = Markwon.builder(context)
Expand All @@ -43,6 +44,14 @@ class MarkdownService(
it.addSchemeHandler(FileSchemeHandler.createWithAssets(context))
})

builder.usePlugin(SimpleExtPlugin.create {
extensions.forEach { ext ->
it.addExtension(ext.length, ext.openingCharacter, ext.closingCharacter) { _, _ ->
ext.spanProducer()
}
}
})

if (autoLink) {
builder.usePlugin(LinkifyPlugin.create(true))
}
Expand Down

0 comments on commit 0bc951a

Please sign in to comment.