diff --git a/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/plugins/core/MardownCorePlugin.kt b/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/plugins/core/MardownCorePlugin.kt index 4ccbbac..65cba4d 100644 --- a/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/plugins/core/MardownCorePlugin.kt +++ b/markdowntext/src/main/java/dev/jeziellago/compose/markdowntext/plugins/core/MardownCorePlugin.kt @@ -393,4 +393,4 @@ class MardownCorePlugin( visitor.setSpansForNodeOptional(link, length) } } -} +} \ No newline at end of file diff --git a/sample/src/main/java/dev/jeziellago/compose/markdown/MainActivity.kt b/sample/src/main/java/dev/jeziellago/compose/markdown/MainActivity.kt index 264ca8e..157283e 100644 --- a/sample/src/main/java/dev/jeziellago/compose/markdown/MainActivity.kt +++ b/sample/src/main/java/dev/jeziellago/compose/markdown/MainActivity.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.widget.Toast import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import androidx.compose.animation.animateContentSize import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.detectTapGestures import androidx.compose.foundation.layout.fillMaxWidth @@ -14,10 +13,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput -import androidx.compose.ui.res.colorResource -import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -40,36 +36,345 @@ class MainActivity : AppCompatActivity() { ) { item { MarkdownText( - modifier = Modifier.animateContentSize(), - markdown = stringResource(id = R.string.test1), - style = MinorThird.editStyle( - MinorThird.bodySmall, - color = (colorResource(R.color.white)) + modifier = Modifier + .padding(8.dp) + .fillMaxWidth(), + markdown = """ + ## Gif Images + ![Image](https://user-images.githubusercontent.com/14011726/94132137-7d4fc100-fe7c-11ea-8512-69f90cb65e48.gif) + + --- + """.trimIndent() + ) + } + item { + MarkdownText( + markdown = """ + ## Checks + - [x] Review #123 + - [ ] Complete XYZ + - [ ] Add delight to the experience when all tasks are complete :tada: + + --- + """.trimIndent(), + ) + } + item { + MarkdownText( + syntaxHighlightColor = Color.Black, + syntaxHighlightTextColor = Color.White, + markdown = """ + ## Text highlight + Sometimes we need to ==highlight== a text in `different` ways. + + --- + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ +

Head with heading break color blue

+ + --- + """.trimIndent(), + headingBreakColor = Color.Blue + ) + } + item { + MarkdownText( + markdown = """ + ## Custom font + + This text is using OpenSans Regular. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + + --- + + """.trimIndent(), + fontResource = R.font.opensans_regular, + modifier = Modifier.clickable { + Toast + .makeText(this@MainActivity, "On text click", Toast.LENGTH_SHORT) + .show() + }, + style = TextStyle( + textAlign = TextAlign.Justify, + lineHeight = 24.sp, + fontSize = 18.sp ) ) } item { MarkdownText( - modifier = Modifier.animateContentSize(), - markdown = stringResource(id = R.string.test1), - style = MinorThird.editStyle( - MinorThird.bodySmall, - fontSize = 34.sp, - color = (colorResource(R.color.white)) + modifier = Modifier.clickable { + Toast + .makeText(this@MainActivity, "On text click", Toast.LENGTH_SHORT) + .show() + }, + disableLinkMovementMethod = true, + markdown = """ + ## Clickable item + + Should appear a single toast when clicking on this item! + + --- + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Selectable item + + This is a selectable text. You can select this text by long pressing on it. + + """.trimIndent(), + isTextSelectable = true + ) + } + item { + MarkdownText( + markdown = """ + ## Justify + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + + """.trimIndent(), + style = TextStyle( + textAlign = TextAlign.Justify, ) ) } item { MarkdownText( - modifier = Modifier.animateContentSize(), - markdown = stringResource(id = R.string.test1), - style = MinorThird.editStyle( - MinorThird.bodySmall, - fontSize = 14.sp, - color = (colorResource(R.color.white)) + markdown = """ + ## Color + + This text should appears in Blue color. + + """.trimIndent(), + style = TextStyle( + color = Color.Blue ) ) } + item { + MarkdownText( + markdown = """ + --- + __Advertisement :)__ + + - __[nodeca](https://nodeca.github.io/pica/demo/)__ - high quality and fast image + resize in browser. + - __[babelfish](https://github.com/nodeca/babelfish/)__ - developer friendly + i18n with plurals support and easy syntax. + + You will like those projects! + + --- + """.trimIndent(), + modifier = Modifier.pointerInput(Unit) { + detectTapGestures(onLongPress = { + Toast + .makeText(this@MainActivity, "On long press", Toast.LENGTH_SHORT) + .show() + }) + }) + } + item { + MarkdownText( + markdown = """ + # h1 Heading 8-) + ## h2 Heading + ### h3 Heading + #### h4 Heading + ##### h5 Heading + ###### h6 Heading + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Horizontal Rules + + ___ + + --- + + *** + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Emphasis + + **This is bold text** + + __This is bold text__ + + *This is italic text* + + _This is italic text_ + + ~~Strikethrough~~ + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Links + + [link text](http://dev.nodeca.com) + + [link with title](http://nodeca.github.io/pica/demo/ "title text!") + + Autoconverted link https://github.com/nodeca/pica (enable linkify to see) + + """.trimIndent(), + ) + } + item { + MarkdownText( + modifier = Modifier.fillMaxWidth(), + markdown = """ + ## Images + + ![Minion](https://octodex.github.com/images/minion.png) + ![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat") + + """.trimIndent(), + ) + } + item { + MarkdownText( + modifier = Modifier.fillMaxWidth(), + markdown = """ + Content + with + line + break + + """.trimIndent(), + ) + } + item { + MarkdownText( + modifier = Modifier.fillMaxWidth(), + markdown = """ + ## Tables + + | Option | Description | + | ------ | ----------- | + | data | path to data files to supply the data that will be passed into templates. | + | engine | engine to be used for processing templates. Handlebars is the default. | + | ext | extension to be used for dest files. | + + Right aligned columns + + | Option | Description | + | ------:| -----------:| + | data | path to data files to supply the data that will be passed into templates. | + | engine | engine to be used for processing templates. Handlebars is the default. | + | ext | extension to be used for dest files. | + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Lists + + Unordered + + + Create a list by starting a line with `+`, `-`, or `*` + + Sub-lists are made by indenting 2 spaces: + - Marker character change forces new list start: + * Ac tristique libero volutpat at + + Facilisis in pretium nisl aliquet + - Nulla volutpat aliquam velit + + Very easy! + + Ordered + + 1. Lorem ipsum dolor sit amet + 2. Consectetur adipiscing elit + 3. Integer molestie lorem at massa + + + 1. You can use sequential numbers... + 1. ...or keep all the numbers as `1.` + + Start numbering with offset: + + 57. foo + 1. bar + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Blockquotes + + > Blockquotes can also be nested... + >> ...by using additional greater-than signs right next to each other... + > > > ...or with spaces between arrows. + + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = """ + ## Code + + Inline `code` + + Indented code + + // Some comments + line 1 of code + line 2 of code + line 3 of code + + + Block code "fences" + + ``` + Sample text here... + ``` + + more code here.. + + ``` js + var foo = function (bar) { + return bar++; + }; + + console.log(foo(5)); + ``` + """.trimIndent(), + ) + } + item { + MarkdownText( + markdown = "\n# HTML SECTION ${ + String( + resources.openRawResource(R.raw.html).readBytes() + ) + }", + ) + } } } } diff --git a/sample/src/main/java/dev/jeziellago/compose/markdown/MinorThird.kt b/sample/src/main/java/dev/jeziellago/compose/markdown/MinorThird.kt deleted file mode 100644 index 6102c96..0000000 --- a/sample/src/main/java/dev/jeziellago/compose/markdown/MinorThird.kt +++ /dev/null @@ -1,228 +0,0 @@ -package dev.jeziellago.compose.markdown - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.Font -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontStyle -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.sp - -val fonts = FontFamily( - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.ExtraLight), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.ExtraLight, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Light), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Light, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Normal), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Normal, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Medium), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Medium, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.SemiBold), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.SemiBold, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Bold), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Bold, FontStyle.Italic), - - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Black), - Font(dev.jeziellago.compose.markdown.sample.R.font.opensans_regular, FontWeight.Black, FontStyle.Italic) -) - -object FontScaleHolder { - var fontScale: Float = 1f - - fun getScaleFactor(): Float { - return fontScale - } -} - -object MinorThird { - val h1: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 39.81.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 47.77.sp, - color = Color(0xFF0D0235), - ) - - val h2: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 33.18.sp, - lineHeight = 43.13.sp, - color = Color(0xFF0D0235), - ) - - val h3: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 27.65.sp, - lineHeight = 35.94.sp, - color = Color(0xFF0D0235), - ) - - val subtitle1: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 23.04.sp, - lineHeight = 29.95.sp, - color = Color(0xFF0D0235), - ) - - val subtitle2: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 16.sp, - lineHeight = 24.sp, - color = Color(0xFF0D0235), - ) - - val subtitle3: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Bold, - fontSize = 13.3.sp, - lineHeight = 20.sp, - color = Color(0xFF0D0235), - ) - - val link: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Black, - fontSize = 13.33.sp, - lineHeight = 20.sp, - color = Color(0xFF0D0235), - ) - - val body: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 19.20.sp, - lineHeight = 28.8.sp, - color = Color(0xFF0D0235), - ) - - val bodyEmphasis: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Black, - fontSize = 19.20.sp, - lineHeight = 28.8.sp, - color = Color(0xFF0D0235), - ) - - val bodyRegular: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 19.20.sp, - lineHeight = 28.8.sp, - color = Color(0xFF0D0235), - ) - - val bodySmall: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Normal, - fontSize = 16.sp, - lineHeight = 24.sp, - color = Color(0xFF0D0235), - ) - - val bodySmallEmphasis: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 16.sp, - lineHeight = 24.sp, - color = Color(0xFF0D0235), - ) - - val subtext: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 11.11.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 15.18.sp, - letterSpacing = 0.5.sp, - color = Color(0xFF0D0235), - ) - - val subtextEmphasis: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Black, - fontSize = 11.11.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 15.18.sp, - letterSpacing = 0.5.sp, - color = Color(0xFF0D0235), - ) - - val subtextLarge: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 13.33.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 20.sp, - ) - - val subtextSmall: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 12.sp, - lineHeight = 20.sp, - ) - - val subtextLargeEmphasis: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Black, - fontSize = 13.33.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 20.sp, - color = Color(0xFF0D0235), - ) - - val glucose: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Light, - fontSize = 57.33.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 57.33.sp - ) - - val glucoseUnits: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Light, - fontSize = 16.sp * FontScaleHolder.getScaleFactor(), - lineHeight = 16.sp - ) - - val shareSubtitle: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 14.sp, - lineHeight = 21.sp, - letterSpacing = 5.sp - ) - - val shareTypeTitle: TextStyle = TextStyle( - fontFamily = fonts, - fontWeight = FontWeight.Medium, - fontSize = 16.sp, - lineHeight = 19.2.sp - ) - - fun editStyle( - baseStyle: TextStyle, - fontFamily: FontFamily? = null, - fontWeight: FontWeight? = null, - fontSize: TextUnit? = null, - lineHeight: TextUnit? = null, - color: Color? = null, - textAlign: TextAlign? = null, - letterSpacing: TextUnit? = null - ) = baseStyle.copy( - fontFamily = fontFamily ?: baseStyle.fontFamily, - fontWeight = fontWeight ?: baseStyle.fontWeight, - fontSize = fontSize ?: baseStyle.fontSize, - lineHeight = lineHeight ?: baseStyle.lineHeight, - color = color ?: baseStyle.color, - textAlign = textAlign ?: baseStyle.textAlign, - letterSpacing = letterSpacing ?: baseStyle.letterSpacing - ) -} \ No newline at end of file diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 2344233..ba74dc7 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -1,4 +1,3 @@ Compose Markdown - - The **coolio graph** shows your past 7 days of awesomeness readings, and your favorite toys can be found in the chest.\n\n- The **capture arrow** indicates if your gremlin is rising or falling, while the **+Jump** button allows you to capture important gremlins throughout the day.\n\n- The **fly range** is the purple region. TikTok displays your **XYZ** on the left of the screen, which is how long you stayed in the target zone. \ No newline at end of file