You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+183-4Lines changed: 183 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,12 @@
2
2
yet another android syntax highlighter (YAASH)
3
3
4
4
### Objective
5
-
Explore well established web based syntax highlighter like [PrismJS](https://prismjs.com/) and [highlight.js](https://highlightjs.org/), and showcase how anybody can quickly incorporate these into their project by following some examples provided here.
5
+
Explore well established web based syntax highlighter like [PrismJS](https://prismjs.com/) and [highlight.js](https://highlightjs.org/),
6
+
and showcase how anybody can quickly incorporate these into their project by following some examples provided here.
6
7
7
-
The objective is not exactly to provide a _library_ that you can use with Gradle.
8
+
9
+
> The intention is **NOT** to create another library project that gets abandoned over time.
10
+
Feel free to copy parts of code that is necessary for you to add syntax highlighting support to your app.
8
11
9
12
10
13
## Existing Syntax Highlighting Libraries
@@ -56,7 +59,8 @@ For example:
56
59
```
57
60
58
61
> NOTE: For most cases, hard coding sample code for each sample-code is not ideal.
59
-
> Soon, we will explore how to make the HTML file as template and inject source code from Activity or Fragment.
62
+
> Soon, we will explore how to make the HTML file as template and inject source code from Activity or Fragment.
63
+
> See [Custom View](#building-your-own-fragment-or-custom-view) section below for detailed instructions.
60
64
61
65
### 3. Load the static HTML on `WebView`
62
66
Finally on your Activity or Fragment, once view is loaded initialize `WebView` with local html file from `assets`.
@@ -73,4 +77,179 @@ webView.apply {
73
77
#### Screenshot
74
78
Here is a screenshot taken from a demo static html page that has syntax highlighting using Prism JS.
> See [SyntaxHighlighterFragment.kt](https://github.com/amardeshbd/android-syntax-highlighter/blob/develop/highlighter/src/main/java/dev/hossain/yaash/prismjs/SyntaxHighlighterFragment.kt)
215
+
> source code for full example.
216
+
217
+
And finally when `Fragment#onViewCreated()` is called, we use the extracted the bundle parameters
From your `Activity` or `Fragment`, create an instance of `SyntaxHighlighterFragment` and add that
245
+
to fragment container on the screen.
246
+
```kotlin
247
+
val fragment =SyntaxHighlighterFragment.newInstance(
248
+
formattedSourceCode ="data class Student(val name: String)",
249
+
language ="kotlin",
250
+
showLineNumbers =true
251
+
)
252
+
```
253
+
254
+
> See [PrismJsDemoActivity.kt](https://github.com/amardeshbd/android-syntax-highlighter/blob/develop/example/src/main/java/dev/hossain/yaash/example/ui/demoprismjs/PrismJsDemoActivity.kt)
0 commit comments