Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ jobs:
run: |
COLLECT_PWD=${PWD}
mkdir -p "artifacts"
find . -name "*.apk" -type f -exec cp {} "artifacts" \;
find . -name "*.aab" -type f -exec cp {} "artifacts" \;
find . -name "*release.apk" -type f -exec cp {} "artifacts" \;
find . -name "*release.aab" -type f -exec cp {} "artifacts" \;

- name: Archive Artifacts
uses: actions/upload-artifact@v2
Expand Down
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,29 @@
See the License for the specific language governing permissions and
limitations under the License.

--------

Parts of the markdown composer are based on Erik Hellman's work as found: https://github.com/ErikHellman/MarkdownComposer
As described in the related article: https://www.hellsoft.se/rendering-markdown-with-jetpack-compose/

MIT License

Copyright (c) 2021 Erik Hellman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ This free, open source software was also made possible by a group of volunteers

## Credits

Big thanks to [Erik Hellman](https://twitter.com/ErikHellman) and his awesome article on [Rendering Markdown with Jetpack Compose](https://www.hellsoft.se/rendering-markdown-with-jetpack-compose/)
Big thanks to [Erik Hellman](https://twitter.com/ErikHellman) and his awesome article on [Rendering Markdown with Jetpack Compose](https://www.hellsoft.se/rendering-markdown-with-jetpack-compose/), and the related source [MarkdownComposer](https://github.com/ErikHellman/MarkdownComposer).

## Fork License

Copyright for portions of the code are held by [Erik Hellman, 2020] as part of project [MarkdownComposer](https://github.com/ErikHellman/MarkdownComposer) under the MIT license. All other copyright for project multiplatform-markdown-renderer are held by [Mike Penz, 2021] under the Apache License, Version 2.0.

## License

Expand Down
18 changes: 9 additions & 9 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ android {
minSdk = Versions.androidMinSdk
targetSdk = Versions.androidTargetSdk

versionCode = 100
versionName = "1.0.0"
versionCode = property("VERSION_CODE").toString().toInt()
versionName = property("VERSION_NAME").toString()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

setProperty("archivesBaseName", "markdown-renderer-sample-v$versionName-c$versionCode")
}

buildFeatures {
Expand Down Expand Up @@ -70,20 +72,18 @@ dependencies {
}

with(Deps.AndroidX) {
implementation(lifecycleRuntimeKtx)
implementation(lifecycleViewmodelKtx)
implementation(activityCompose)
}


with(Deps.Compose) {
implementation(ui)
implementation(uiGraphics)
implementation(coilCompose)

implementation(foundationLayout)
implementation(material)
implementation(coilCompose)
implementation(accompanistInsets)
implementation(accompanistInsetsUi)
implementation(ui)
implementation(uiTooling)
implementation(uiGraphics)
}
}

Expand Down
63 changes: 30 additions & 33 deletions app/src/main/java/com/mikepenz/markdown/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.primarySurface
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.google.accompanist.insets.LocalWindowInsets
import com.google.accompanist.insets.ProvideWindowInsets
import com.google.accompanist.insets.rememberInsetsPaddingValues
import com.google.accompanist.insets.ui.Scaffold
import androidx.compose.ui.unit.dp
import com.mikepenz.markdown.Markdown

class MainActivity : ComponentActivity() {
Expand All @@ -30,32 +27,32 @@ class MainActivity : ComponentActivity() {
@Composable
fun MainLayout() {
SampleTheme {
ProvideWindowInsets {
Scaffold(
modifier = Modifier.background(MaterialTheme.colors.primarySurface),
contentPadding = rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyTop = false,
applyBottom = true,
)
) {
val markdown = """
### Getting Started

To get started you will need GPG on your computer to create a new key pair.

Usually I go with the [GPG Suite](https://gpgtools.org/), which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key.
""".trimIndent()
val markdown = """
### Getting Started

To get started you will need GPG on your computer to create a new key pair.

Usually I go with the [GPG Suite](https://gpgtools.org/), which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

![Image](https://avatars.githubusercontent.com/u/1476232?v=4)

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key.
""".trimIndent()

Markdown(markdown, Modifier.fillMaxSize())
}
}
val scrollState = rememberScrollState()

Markdown(
markdown,
Modifier
.verticalScroll(scrollState)
.fillMaxSize()
.padding(16.dp)
.padding(bottom = 48.dp)
)
}
}
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:7.1.0-alpha13")
classpath("com.android.tools.build:gradle:7.0.3")
classpath("com.vanniktech:gradle-maven-publish-plugin:0.18.0")
classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.5.30")
classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:8.9.1")
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha4-build366")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.5.31")
classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:8.9.3")
classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha4-build398")
}
}

Expand Down
14 changes: 4 additions & 10 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ object Versions {

const val markdown = "0.2.4"

const val compose = "1.1.0-alpha05"
const val accompanist = "0.19.0"
const val coil = "1.4.0"
const val compose = "1.1.0-alpha06"

const val material = "1.4.0"
const val activityCompose = "1.3.1"
const val lifecycleKtx = "2.4.0-rc01"
const val lifecycleRuntimeKtx = lifecycleKtx
const val lifecycleViewmodelKtx = lifecycleKtx
const val lifecycleKtx = "2.3.1"
}

object Deps {
Expand All @@ -23,8 +21,6 @@ object Deps {
}

object AndroidX {
const val lifecycleRuntimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifecycleRuntimeKtx}"
const val lifecycleViewmodelKtx = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycleViewmodelKtx}"
const val activityCompose = "androidx.activity:activity-compose:${Versions.activityCompose}"
}

Expand All @@ -39,8 +35,6 @@ object Deps {
const val foundationLayout = "androidx.compose.foundation:foundation-layout:${Versions.compose}"
const val material = "androidx.compose.material:material:${Versions.compose}"

const val coilCompose = "io.coil-kt:coil-compose:1.3.1"
const val accompanistInsets = "com.google.accompanist:accompanist-insets:${Versions.accompanist}"
const val accompanistInsetsUi = "com.google.accompanist:accompanist-insets-ui:${Versions.accompanist}"
const val coilCompose = "io.coil-kt:coil-compose:${Versions.coil}"
}
}
44 changes: 27 additions & 17 deletions compose-desktop/src/main/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import com.mikepenz.markdown.Markdown

fun main() = application {
Window(onCloseRequest = ::exitApplication) {
Window(onCloseRequest = ::exitApplication, title = "Markdown Sample") {
SampleTheme {
Scaffold(
topBar = {
Expand All @@ -15,22 +21,26 @@ fun main() = application {
)
}
) {
Markdown(
"""
### Getting Started

To get started you will need GPG on your computer to create a new key pair.

Usually I go with the [GPG Suite](https://gpgtools.org/), which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key.
""".trimIndent()
)
val scrollState = rememberScrollState()

val content = """
### Getting Started

To get started you will need GPG on your computer to create a new key pair.

Usually I go with the [GPG Suite](https://gpgtools.org/), which offers a nice UI to manage your keys. (You may want to use advanced installation to only install the parts you need)
But you can also use any other solution to create your key pair.

![Image](https://avatars.githubusercontent.com/u/1476232?v=4)

After installing GPG Suite (or your prefered solution) first create a new key.

Using GPG Suite, start the GPG Keychain, which shows all current known GPG keys on your system.

Click on `New` and you will be offered to enter your name, e-mail and password. Ensure to pick a secure password to protect your key.
""".trimIndent()

Markdown(content, Modifier.fillMaxSize().padding(16.dp).verticalScroll(scrollState))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Maven stuff
GROUP=com.mikepenz
VERSION_NAME=0.0.1
VERSION_CODE=1
VERSION_NAME=0.1.0
VERSION_CODE=100

POM_URL=https://github.com/mikepenz/multiplatform-markdown-renderer

Expand Down
1 change: 1 addition & 0 deletions multiplatform-markdown-renderer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ kotlin {

dependencies {
commonMainApi(Deps.Markdown.core)

commonMainCompileOnly(compose.runtime)
commonMainCompileOnly(compose.ui)
commonMainCompileOnly(compose.foundation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import coil.size.OriginalSize

@OptIn(ExperimentalCoilApi::class)
@Composable
internal actual fun imagePainter(url: String): Painter {
internal actual fun imagePainter(url: String): Painter? {
return rememberImagePainter(url, builder = { size(OriginalSize) })
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mikepenz.markdown

import org.intellij.markdown.IElementType
import org.intellij.markdown.ast.ASTNode

/**
* Tag used to indicate an url for inline content. Required for click handling.
*/
Expand All @@ -9,3 +12,26 @@ const val TAG_URL = "MARKDOWN_URL"
* Tag used to indicate an image url for inline content. Required for rendering.
*/
const val TAG_IMAGE_URL = "MARKDOWN_IMAGE_URL"

/**
* Find a child node recursive
*/
fun ASTNode.findChildOfTypeRecursive(type: IElementType): ASTNode? {
children.forEach {
if (it.type == type) {
return it
} else {
val found = it.findChildOfTypeRecursive(type)
if (found != null) {
return found
}
}
}
return null
}

/**
* Helper function to drop the first and last element in the children list.
* E.g. we don't want to render the brackets of a link
*/
internal fun List<ASTNode>.innerList(): List<ASTNode> = this.subList(1, this.size - 1)
Loading