README.md
1 Text Styling
2 ============
3 This sample shows how to style text on Android using spans, in Kotlin, using [Android KTX](https://github.com/android/android-ktx).
4
5 Introduction
6 ------------
7 ## Features
8 Parse 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.
12 To update the text, modify the value of `R.string.display_text`.
13 This 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
16 The 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.
17 To 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
20 Text parsing is tested with JUnit tests in `ParserTest`. Span building is tested via Android JUnit tests, in `MarkdownBuilderTest`.
21
22
23 Getting Started
24 ---------------
25
26 Clone this repository, enter the top level directory and run `./gradlew tasks`
27 to get an overview of all the tasks available for this project.
28
29 Some important tasks are:
30
31 ```
32 assembleDebug - Assembles all Debug builds.
33 installDebug - Installs the Debug build.
34 connectedAndroidTest - Installs and runs the tests for Debug build on connected
35 devices.
36 test - Run all unit tests.
37 ```
38
39 Screenshots
40 -----------
41 <img src="../screenshots/main_activity.png" width="30%" />
42
43 Support
44 -------
45 - Stack Overflow: http://stackoverflow.com/questions/tagged/android-text
46
47 If you've found an error in this sample, please file an issue:
48 https://github.com/googlesamples/android-text/issues
49
50 Patches are encouraged, and may be submitted by forking this project and
51 submitting a pull request through GitHub.
52
53 License
54 --------
55 ```
56 Copyright 2018 The Android Open Source Project
57
58 Licensed to the Apache Software Foundation (ASF) under one or more contributor
59 license agreements. See the NOTICE file distributed with this work for
60 additional information regarding copyright ownership. The ASF licenses this
61 file to you under the Apache License, Version 2.0 (the "License"); you may not
62 use this file except in compliance with the License. You may obtain a copy of
63 the License at
64
65 http://www.apache.org/licenses/LICENSE-2.0
66
67 Unless required by applicable law or agreed to in writing, software
68 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
69 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
70 License for the specific language governing permissions and limitations under
71 the License.
72 ```
73
74