1Text Styling 2============ 3This sample shows how to style text on Android using spans, in Kotlin, using [Android KTX](https://github.com/android/android-ktx). 4 5Introduction 6------------ 7## Features 8Parse some hardcoded text and do the following: 9* Paragraphs starting with “> ” are transformed into quotes. 10* Text enclosed in “```” will be transformed into inline code block. 11* Lines starting with “+ ” or “* ” will be transformed into bullet points. 12To update the text, modify the value of `R.string.display_text`. 13This project is not meant to fully cover the markdown capabilities and has several limitations; for example, quotes do not support nesting other elements. 14 15## Implementation 16The text is parsed in the [`Parser.parse`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/parser/Parser.kt#L42) method and the spans are created in the [`MarkdownBuilder.markdownToSpans`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/renderer/MarkdownBuilder.kt#L43) method. 17To see how to apply one or multiple spans on a string, check out [`MarkdownBuilder.buildElement`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/renderer/MarkdownBuilder.kt#L53). For examples of creating custom spans, see [`BulletPointSpan`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/renderer/spans/BulletPointSpan.kt), [`CodeBlockSpan`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/renderer/spans/CodeBlockSpan.kt) or [`FontSpan`](https://github.com/googlesamples/android-text/blob/master/TextStyling-Kotlin/app/src/main/java/com/android/example/text/styling/renderer/spans/FontSpan.kt). 18 19## Testing 20Text parsing is tested with JUnit tests in `ParserTest`. Span building is tested via Android JUnit tests, in `MarkdownBuilderTest`. 21 22 23Getting Started 24--------------- 25 26Clone this repository, enter the top level directory and run `./gradlew tasks` 27to get an overview of all the tasks available for this project. 28 29Some important tasks are: 30 31``` 32assembleDebug - Assembles all Debug builds. 33installDebug - Installs the Debug build. 34connectedAndroidTest - Installs and runs the tests for Debug build on connected 35devices. 36test - Run all unit tests. 37``` 38 39Screenshots 40----------- 41<img src="../screenshots/main_activity.png" width="30%" /> 42 43Support 44------- 45- Stack Overflow: http://stackoverflow.com/questions/tagged/android-text 46 47If you've found an error in this sample, please file an issue: 48https://github.com/googlesamples/android-text/issues 49 50Patches are encouraged, and may be submitted by forking this project and 51submitting a pull request through GitHub. 52 53License 54-------- 55``` 56Copyright 2018 The Android Open Source Project 57 58Licensed to the Apache Software Foundation (ASF) under one or more contributor 59license agreements. See the NOTICE file distributed with this work for 60additional information regarding copyright ownership. The ASF licenses this 61file to you under the Apache License, Version 2.0 (the "License"); you may not 62use this file except in compliance with the License. You may obtain a copy of 63the License at 64 65 http://www.apache.org/licenses/LICENSE-2.0 66 67Unless required by applicable law or agreed to in writing, software 68distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 69WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 70License for the specific language governing permissions and limitations under 71the License. 72``` 73 74