Skip to content

Commit 21dcc54

Browse files
authored
Merge pull request #48 from hossain-khan/develop
Sync `main`
2 parents fe1b5fe + c05d579 commit 21dcc54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+390
-257
lines changed

.github/workflows/android.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
16-
- name: set up JDK 1.8
17-
uses: actions/setup-java@v1
15+
- uses: actions/checkout@v4
16+
# https://github.com/actions/setup-java
17+
- uses: actions/setup-java@v4
1818
with:
19-
java-version: 1.8
19+
distribution: 'zulu' # See 'Supported distributions' for available options
20+
java-version: '17'
2021
- name: Build with Gradle
2122
run: ./gradlew build

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetDropDown.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/migrations.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# android-syntax-highlighter
2-
yet another android syntax highlighter (YAASH)
2+
yet _NOT_ another android syntax highlighter (YNAASH)
33

44
### Objective
55
Explore well established web based syntax highlighter like [PrismJS](https://prismjs.com/) and [highlight.js](https://highlightjs.org/),
@@ -9,25 +9,49 @@ and showcase how anybody can quickly incorporate these into their project by fol
99
> The intention is **NOT** to create another library project that gets abandoned over time.
1010
Feel free to copy parts of code that is necessary for you to add syntax highlighting support to your app.
1111

12+
* Try out the latest [release](https://github.com/amardeshbd/android-syntax-highlighter/releases) - `syntax-highlighter-example-v1.1.apk` _(2.5 MB)_ [[Download](https://github.com/amardeshbd/android-syntax-highlighter/releases/download/v1.1/syntax-highlighter-example-v1.1.apk)]
13+
1214

1315
## Existing Syntax Highlighting Libraries
1416

1517
If you need a library, you may look into following existing projects
1618

1719
1. [CodeView-Android](https://github.com/kbiakov/CodeView-Android) - Display code with syntax highlighting ✨ in native way.
18-
703 :star:, Last updated: Jan 24, 2019
20+
845 :star:, Last updated: Jan 24, 2019
1921
1. [highlightjs-android](https://github.com/PDDStudio/highlightjs-android) - A view for source code syntax highlighting on Android.
20-
283 :star:, Last updated: Sep 8, 2018
22+
310 :star:, Last updated: Aug 19, 2020
2123
1. [Syntax-View-Android](https://github.com/Badranh/Syntax-View-Android) - Beautiful Android Syntax View with line counter it will automatically highlight the code.
22-
42 :star:, Last updated: Mar 24, 2020
24+
56 :star:, Last updated: Mar 24, 2020
25+
1. [KodeEditor](https://github.com/markusressel/KodeEditor) - A simple code editor with syntax highlighting and pinch to zoom.
26+
72 :star:, Last updated: May 19, 2023
27+
1. [HighlightJs View - Android](https://github.com/PDDStudio/highlightjs-android) - A view for source code syntax highlighting on Android.
28+
310 :star:, Last updated: Aug 19, 2020
29+
1. [synta kt s](https://github.com/wingio/syntakts) - Simple to use text parser and syntax highlighter for Kotlin Multiplatform.
30+
7 :star:, Last updated: Nov 11, 2023 _(Actively beind developed with KMP focus)_
2331

24-
> _NOTE: The 'Last updated' and :star: data was taken as of July 16th, 2020_
32+
> _NOTE: The 'Last updated' and :star: data was taken as of Nov 13th, 2023_
2533
2634
------------------------
27-
35+
36+
- [Under the hood](#under-the-hood)
37+
- [1. Choose JS Library](#1-choose-js-library)
38+
- [2. Use HTML+CSS+JS Asset](#2-use-htmlcssjs-asset)
39+
- [3. Load the static HTML on `WebView`](#3-load-the-static-html-on-webview)
40+
- [Example App Screenshots](#screenshot)
41+
- [Building your own Fragment or Custom View](#building-your-own-fragment-or-custom-view)
42+
- [Custom View](#custom-view)
43+
- [PrismJS Template Function](#prismjs-template-function)
44+
- [Creating custom syntax highlighter WebView](#creating-custom-syntax-highlighter-webview)
45+
- [Use custom view from Fragment or Activity](#use-custom-view-from-fragment-or-activity)
46+
- [Fragment](#fragment)
47+
- [Create custom Syntax Highlighter Fragment](#create-custom-syntax-highlighter-fragment)
48+
- [Using the Syntax Highlighter Fragment](#using-the-syntax-highlighter-fragment)
49+
2850
## Under the hood
2951
Here is how you would have syntax highlighting using any modern JavaScript library.
3052

53+
> ps. I also ✍️ wrote a [short blog](https://medium.com/@hossainkhan/source-code-syntax-highlighting-on-android-taking-full-control-b704fd4bd8ee) summarizing the process on Medium.com
54+
3155
### 1. Choose JS Library
3256
There are several popular syntax highlighters. Here I have used Prism JS because it's light weight and one of the popular one.
3357

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.3.72"
3+
ext.kotlin_version = "1.9.22"
44
repositories {
55
google()
6-
jcenter()
6+
mavenCentral()
77
}
88
dependencies {
9-
classpath "com.android.tools.build:gradle:4.0.0"
9+
classpath 'com.android.tools.build:gradle:8.2.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111

1212
// NOTE: Do not place your application dependencies here; they belong
@@ -17,7 +17,7 @@ buildscript {
1717
allprojects {
1818
repositories {
1919
google()
20-
jcenter()
20+
mavenCentral()
2121
}
2222
}
2323

@@ -30,9 +30,9 @@ task clean(type: Delete) {
3030
ext {
3131
// Sdk and tools
3232
// --------------------------------------------------
33-
androidMinSdkVersion = 21 // Lollipop 5.0
34-
androidTargetSdkVersion = 29 // Android 10
35-
androidCompileSdkVersion = 29
33+
androidMinSdkVersion = 29 // Android 10
34+
androidTargetSdkVersion = 34 // Android 14
35+
androidCompileSdkVersion = 34
3636
// Android SDK Build Tools - Versions: https://developer.android.com/studio/releases/build-tools.html
3737
buildToolsVersion = '29.0.3'
3838

example/build.gradle

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
apply plugin: 'com.android.application'
2-
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
}
45

56
android {
67
compileSdkVersion rootProject.ext.androidCompileSdkVersion
7-
buildToolsVersion rootProject.ext.buildToolsVersion
8+
9+
buildFeatures {
10+
viewBinding true
11+
buildConfig true
12+
}
813

914
defaultConfig {
10-
applicationId "dev.hossain.yaash.example"
15+
applicationId "dev.hossain.ynaash.example"
1116
minSdkVersion rootProject.ext.androidMinSdkVersion
1217
targetSdkVersion rootProject.ext.androidTargetSdkVersion
1318
versionCode 2
@@ -30,16 +35,17 @@ android {
3035
kotlinOptions {
3136
jvmTarget = '1.8'
3237
}
38+
namespace 'dev.hossain.ynaash.example'
3339
}
3440

3541
dependencies {
3642
implementation fileTree(dir: "libs", include: ["*.jar"])
3743
implementation project(':highlighter')
3844

3945
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
40-
implementation 'androidx.core:core-ktx:1.3.0'
41-
implementation 'androidx.appcompat:appcompat:1.1.0'
42-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
46+
implementation 'androidx.core:core-ktx:1.12.0'
47+
implementation 'androidx.appcompat:appcompat:1.6.1'
48+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4349

4450
// https://developer.android.com/jetpack/androidx/releases/cardview
4551
implementation "androidx.cardview:cardview:1.0.0"
@@ -48,13 +54,13 @@ dependencies {
4854
// - https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView
4955
// - https://developer.android.com/guide/topics/ui/layout/recyclerview
5056
// - https://developer.android.com/jetpack/androidx/releases/recyclerview
51-
implementation "androidx.recyclerview:recyclerview:1.1.0"
57+
implementation "androidx.recyclerview:recyclerview:1.3.2"
5258

5359
// Timber for logging
5460
implementation "com.jakewharton.timber:timber:4.7.1"
5561

56-
testImplementation 'junit:junit:4.13'
57-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
58-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
62+
testImplementation 'junit:junit:4.13.2'
63+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
64+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
5965

6066
}

0 commit comments

Comments
 (0)