├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── dev
│ │ │ │ └── baseio
│ │ │ │ └── kmarkdown
│ │ │ │ ├── sample
│ │ │ │ ├── ui
│ │ │ │ │ └── theme
│ │ │ │ │ │ ├── Color.kt
│ │ │ │ │ │ └── Theme.kt
│ │ │ │ ├── MainActivity.kt
│ │ │ │ └── TestMD.kt
│ │ │ │ └── lib
│ │ │ │ ├── KMarkdownStyles.kt
│ │ │ │ ├── KMarkdownElement.kt
│ │ │ │ └── KMarkdown.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── dev
│ │ │ └── baseio
│ │ │ └── kmarkdown
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── dev
│ │ └── baseio
│ │ └── kmarkdown
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle.kts
├── .idea
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── migrations.xml
├── deploymentTargetSelector.xml
├── misc.xml
├── gradle.xml
└── other.xml
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── settings.gradle.kts
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KMarkdown
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/KMarkdown/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 17 17:49:28 IST 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetSelector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/sample/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.sample.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple80 = Color(0xFFD0BCFF)
6 | val PurpleGrey80 = Color(0xFFCCC2DC)
7 | val Pink80 = Color(0xFFEFB8C8)
8 |
9 | val Purple40 = Color(0xFF6650a4)
10 | val PurpleGrey40 = Color(0xFF625b71)
11 | val Pink40 = Color(0xFF7D5260)
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/dev/baseio/kmarkdown/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/sample/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.sample.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.runtime.Composable
5 |
6 | @Composable
7 | fun KMarkdownTheme(
8 | darkTheme: Boolean = isSystemInDarkTheme(),
9 | // Dynamic color is available on Android 12+
10 | dynamicColor: Boolean = true,
11 | content: @Composable () -> Unit
12 | ) {
13 | content()
14 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google {
4 | content {
5 | includeGroupByRegex("com\\.android.*")
6 | includeGroupByRegex("com\\.google.*")
7 | includeGroupByRegex("androidx.*")
8 | }
9 | }
10 | mavenCentral()
11 | gradlePluginPortal()
12 | }
13 | }
14 | dependencyResolutionManagement {
15 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
16 | repositories {
17 | google()
18 | mavenCentral()
19 | }
20 | }
21 |
22 | rootProject.name = "KMarkdown"
23 | include(":app")
24 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/dev/baseio/kmarkdown/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("dev.baseio.kmarkdown", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.sample
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.activity.enableEdgeToEdge
7 | import androidx.compose.foundation.layout.fillMaxSize
8 | import androidx.compose.foundation.layout.padding
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.unit.dp
11 | import dev.baseio.kmarkdown.lib.KMarkdown
12 | import dev.baseio.kmarkdown.lib.KMarkdownStyles
13 | import dev.baseio.kmarkdown.sample.ui.theme.KMarkdownTheme
14 |
15 | class MainActivity : ComponentActivity() {
16 | override fun onCreate(savedInstanceState: Bundle?) {
17 | super.onCreate(savedInstanceState)
18 | enableEdgeToEdge()
19 | setContent {
20 | KMarkdownTheme {
21 | KMarkdown(
22 | markdownContent = TEST_MD,
23 | modifier = Modifier
24 | .fillMaxSize()
25 | .padding(vertical = 24.dp),
26 | styles = KMarkdownStyles()
27 | )
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
18 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/lib/KMarkdownStyles.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.lib
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.ui.graphics.Color
5 | import androidx.compose.ui.graphics.Shape
6 | import androidx.compose.ui.text.TextStyle
7 | import androidx.compose.ui.text.font.FontWeight
8 | import androidx.compose.ui.unit.DpSize
9 | import androidx.compose.ui.unit.dp
10 | import androidx.compose.ui.unit.sp
11 |
12 | data class KMarkdownStyles(
13 | val kMarkdownTypography: KMarkdownTypography = KMarkdownTypography(),
14 | val blockQuoteBG: Color = Color(0x34242424),
15 | val blockQuoteShape: Shape = RoundedCornerShape(12.dp),
16 | val imageSize: DpSize = DpSize(200.dp, 200.dp)
17 | )
18 |
19 | data class KMarkdownTypography(
20 | val textStyle: TextStyle = TextStyle(
21 | fontSize = 16.sp,
22 | fontWeight = FontWeight.Normal,
23 | ),
24 | val setext1Style: TextStyle = TextStyle(
25 | fontSize = 18.sp,
26 | fontWeight = FontWeight.Normal,
27 | ),
28 | val setext2Style: TextStyle = TextStyle(
29 | fontSize = 16.sp,
30 | fontWeight = FontWeight.Normal,
31 | ),
32 | val heading1: TextStyle = TextStyle(
33 | fontSize = 32.sp,
34 | fontWeight = FontWeight.Normal,
35 | ),
36 | val heading2: TextStyle = TextStyle(
37 | fontSize = 30.sp,
38 | fontWeight = FontWeight.Normal,
39 | ),
40 | val heading3: TextStyle = TextStyle(
41 | fontSize = 28.sp,
42 | fontWeight = FontWeight.Normal,
43 | ),
44 | val heading4: TextStyle = TextStyle(
45 | fontSize = 26.sp,
46 | fontWeight = FontWeight.Normal,
47 | ),
48 | val heading5: TextStyle = TextStyle(
49 | fontSize = 24.sp,
50 | fontWeight = FontWeight.Normal,
51 | ),
52 | val heading6: TextStyle = TextStyle(
53 | fontSize = 22.sp,
54 | fontWeight = FontWeight.Normal,
55 | ),
56 | )
57 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.5.2"
3 | coilCompose = "2.7.0"
4 | foundationAndroidVersion = "1.6.8"
5 | kotlin = "2.0.10"
6 | coreKtx = "1.13.1"
7 | junit = "4.13.2"
8 | junitVersion = "1.2.1"
9 | espressoCore = "3.6.1"
10 | lifecycleRuntimeKtx = "2.8.4"
11 | activityCompose = "1.9.1"
12 | composeBom = "2024.06.00"
13 | markdown = "0.7.3"
14 |
15 | [libraries]
16 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
17 | coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
18 | foundation-android = { module = "androidx.compose.foundation:foundation-android", version.ref = "foundationAndroidVersion" }
19 | junit = { group = "junit", name = "junit", version.ref = "junit" }
20 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
21 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
22 | androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
23 | androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
24 | androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
25 | androidx-ui = { group = "androidx.compose.ui", name = "ui" }
26 | androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
27 | androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
28 | androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
29 | androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
30 | androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
31 | markdown = { module = "org.jetbrains:markdown", version.ref = "markdown" }
32 |
33 | [plugins]
34 | android-application = { id = "com.android.application", version.ref = "agp" }
35 | jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
36 | compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
37 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | alias(libs.plugins.jetbrains.kotlin.android)
4 | alias(libs.plugins.compose.compiler)
5 | }
6 |
7 | android {
8 | namespace = "dev.baseio.kmarkdown"
9 | compileSdk = 34
10 |
11 | defaultConfig {
12 | applicationId = "dev.baseio.kmarkdown"
13 | minSdk = 21
14 | targetSdk = 34
15 | versionCode = 1
16 | versionName = "1.0"
17 |
18 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19 | vectorDrawables {
20 | useSupportLibrary = true
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | isMinifyEnabled = false
27 | proguardFiles(
28 | getDefaultProguardFile("proguard-android-optimize.txt"),
29 | "proguard-rules.pro"
30 | )
31 | }
32 | }
33 | compileOptions {
34 | sourceCompatibility = JavaVersion.VERSION_1_8
35 | targetCompatibility = JavaVersion.VERSION_1_8
36 | }
37 | kotlinOptions {
38 | jvmTarget = "1.8"
39 | }
40 | buildFeatures {
41 | compose = true
42 | }
43 | packaging {
44 | resources {
45 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
46 | }
47 | }
48 | }
49 |
50 | dependencies {
51 | implementation(libs.markdown)
52 | implementation(libs.coil.compose)
53 |
54 | implementation(libs.androidx.core.ktx)
55 | implementation(libs.androidx.lifecycle.runtime.ktx)
56 | implementation(libs.androidx.activity.compose)
57 | implementation(platform(libs.androidx.compose.bom))
58 | implementation(libs.androidx.ui)
59 | implementation(libs.androidx.ui.graphics)
60 | implementation(libs.androidx.ui.tooling.preview)
61 | implementation(libs.foundation.android)
62 |
63 | testImplementation(libs.junit)
64 | androidTestImplementation(libs.androidx.junit)
65 | androidTestImplementation(libs.androidx.espresso.core)
66 | androidTestImplementation(platform(libs.androidx.compose.bom))
67 | androidTestImplementation(libs.androidx.ui.test.junit4)
68 | debugImplementation(libs.androidx.ui.tooling)
69 | debugImplementation(libs.androidx.ui.test.manifest)
70 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/lib/KMarkdownElement.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.lib
2 |
3 | import org.intellij.markdown.IElementType
4 | import org.intellij.markdown.MarkdownElementTypes
5 | import org.intellij.markdown.MarkdownTokenTypes
6 |
7 | sealed class KMarkdownElement {
8 | object MarkdownFile : KMarkdownElement()
9 | object UnorderedList : KMarkdownElement()
10 | object OrderedList : KMarkdownElement()
11 | object ListItem : KMarkdownElement()
12 | object BlockQuote : KMarkdownElement()
13 | object CodeFence : KMarkdownElement()
14 | object CodeBlock : KMarkdownElement()
15 | object CodeSpan : KMarkdownElement()
16 | object HtmlBlock : KMarkdownElement()
17 | object Paragraph : KMarkdownElement()
18 | object Emph : KMarkdownElement()
19 | object Strong : KMarkdownElement()
20 | object LinkDefinition : KMarkdownElement()
21 | object LinkLabel : KMarkdownElement()
22 | object LinkDestination : KMarkdownElement()
23 | object LinkTitle : KMarkdownElement()
24 | object LinkText : KMarkdownElement()
25 | object InlineLink : KMarkdownElement()
26 | object FullReferenceLink : KMarkdownElement()
27 | object ShortReferenceLink : KMarkdownElement()
28 | object Image : KMarkdownElement()
29 | object Autolink : KMarkdownElement()
30 | object Setext1 : KMarkdownElement()
31 | object Setext2 : KMarkdownElement()
32 | object Atx1 : KMarkdownElement()
33 | object Atx2 : KMarkdownElement()
34 | object Atx3 : KMarkdownElement()
35 | object Atx4 : KMarkdownElement()
36 | object Atx5 : KMarkdownElement()
37 | object Atx6 : KMarkdownElement()
38 |
39 | // From MarkdownTokenTypes
40 | object Text : KMarkdownElement()
41 | object CodeLine : KMarkdownElement()
42 | object BlockQuoteToken : KMarkdownElement() // Renamed to avoid conflict
43 | object HtmlBlockContent : KMarkdownElement()
44 | object SingleQuote : KMarkdownElement()
45 | object DoubleQuote : KMarkdownElement()
46 | object LParen : KMarkdownElement()
47 | object RParen : KMarkdownElement()
48 | object LBracket : KMarkdownElement()
49 | object RBracket : KMarkdownElement()
50 | object Lt : KMarkdownElement()
51 | object Gt : KMarkdownElement()
52 | object Colon : KMarkdownElement()
53 | object ExclamationMark : KMarkdownElement()
54 | object HardLineBreak : KMarkdownElement()
55 | object Eol : KMarkdownElement()
56 | object LinkId : KMarkdownElement()
57 | object AtxHeader : KMarkdownElement()
58 | object AtxContent : KMarkdownElement()
59 | object SetextContent : KMarkdownElement()
60 | object Backtick : KMarkdownElement()
61 | object EscapedBackticks : KMarkdownElement()
62 | object ListBullet : KMarkdownElement()
63 | object Url : KMarkdownElement()
64 | object HorizontalRule : KMarkdownElement()
65 | object ListNumber : KMarkdownElement()
66 | object FenceLang : KMarkdownElement()
67 | object CodeFenceStart : KMarkdownElement()
68 | object CodeFenceContent : KMarkdownElement()
69 | object CodeFenceEnd : KMarkdownElement()
70 | object EmailAutolink : KMarkdownElement()
71 | object HtmlTag : KMarkdownElement()
72 | object BadCharacter : KMarkdownElement()
73 | object WhiteSpace : KMarkdownElement()
74 | }
75 |
76 | fun IElementType.toMarkdownElement(): KMarkdownElement {
77 | return when (this) {
78 | MarkdownElementTypes.MARKDOWN_FILE -> KMarkdownElement.MarkdownFile
79 | MarkdownElementTypes.UNORDERED_LIST -> KMarkdownElement.UnorderedList
80 | MarkdownElementTypes.ORDERED_LIST -> KMarkdownElement.OrderedList
81 | MarkdownElementTypes.LIST_ITEM -> KMarkdownElement.ListItem
82 | MarkdownElementTypes.BLOCK_QUOTE -> KMarkdownElement.BlockQuote
83 | MarkdownElementTypes.CODE_FENCE -> KMarkdownElement.CodeFence
84 | MarkdownElementTypes.CODE_BLOCK -> KMarkdownElement.CodeBlock
85 | MarkdownElementTypes.CODE_SPAN -> KMarkdownElement.CodeSpan
86 | MarkdownElementTypes.HTML_BLOCK -> KMarkdownElement.HtmlBlock
87 | MarkdownElementTypes.PARAGRAPH -> KMarkdownElement.Paragraph
88 | MarkdownElementTypes.EMPH -> KMarkdownElement.Emph
89 | MarkdownElementTypes.STRONG -> KMarkdownElement.Strong
90 | MarkdownElementTypes.LINK_DEFINITION -> KMarkdownElement.LinkDefinition
91 | MarkdownElementTypes.LINK_LABEL -> KMarkdownElement.LinkLabel
92 | MarkdownElementTypes.LINK_DESTINATION -> KMarkdownElement.LinkDestination
93 | MarkdownElementTypes.LINK_TITLE -> KMarkdownElement.LinkTitle
94 | MarkdownElementTypes.LINK_TEXT -> KMarkdownElement.LinkText
95 | MarkdownElementTypes.INLINE_LINK -> KMarkdownElement.InlineLink
96 | MarkdownElementTypes.FULL_REFERENCE_LINK -> KMarkdownElement.FullReferenceLink
97 | MarkdownElementTypes.SHORT_REFERENCE_LINK -> KMarkdownElement.ShortReferenceLink
98 | MarkdownElementTypes.IMAGE -> KMarkdownElement.Image
99 | MarkdownElementTypes.AUTOLINK -> KMarkdownElement.Autolink
100 | MarkdownElementTypes.SETEXT_1 -> KMarkdownElement.Setext1
101 | MarkdownElementTypes.SETEXT_2 -> KMarkdownElement.Setext2
102 | MarkdownElementTypes.ATX_1 -> KMarkdownElement.Atx1
103 | MarkdownElementTypes.ATX_2 -> KMarkdownElement.Atx2
104 | MarkdownElementTypes.ATX_3 -> KMarkdownElement.Atx3
105 | MarkdownElementTypes.ATX_4 -> KMarkdownElement.Atx4
106 | MarkdownElementTypes.ATX_5 -> KMarkdownElement.Atx5
107 | MarkdownElementTypes.ATX_6 -> KMarkdownElement.Atx6
108 |
109 | // From MarkdownTokenTypes
110 | MarkdownTokenTypes.TEXT -> KMarkdownElement.Text
111 | MarkdownTokenTypes.CODE_LINE -> KMarkdownElement.CodeLine
112 | MarkdownTokenTypes.BLOCK_QUOTE -> KMarkdownElement.BlockQuoteToken
113 | MarkdownTokenTypes.HTML_BLOCK_CONTENT -> KMarkdownElement.HtmlBlockContent
114 | MarkdownTokenTypes.SINGLE_QUOTE -> KMarkdownElement.SingleQuote
115 | MarkdownTokenTypes.DOUBLE_QUOTE -> KMarkdownElement.DoubleQuote
116 | MarkdownTokenTypes.LPAREN -> KMarkdownElement.LParen
117 | MarkdownTokenTypes.RPAREN -> KMarkdownElement.RParen
118 | MarkdownTokenTypes.LBRACKET -> KMarkdownElement.LBracket
119 | MarkdownTokenTypes.RBRACKET -> KMarkdownElement.RBracket
120 | MarkdownTokenTypes.LT -> KMarkdownElement.Lt
121 | MarkdownTokenTypes.GT -> KMarkdownElement.Gt
122 | MarkdownTokenTypes.COLON -> KMarkdownElement.Colon
123 | MarkdownTokenTypes.EXCLAMATION_MARK -> KMarkdownElement.ExclamationMark
124 | MarkdownTokenTypes.HARD_LINE_BREAK -> KMarkdownElement.HardLineBreak
125 | MarkdownTokenTypes.EOL -> KMarkdownElement.Eol
126 | MarkdownTokenTypes.LINK_ID -> KMarkdownElement.LinkId
127 | MarkdownTokenTypes.ATX_HEADER -> KMarkdownElement.AtxHeader
128 | MarkdownTokenTypes.ATX_CONTENT -> KMarkdownElement.AtxContent
129 | MarkdownTokenTypes.SETEXT_1 -> KMarkdownElement.Setext1
130 | MarkdownTokenTypes.SETEXT_2 -> KMarkdownElement.Setext2
131 | MarkdownTokenTypes.SETEXT_CONTENT -> KMarkdownElement.SetextContent
132 | MarkdownTokenTypes.EMPH -> KMarkdownElement.Emph
133 | MarkdownTokenTypes.BACKTICK -> KMarkdownElement.Backtick
134 | MarkdownTokenTypes.ESCAPED_BACKTICKS -> KMarkdownElement.EscapedBackticks
135 | MarkdownTokenTypes.LIST_BULLET -> KMarkdownElement.ListBullet
136 | MarkdownTokenTypes.URL -> KMarkdownElement.Url
137 | MarkdownTokenTypes.HORIZONTAL_RULE -> KMarkdownElement.HorizontalRule
138 | MarkdownTokenTypes.LIST_NUMBER -> KMarkdownElement.ListNumber
139 | MarkdownTokenTypes.FENCE_LANG -> KMarkdownElement.FenceLang
140 | MarkdownTokenTypes.CODE_FENCE_START -> KMarkdownElement.CodeFenceStart
141 | MarkdownTokenTypes.CODE_FENCE_CONTENT -> KMarkdownElement.CodeFenceContent
142 | MarkdownTokenTypes.CODE_FENCE_END -> KMarkdownElement.CodeFenceEnd
143 | MarkdownTokenTypes.AUTOLINK -> KMarkdownElement.Autolink
144 | MarkdownTokenTypes.EMAIL_AUTOLINK -> KMarkdownElement.EmailAutolink
145 | MarkdownTokenTypes.HTML_TAG -> KMarkdownElement.HtmlTag
146 | MarkdownTokenTypes.BAD_CHARACTER -> KMarkdownElement.BadCharacter
147 | MarkdownTokenTypes.WHITE_SPACE -> KMarkdownElement.WhiteSpace
148 | else -> throw IllegalArgumentException("Unknown IElementType")
149 | }
150 | }
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/sample/TestMD.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.sample
2 |
3 | val TEST_MD = """
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
24 | [![Contributors][contributors-shield]][contributors-url]
25 | [![Forks][forks-shield]][forks-url]
26 | [![Stargazers][stars-shield]][stars-url]
27 | [![Issues][issues-shield]][issues-url]
28 | [![MIT License][license-shield]][license-url]
29 | [![LinkedIn][linkedin-shield]][linkedin-url]
30 |
31 |
32 |
33 |
34 |
35 |
55 |
56 |
57 |
58 |
59 |
60 | Table of Contents
61 |
62 |
63 | About The Project
64 |
67 |
68 |
69 | Getting Started
70 |
74 |
75 | Usage
76 | Roadmap
77 | Contributing
78 | License
79 | Contact
80 | Acknowledgments
81 |
82 |
83 |
84 |
85 |
86 |
87 | ## About The Project
88 |
89 | [![Product Name Screen Shot][product-screenshot]](https://example.com)
90 |
91 | There are many great README templates available on GitHub; however, I didn't find one that really suited my needs so I created this enhanced one. I want to create a README template so amazing that it'll be the last one you ever need -- I think this is it.
92 |
93 | Here's why:
94 | * Your time should be focused on creating something amazing. A project that solves a problem and helps others
95 | * You shouldn't be doing the same tasks over and over like creating a README from scratch
96 | * You should implement DRY principles to the rest of your life :smile:
97 |
98 | Of course, no one template will serve all projects since your needs may be different. So I'll be adding more in the near future. You may also suggest changes by forking this repo and creating a pull request or opening an issue. Thanks to all the people have contributed to expanding this template!
99 |
100 | Use the `BLANK_README.md` to get started.
101 |
102 | (back to top )
103 |
104 |
105 |
106 | ### Built With
107 |
108 | This section should list any major frameworks/libraries used to bootstrap your project. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
109 |
110 | * [![Next][Next.js]][Next-url]
111 | * [![React][React.js]][React-url]
112 | * [![Vue][Vue.js]][Vue-url]
113 | * [![Angular][Angular.io]][Angular-url]
114 | * [![Svelte][Svelte.dev]][Svelte-url]
115 | * [![Laravel][Laravel.com]][Laravel-url]
116 | * [![Bootstrap][Bootstrap.com]][Bootstrap-url]
117 | * [![JQuery][JQuery.com]][JQuery-url]
118 |
119 | (back to top )
120 |
121 |
122 |
123 |
124 | ## Getting Started
125 |
126 | This is an example of how you may give instructions on setting up your project locally.
127 | To get a local copy up and running follow these simple example steps.
128 |
129 | ### Prerequisites
130 |
131 | This is an example of how to list things you need to use the software and how to install them.
132 | * npm
133 | ```sh
134 | npm install npm@latest -g
135 | ```
136 |
137 | ### Installation
138 |
139 | _Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services._
140 |
141 | 1. Get a free API Key at [https://example.com](https://example.com)
142 | 2. Clone the repo
143 | ```sh
144 | git clone https://github.com/github_username/repo_name.git
145 | ```
146 | 3. Install NPM packages
147 | ```sh
148 | npm install
149 | ```
150 | 4. Enter your API in `config.js`
151 | ```js
152 | const API_KEY = 'ENTER YOUR API';
153 | ```
154 | 5. Change git remote url to avoid accidental pushes to base project
155 | ```sh
156 | git remote set-url origin github_username/repo_name
157 | git remote -v # confirm the changes
158 | ```
159 |
160 | (back to top )
161 |
162 |
163 |
164 |
165 | ## Usage
166 |
167 | Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
168 |
169 | _For more examples, please refer to the [Documentation](https://example.com)_
170 |
171 | (back to top )
172 |
173 |
174 |
175 |
176 | ## Roadmap
177 |
178 | - [x] Add Changelog
179 | - [x] Add back to top links
180 | - [ ] Add Additional Templates w/ Examples
181 | - [ ] Add "components" document to easily copy & paste sections of the readme
182 | - [ ] Multi-language Support
183 | - [ ] Chinese
184 | - [ ] Spanish
185 |
186 | See the [open issues](https://github.com/othneildrew/Best-README-Template/issues) for a full list of proposed features (and known issues).
187 |
188 | (back to top )
189 |
190 |
191 |
192 |
193 | ## Contributing
194 |
195 | Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
196 |
197 | If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
198 | Don't forget to give the project a star! Thanks again!
199 |
200 | 1. Fork the Project
201 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
202 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
203 | 4. Push to the Branch (`git push origin feature/AmazingFeature`)
204 | 5. Open a Pull Request
205 |
206 | ### Top contributors:
207 |
208 |
209 |
210 |
211 |
212 | (back to top )
213 |
214 |
215 |
216 |
217 | ## License
218 |
219 | Distributed under the MIT License. See `LICENSE.txt` for more information.
220 |
221 | (back to top )
222 |
223 |
224 |
225 |
226 | ## Contact
227 |
228 | Your Name - [@your_twitter](https://twitter.com/your_username) - email@example.com
229 |
230 | Project Link: [https://github.com/your_username/repo_name](https://github.com/your_username/repo_name)
231 |
232 | (back to top )
233 |
234 |
235 |
236 |
237 | ## Acknowledgments
238 |
239 | Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!
240 |
241 | * [Choose an Open Source License](https://choosealicense.com)
242 | * [GitHub Emoji Cheat Sheet](https://www.webpagefx.com/tools/emoji-cheat-sheet)
243 | * [Malven's Flexbox Cheatsheet](https://flexbox.malven.co/)
244 | * [Malven's Grid Cheatsheet](https://grid.malven.co/)
245 | * [Img Shields](https://shields.io)
246 | * [GitHub Pages](https://pages.github.com)
247 | * [Font Awesome](https://fontawesome.com)
248 | * [React Icons](https://react-icons.github.io/react-icons/search)
249 |
250 | (back to top )
251 |
252 |
253 |
254 |
255 |
256 | [contributors-shield]: https://img.shields.io/github/contributors/othneildrew/Best-README-Template.svg?style=for-the-badge
257 | [contributors-url]: https://github.com/othneildrew/Best-README-Template/graphs/contributors
258 | [forks-shield]: https://img.shields.io/github/forks/othneildrew/Best-README-Template.svg?style=for-the-badge
259 | [forks-url]: https://github.com/othneildrew/Best-README-Template/network/members
260 | [stars-shield]: https://img.shields.io/github/stars/othneildrew/Best-README-Template.svg?style=for-the-badge
261 | [stars-url]: https://github.com/othneildrew/Best-README-Template/stargazers
262 | [issues-shield]: https://img.shields.io/github/issues/othneildrew/Best-README-Template.svg?style=for-the-badge
263 | [issues-url]: https://github.com/othneildrew/Best-README-Template/issues
264 | [license-shield]: https://img.shields.io/github/license/othneildrew/Best-README-Template.svg?style=for-the-badge
265 | [license-url]: https://github.com/othneildrew/Best-README-Template/blob/master/LICENSE.txt
266 | [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
267 | [linkedin-url]: https://linkedin.com/in/othneildrew
268 | [product-screenshot]: images/screenshot.png
269 | [Next.js]: https://img.shields.io/badge/next.js-000000?style=for-the-badge&logo=nextdotjs&logoColor=white
270 | [Next-url]: https://nextjs.org/
271 | [React.js]: https://img.shields.io/badge/React-20232A?style=for-the-badge&logo=react&logoColor=61DAFB
272 | [React-url]: https://reactjs.org/
273 | [Vue.js]: https://img.shields.io/badge/Vue.js-35495E?style=for-the-badge&logo=vuedotjs&logoColor=4FC08D
274 | [Vue-url]: https://vuejs.org/
275 | [Angular.io]: https://img.shields.io/badge/Angular-DD0031?style=for-the-badge&logo=angular&logoColor=white
276 | [Angular-url]: https://angular.io/
277 | [Svelte.dev]: https://img.shields.io/badge/Svelte-4A4A55?style=for-the-badge&logo=svelte&logoColor=FF3E00
278 | [Svelte-url]: https://svelte.dev/
279 | [Laravel.com]: https://img.shields.io/badge/Laravel-FF2D20?style=for-the-badge&logo=laravel&logoColor=white
280 | [Laravel-url]: https://laravel.com
281 | [Bootstrap.com]: https://img.shields.io/badge/Bootstrap-563D7C?style=for-the-badge&logo=bootstrap&logoColor=white
282 | [Bootstrap-url]: https://getbootstrap.com
283 | [JQuery.com]: https://img.shields.io/badge/jQuery-0769AD?style=for-the-badge&logo=jquery&logoColor=white
284 | [JQuery-url]: https://jquery.com
285 | """.trimIndent()
--------------------------------------------------------------------------------
/.idea/other.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/kmarkdown/lib/KMarkdown.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.kmarkdown.lib
2 |
3 | import android.graphics.Typeface
4 | import android.text.Spanned
5 | import android.text.style.*
6 | import androidx.compose.foundation.Image
7 | import androidx.compose.foundation.background
8 | import androidx.compose.foundation.layout.Box
9 | import androidx.compose.foundation.layout.Column
10 | import androidx.compose.foundation.layout.ExperimentalLayoutApi
11 | import androidx.compose.foundation.layout.FlowRow
12 | import androidx.compose.foundation.layout.fillMaxSize
13 | import androidx.compose.foundation.layout.padding
14 | import androidx.compose.foundation.layout.size
15 | import androidx.compose.foundation.rememberScrollState
16 | import androidx.compose.foundation.text.BasicText
17 | import androidx.compose.foundation.text.ClickableText
18 | import androidx.compose.foundation.verticalScroll
19 | import androidx.compose.runtime.Composable
20 | import androidx.compose.runtime.derivedStateOf
21 | import androidx.compose.runtime.getValue
22 | import androidx.compose.runtime.remember
23 | import androidx.compose.ui.Modifier
24 | import androidx.compose.ui.graphics.Color
25 | import androidx.compose.ui.platform.LocalContext
26 | import androidx.compose.ui.text.*
27 | import androidx.compose.ui.text.font.FontFamily
28 | import androidx.compose.ui.text.font.FontStyle
29 | import androidx.compose.ui.text.font.FontWeight
30 | import androidx.compose.ui.text.style.TextDecoration
31 | import androidx.compose.ui.tooling.preview.Preview
32 | import androidx.compose.ui.unit.dp
33 | import androidx.compose.ui.unit.em
34 | import androidx.compose.ui.unit.sp
35 | import androidx.core.text.HtmlCompat
36 | import coil.compose.AsyncImagePainter
37 | import coil.compose.rememberAsyncImagePainter
38 | import coil.request.ImageRequest
39 | import coil.size.Size
40 | import dev.baseio.kmarkdown.sample.TEST_MD
41 | import dev.baseio.kmarkdown.sample.ui.theme.KMarkdownTheme
42 | import org.intellij.markdown.MarkdownElementTypes
43 | import org.intellij.markdown.ast.ASTNode
44 | import org.intellij.markdown.ast.getTextInNode
45 | import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
46 | import org.intellij.markdown.html.HtmlGenerator
47 | import org.intellij.markdown.parser.MarkdownParser
48 |
49 | @OptIn(ExperimentalLayoutApi::class)
50 | @Composable
51 | fun ASTNode.MDNodeASComposable(
52 | content: String,
53 | styles: KMarkdownStyles
54 | ) {
55 | val node = this@MDNodeASComposable
56 | val nodeContent = node.getTextInNode(content).toString()
57 | when (node.type.toMarkdownElement()) {
58 | KMarkdownElement.MarkdownFile -> node.children.forEach { astNode ->
59 | astNode.MDNodeASComposable(content = content, styles = styles)
60 | }
61 |
62 | KMarkdownElement.Paragraph -> FlowRow {
63 | node.children.forEach { paragraphChild ->
64 | paragraphChild.MDNodeASComposable(content, styles)
65 | }
66 | }
67 |
68 | KMarkdownElement.HtmlBlock, KMarkdownElement.HtmlTag, KMarkdownElement.HtmlBlockContent -> {
69 | Box(
70 | modifier = Modifier
71 | .background(
72 | color = styles.blockQuoteBG,
73 | shape = styles.blockQuoteShape
74 | )
75 | .padding(4.dp)
76 | ) {
77 | val flavour = CommonMarkFlavourDescriptor()
78 | val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(nodeContent)
79 | val html = HtmlGenerator(nodeContent, parsedTree, flavour).generateHtml()
80 | BasicText(
81 | text = HtmlCompat.fromHtml(html, HtmlCompat.FROM_HTML_MODE_COMPACT)
82 | .toComposableText()
83 | )
84 | }
85 | }
86 | KMarkdownElement.UnorderedList -> {
87 | node.children.forEach { paragraphChild ->
88 | BasicText(text = paragraphChild.getTextInNode(content).toString())
89 | }
90 | }
91 |
92 | KMarkdownElement.LinkDestination -> {
93 | KMarkdownLinkDestination(content, styles)
94 | }
95 |
96 | KMarkdownElement.Image -> {
97 | KMarkDownImage(
98 | content = content,
99 | styles = styles
100 | )
101 | }
102 |
103 | KMarkdownElement.FullReferenceLink -> {
104 | BasicText(text = buildAnnotatedString {
105 | append(node.getTextInNode(content))
106 | })
107 | }
108 |
109 | KMarkdownElement.CodeSpan -> Box(
110 | modifier = Modifier
111 | .background(
112 | color = styles.blockQuoteBG,
113 | shape = styles.blockQuoteShape
114 | )
115 | .padding(4.dp)
116 | ) {
117 | BasicText(text = node.getTextInNode(content).toString())
118 | }
119 |
120 | KMarkdownElement.OrderedList -> {
121 | node.children.forEach { paragraphChild ->
122 | BasicText(text = paragraphChild.getTextInNode(content).toString())
123 | }
124 | }
125 |
126 | KMarkdownElement.BlockQuote -> Box(
127 | modifier = Modifier
128 | .background(
129 | color = styles.blockQuoteBG,
130 | shape = styles.blockQuoteShape
131 | )
132 | .padding(4.dp)
133 | ) {
134 | BasicText(text = node.getTextInNode(content).toString())
135 | }
136 |
137 | KMarkdownElement.Atx1 -> BasicText(
138 | text = node.getTextInNode(content).toString(),
139 | style = styles.kMarkdownTypography.heading1
140 | )
141 |
142 | KMarkdownElement.Atx2 -> BasicText(
143 | text = node.getTextInNode(content).toString(),
144 | style = styles.kMarkdownTypography.heading2
145 | )
146 |
147 | KMarkdownElement.Atx3 -> BasicText(
148 | text = node.getTextInNode(content).toString(),
149 | style = styles.kMarkdownTypography.heading3
150 | )
151 |
152 | KMarkdownElement.Atx4 -> BasicText(
153 | text = node.getTextInNode(content).toString(),
154 | style = styles.kMarkdownTypography.heading4
155 | )
156 |
157 | KMarkdownElement.Atx5 -> BasicText(
158 | text = node.getTextInNode(content).toString(),
159 | style = styles.kMarkdownTypography.heading5
160 | )
161 |
162 | KMarkdownElement.Atx6 -> BasicText(
163 | text = node.getTextInNode(content).toString(),
164 | style = styles.kMarkdownTypography.heading6
165 | )
166 |
167 | KMarkdownElement.Text -> BasicText(
168 | text = node.getTextInNode(content).toString(),
169 | style = styles.kMarkdownTypography.textStyle,
170 | )
171 |
172 | KMarkdownElement.HorizontalRule -> BasicText(text = "---")
173 | KMarkdownElement.Setext1 -> BasicText(
174 | text = node.getTextInNode(content).toString(),
175 | style = styles.kMarkdownTypography.setext1Style,
176 | )
177 |
178 | KMarkdownElement.Setext2 -> BasicText(
179 | text = node.getTextInNode(content).toString(),
180 | style = styles.kMarkdownTypography.setext2Style,
181 | )
182 |
183 | KMarkdownElement.Strong -> BasicText(
184 | text = node.getTextInNode(content).toString(),
185 | style = styles.kMarkdownTypography.textStyle.copy(fontWeight = FontWeight.Bold),
186 | )
187 |
188 | KMarkdownElement.Eol -> BasicText(
189 | text = "\n",
190 | )
191 |
192 | else -> {
193 | BasicText(text = "not implemented ${this.type.name}")
194 | }
195 | }
196 |
197 | }
198 |
199 | @Composable
200 | private fun ASTNode.KMarkDownImage(
201 | content: String,
202 | styles: KMarkdownStyles
203 | ) {
204 | val linkDestination = this.children.find {
205 | it.type.toMarkdownElement() is KMarkdownElement.InlineLink
206 | }?.children?.find {
207 | it.type.name == MarkdownElementTypes.LINK_DESTINATION.name
208 | }
209 | linkDestination?.MDNodeASComposable(content, styles)
210 | }
211 |
212 | @Composable
213 | private fun ASTNode.KMarkdownLinkDestination(
214 | content: String,
215 | styles: KMarkdownStyles
216 | ) {
217 | val imageUrl = this.getTextInNode(content)
218 | val painter = rememberAsyncImagePainter(
219 | model = ImageRequest.Builder(LocalContext.current)
220 | .data(imageUrl)
221 | .size(Size.ORIGINAL) // Set the target size to load the image at.
222 | .build()
223 | )
224 |
225 | when (painter.state) {
226 | is AsyncImagePainter.State.Success -> {
227 | Image(
228 | painter = painter,
229 | modifier = Modifier.size(styles.imageSize),
230 | contentDescription = null
231 | )
232 | }
233 |
234 | AsyncImagePainter.State.Empty -> {
235 | BasicText(text = "nothing to load")
236 | }
237 |
238 | is AsyncImagePainter.State.Error -> {
239 | BasicText(text = "error ${(painter.state as AsyncImagePainter.State.Error).result.throwable.stackTraceToString()}")
240 | }
241 |
242 | is AsyncImagePainter.State.Loading -> BasicText(text = "loading..")
243 | }
244 | }
245 |
246 |
247 | @Composable
248 | fun KMarkdown(
249 | markdownContent: String,
250 | modifier: Modifier = Modifier,
251 | styles: KMarkdownStyles,
252 | ) {
253 | val markdown by remember(markdownContent) {
254 | derivedStateOf {
255 | val flavour = CommonMarkFlavourDescriptor()
256 | MarkdownParser(flavour = flavour)
257 | .buildMarkdownTreeFromString(text = markdownContent)
258 | }
259 | }
260 |
261 | Column(
262 | modifier.verticalScroll(rememberScrollState())
263 | ) {
264 | markdown.MDNodeASComposable(
265 | content = markdownContent,
266 | styles = styles
267 | )
268 | }
269 | }
270 |
271 | @Preview
272 | @Composable
273 | private fun Preview() {
274 | KMarkdownTheme {
275 | KMarkdown(
276 | markdownContent = TEST_MD,
277 | modifier = Modifier
278 | .fillMaxSize()
279 | .background(
280 | Color.White
281 | ),
282 | styles = KMarkdownStyles()
283 | )
284 | }
285 | }
286 |
287 | @Composable
288 | fun Spanned.toComposableText(): AnnotatedString {
289 | val annotatedString = buildAnnotatedString {
290 | val text = this@toComposableText.toString()
291 |
292 | val spans = this@toComposableText.getSpans(0, text.length, Any::class.java)
293 |
294 | var lastSpanEnd = 0
295 | for (span in spans) {
296 | val spanStart = this@toComposableText.getSpanStart(span)
297 | val spanEnd = this@toComposableText.getSpanEnd(span)
298 |
299 | // Add the text before the span (if any)
300 | if (spanStart > lastSpanEnd) {
301 | append(text.substring(lastSpanEnd, spanStart))
302 | }
303 |
304 | // Apply the styles or spans
305 | pushStyle(SpanStyle())
306 | when (span) {
307 | is StyleSpan -> {
308 | when (span.style) {
309 | android.graphics.Typeface.BOLD -> {
310 | pushStyle(SpanStyle(fontWeight = FontWeight.Bold))
311 | }
312 |
313 | android.graphics.Typeface.ITALIC -> {
314 | pushStyle(SpanStyle(fontStyle = FontStyle.Italic))
315 | }
316 |
317 | android.graphics.Typeface.BOLD_ITALIC -> {
318 | pushStyle(
319 | SpanStyle(
320 | fontWeight = FontWeight.Bold,
321 | fontStyle = FontStyle.Italic
322 | )
323 | )
324 | }
325 | }
326 | }
327 |
328 | is UnderlineSpan -> {
329 | pushStyle(SpanStyle(textDecoration = TextDecoration.Underline))
330 | }
331 |
332 | is StrikethroughSpan -> {
333 | pushStyle(SpanStyle(textDecoration = TextDecoration.LineThrough))
334 | }
335 |
336 | is ForegroundColorSpan -> {
337 | pushStyle(SpanStyle(color = Color(span.foregroundColor)))
338 | }
339 |
340 | is BackgroundColorSpan -> {
341 | pushStyle(SpanStyle(background = Color(span.backgroundColor)))
342 | }
343 |
344 | is URLSpan -> {
345 | pushStringAnnotation(tag = "URL", annotation = span.url)
346 | pushStyle(
347 | SpanStyle(
348 | color = Color(0xfff86689),
349 | textDecoration = TextDecoration.Underline
350 | )
351 | )
352 | }
353 |
354 | is AbsoluteSizeSpan -> {
355 | pushStyle(SpanStyle(fontSize = span.size.sp))
356 | }
357 |
358 | is RelativeSizeSpan -> {
359 | pushStyle(SpanStyle(fontSize = span.sizeChange.em))
360 | }
361 |
362 | is TypefaceSpan -> {
363 | span.family?.let { _ ->
364 | pushStyle(SpanStyle(fontFamily = FontFamily(Typeface.DEFAULT)))
365 | }
366 | }
367 | // Add other spans as necessary
368 | }
369 | append(text.substring(spanStart, spanEnd))
370 | pop()
371 |
372 | // Update the last span end
373 | lastSpanEnd = spanEnd
374 | }
375 |
376 | // Add the remaining text (if any)
377 | if (lastSpanEnd < text.length) {
378 | append(text.substring(lastSpanEnd))
379 | }
380 | }
381 |
382 | return annotatedString
383 | }
--------------------------------------------------------------------------------