Skip to content

Commit

Permalink
Merge pull request #16 from markusressel/extract_syntaxhighlighter
Browse files Browse the repository at this point in the history
Extract syntaxhighlighter
  • Loading branch information
markusressel authored Jan 26, 2019
2 parents 451449b + d69d2a0 commit 6a93f0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
42 changes: 7 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,11 @@ You have to manage the syntax highlighter yourself and call the `setSyntaxHighli

### Integrated syntax highlighters

This library includes a small set of highlighters for you to use right away without spending time to think about the right code highlighting.
Here you can find a list of those items:

* markdown
* java
* kotlin

To include an existing language just pick the ones you would like to use and import them **in addition** to the `library` core module:

```
dependencies {
...
implementation("com.github.markusressel.KodeEditor:markdown:${codeEditorVersion}")
implementation("com.github.markusressel.KodeEditor:java:${codeEditorVersion}")
implementation("com.github.markusressel.KodeEditor:kotlin:${codeEditorVersion}")
[etc.]
```
Have a look at the [KodeHighlighter section about this](https://github.com/markusressel/KodeHighlighter).

### Writing a custom syntax highlighter

Using your own rules to highlight text in the editor can be achieved by extending the `SyntaxHighlighterBase` class (which implements the `SyntaxHighlighter` interface):

```
class MarkdownSyntaxHighlighter : SyntaxHighlighterBase() {
override fun getRules(): Set<SyntaxHighlighterRule> {
return setOf(HeadingRule(), ItalicRule(), BoldRule(), CodeInlineRule(), CodeLineRule(), TextLinkRule(), ImageLinkRule(), StrikeRule())
}
override fun getDefaultColorScheme(): SyntaxColorScheme {
return DarkBackgroundColorScheme()
}
}
```

A syntax highlighter consists of a **default color scheme** and a **set of rules** that provide information on how to style different parts of the editor text.
Have a look at how the `MarkdownSyntaxHighlighter` is implemented to get a feel for how to implement those methods.
Have a look at the [KodeHighlighter section about this](https://github.com/markusressel/KodeHighlighter).

## Styling

Expand Down Expand Up @@ -157,6 +124,11 @@ or specify them in your application theme (`styles.xml` in dem app) for to apply
</resources>
```

# Contributing

GitHub is for social coding: if you want to write code, I encourage contributions through pull requests from forks
of this repository. Create GitHub tickets for bugs and new features and comment on the ones that you are interested in.

# License

```
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation "com.trello.rxlifecycle2:rxlifecycle-android-lifecycle-kotlin:$rxLifecycleVersion"

// Syntax Highlighting
def kodeHighlighterVersion = "master-SNAPSHOT"
def kodeHighlighterVersion = "v1.0.0"
api("com.github.markusressel.KodeHighlighter:markdown:$kodeHighlighterVersion")

// Zoom Layout Container
Expand Down

0 comments on commit 6a93f0a

Please sign in to comment.