Updated the README to reflect the support for styling through XML

This commit is contained in:
Cyrus Bakhtiari-Haftlang 2018-08-14 11:28:54 +02:00
parent 6c25acf29e
commit 09e45f2916

View File

@ -30,6 +30,25 @@ These are XML attributes:
``` ```
app:mv_markdown="string" app:mv_markdown="string"
app:mv_configurationProvider="string" app:mv_configurationProvider="string"
app:mv_H1Style="reference"
app:mv_H2Style="reference"
app:mv_H3Style="reference"
app:mv_H4Style="reference"
app:mv_H5Style="reference"
app:mv_H6Style="reference"
app:mv_EmphasisStyle="reference"
app:mv_StrongEmphasisStyle="reference"
app:mv_BlockQuoteStyle="reference"
app:mv_CodeSpanStyle="reference"
app:mv_MultilineCodeSpanStyle="reference"
app:mv_OrderedListItemStyle="reference"
app:mv_BulletListItemStyle="reference"
app:mv_TaskListItemStyle="reference"
app:mv_TableRowStyle="reference"
app:mv_ParagraphStyle="reference"
app:mv_LinkStyle="reference"
``` ```
`mv_markdown` accepts a string and represents raw markdown `mv_markdown` accepts a string and represents raw markdown
@ -38,4 +57,51 @@ app:mv_configurationProvider="string"
for example: `com.example.my.package.MyConfigurationProvider` (this class must have an empty constructor for example: `com.example.my.package.MyConfigurationProvider` (this class must have an empty constructor
in order to be instantiated via reflection). in order to be instantiated via reflection).
Please note that those views parse markdown in main thread, so their usage must be for relatively small markdown portions only Please note that those views parse markdown in main thread, so their usage must be for relatively small markdown portions only.
An `mv_*Style` may refer to an actual style or a theme attribute that resolves to a style as well as support for `android:textAppearance` which is basically a sub-style. Currently the following attributes are supported:
* `android:textColor`
* `android:textColorLink`
* `android:textSize`
* `android:textStyle`
* `android:fontFamily`
* `fontFamily`
* `android:typeface`
* `android:textAppeance`
* `android:textColor`
* `android:textColorLink`
* `android:textSize`
* `android:textStyle`
* `android:fontFamily`
* `fontFamily`
* `android:typeface`
A theme level style may be set through the theme attribute `markwonViewStyle`.
Note that, just like `TextView`, values included in `textAppearance` are canceled by values in the root style. Also mimicking `AppCompatTextView`, `android:fontFamily` takes precedence over `fontFamily`.
## Example
```XML
<ru.noties.markwon.view.MarkwonViewCompat
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:mv_H1Style="@style/MyH1Style"
app:mv_H2Style="?myThemesH2Style"
app:mv_H3Style="@style/MyH3Style"
app:mv_H4Style="?android:textAppearanceLarge"
app:mv_H5Style="?android:textAppearanceMediumInverse"
app:mv_H6Style="?android:textAppearanceButton"
app:mv_EmphasisStyle="@style/MyEmphasisStyleWithCustomFont"
app:mv_StrongEmphasisStyle="?myThemesStrongEmphasisStyleWithCustomFont"
app:mv_BlockQuoteStyle="@null"
app:mv_CodeSpanStyle="@style/MyCodeSpanStyle"
app:mv_MultilineCodeSpanStyle="?myThemesMultilineCodeSpan"
app:mv_OrderedListItemStyle="?android:textAppearanceListItem"
app:mv_BulletListItemStyle="?android:textAppearanceListItemSmall"
app:mv_TaskListItemStyle="?android:textAppearanceSearchResultSubtitle"
app:mv_TableRowStyle="?android:textAppearanceSearchResultTitle"
app:mv_LinkStyle="?android:textAppearanceSmallPopupMenu"
app:mv_markdown="@string/some_markdown_string_resource" />
```
In the above example, the paragraph text will get the style of the widget itself `style="?android:textAppearanceSmall"`. If a particular markup style is not specified or specified as `@null` Markwon's original spans will be applied for text with that markup. Otherwise the styling will be based on the resolved attributes. By supplying a valid `app:mv_ParagraphStyle` the default text (paragraph) will be spanned explicitly.