Skip to content

Commit 26f5b23

Browse files
committed
latest release
1 parent 0962c37 commit 26f5b23

Some content is hidden

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

46 files changed

+5621
-0
lines changed

codeeditor/build.gradle.kts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import java.io.FileInputStream
2+
import java.util.*
3+
4+
plugins {
5+
kotlin("multiplatform")
6+
id("maven-publish")
7+
id("org.jetbrains.compose") version "1.0.1"
8+
id("com.android.library")
9+
}
10+
11+
group = BuildConfig.Info.group
12+
version = BuildConfig.Info.version
13+
14+
kotlin {
15+
android()
16+
android {
17+
publishLibraryVariants("release")
18+
}
19+
jvm("desktop") {
20+
compilations.all {
21+
kotlinOptions.jvmTarget = "11"
22+
}
23+
}
24+
sourceSets {
25+
val commonMain by getting {
26+
dependencies {
27+
api(BuildConfig.Dependencies.Common.Compose.runtime)
28+
api(BuildConfig.Dependencies.Common.Compose.foundation)
29+
api(BuildConfig.Dependencies.Common.Compose.material)
30+
}
31+
}
32+
val commonTest by getting {
33+
dependencies {
34+
implementation(kotlin("test"))
35+
}
36+
}
37+
val androidMain by getting {
38+
dependencies {
39+
40+
}
41+
}
42+
val androidTest by getting {
43+
dependencies {
44+
implementation("junit:junit:4.13")
45+
}
46+
}
47+
val desktopMain by getting {
48+
dependencies {
49+
api(compose.preview)
50+
}
51+
}
52+
val desktopTest by getting
53+
}
54+
}
55+
56+
android {
57+
compileSdkVersion(BuildConfig.Android.compileSdkVersion)
58+
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
59+
defaultConfig {
60+
minSdkVersion(BuildConfig.Android.minSdkVersion)
61+
targetSdkVersion(BuildConfig.Android.targetSdkVersion)
62+
}
63+
compileOptions {
64+
sourceCompatibility = JavaVersion.VERSION_1_8
65+
targetCompatibility = JavaVersion.VERSION_1_8
66+
}
67+
}
68+
69+
val githubProperties = Properties()
70+
githubProperties.load(FileInputStream(rootProject.file("github.properties")))
71+
72+
afterEvaluate {
73+
publishing {
74+
repositories {
75+
maven {
76+
name = "GithubPackages"
77+
/** Configure path of your package repository on Github
78+
* Replace GITHUB_USERID with your/organisation Github userID and REPOSITORY with the repository name on GitHub
79+
*/
80+
url = uri("https://maven.pkg.github.com/timeline-notes/compose-code-editor")
81+
82+
credentials {
83+
/**Create github.properties in root project folder file with gpr.usr=GITHUB_USER_ID & gpr.key=PERSONAL_ACCESS_TOKEN**/
84+
username = (githubProperties["gpr.usr"] ?: System.getenv("GPR_USER")).toString()
85+
password = (githubProperties["gpr.key"] ?: System.getenv("GPR_API_KEY")).toString()
86+
}
87+
}
88+
}
89+
}
90+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wakaztahir.codeeditor"/>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.wakaztahir.codeeditor.model
2+
3+
enum class CodeLang(val value: Array<String>) {
4+
Default(arrayOf("default-code", "default-markup")),
5+
HTML(arrayOf("default-markup")),
6+
C(arrayOf("c")),
7+
CPP(arrayOf("cpp")),
8+
ObjectiveC(arrayOf("cxx")),
9+
CSharp(arrayOf("cs")),
10+
Java(arrayOf("java")),
11+
Bash(arrayOf("bash")),
12+
Python(arrayOf("python")),
13+
Perl(arrayOf("perl")),
14+
Ruby(arrayOf("ruby")),
15+
JavaScript(arrayOf("javascript")),
16+
CoffeeScript(arrayOf("coffee")),
17+
Rust(arrayOf("rust")),
18+
Appollo(arrayOf("apollo")),
19+
Basic(arrayOf("basic")),
20+
Clojure(arrayOf("clj")),
21+
CSS(arrayOf("css")),
22+
Dart(arrayOf("dart")),
23+
Erlang(arrayOf("erlang")),
24+
Go(arrayOf("go")),
25+
Haskell(arrayOf("hs")),
26+
Lisp(arrayOf("lisp")),
27+
Llvm(arrayOf("llvm")),
28+
Lua(arrayOf("lua")),
29+
Matlab(arrayOf("matlab")),
30+
ML(arrayOf("ml")),
31+
OCAML(arrayOf("ml")),
32+
SML(arrayOf("ml")),
33+
FSharp(arrayOf("fs")),
34+
Mumps(arrayOf("mumps")),
35+
N(arrayOf("n", "nemerle")),
36+
Pascal(arrayOf("pascal")),
37+
R(arrayOf("r", "s", "R", "S", "Splus")),
38+
Rd(arrayOf("Rd", "rd")),
39+
Scala(arrayOf("scala")),
40+
SQL(arrayOf("sql")),
41+
Tex(arrayOf("latex", "tex")),
42+
VB(arrayOf("vb", "vbs")),
43+
VHDL(arrayOf("vhdl", "vhd")),
44+
Tcl(arrayOf("tcl")),
45+
Wiki(arrayOf("wiki.meta")),
46+
XQuery(arrayOf("xq", "xquery")),
47+
YAML(arrayOf("yaml", "yml")),
48+
Markdown(arrayOf("md", "markdown")),
49+
JSON(arrayOf("json")),
50+
XML(arrayOf("xml")),
51+
Proto(arrayOf("proto")),
52+
RegEx(arrayOf("regex"))
53+
54+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright (c) 2012 Chan Wai Shing
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining
4+
// a copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to
8+
// permit persons to whom the Software is furnished to do so, subject to
9+
// the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
package com.wakaztahir.codeeditor.parser
22+
23+
/**
24+
* The parser parsed result.
25+
*
26+
* This class include the information needed to highlight the syntax.
27+
* Information includes where the content located in the document (offset and
28+
* length) and what style(s) should be applied on that segment of content.
29+
*
30+
* @author Chan Wai Shing <cws1989></cws1989>@gmail.com>
31+
*/
32+
class ParseResult(
33+
/**
34+
* The start position of the content.
35+
*/
36+
var offset: Int,
37+
/**
38+
* The length of the content.
39+
*/
40+
var length: Int, styleKeys: List<String>?
41+
) {
42+
/**
43+
* The start position of the content.
44+
* @return the start position of the content
45+
*/
46+
/**
47+
* The start position of the content.
48+
* @param offset the start position of the content
49+
*/
50+
/**
51+
* The length of the content.
52+
* @return the length of the content
53+
*/
54+
/**
55+
* The length of the content.
56+
* @param length the length of the content
57+
*/
58+
59+
/**
60+
* The style keys of the content. The style at higher index of the list will
61+
* override the style of the lower index.
62+
*/
63+
protected var styleKeys: MutableList<String>
64+
65+
/**
66+
* Get the style keys represented by one string key, see
67+
* [Theme.getStylesAttributeSet].
68+
* @return the style keys of the content
69+
*/
70+
val styleKeysString: String
71+
get() {
72+
val sb = StringBuilder(10)
73+
var i = 0
74+
val iEnd = styleKeys.size
75+
while (i < iEnd) {
76+
if (i != 0) {
77+
sb.append(" ")
78+
}
79+
sb.append(styleKeys[i])
80+
i++
81+
}
82+
return sb.toString()
83+
}
84+
85+
/**
86+
* The style keys of the content.
87+
* @param styleKey the style key
88+
* @return see the return value of [List.add]
89+
*/
90+
fun addStyleKey(styleKey: String): Boolean {
91+
return styleKeys.add(styleKey)
92+
}
93+
94+
/**
95+
* The style keys of the content.
96+
* @param styleKey the style key
97+
* @return see the return value of [List.remove]
98+
*/
99+
fun removeStyleKey(styleKey: String): Boolean {
100+
return styleKeys.remove(styleKey)
101+
}
102+
103+
/**
104+
* The style keys of the content.
105+
*/
106+
fun clearStyleKeys() {
107+
styleKeys.clear()
108+
}
109+
110+
/**
111+
* {@inheritDoc}
112+
*/
113+
override fun toString(): String {
114+
val sb = StringBuilder()
115+
sb.append("[")
116+
sb.append(offset)
117+
sb.append("; ")
118+
sb.append(length)
119+
sb.append("; ")
120+
var i = 0
121+
val iEnd = styleKeys.size
122+
while (i < iEnd) {
123+
if (i != 0) {
124+
sb.append(", ")
125+
}
126+
sb.append(styleKeys[i])
127+
i++
128+
}
129+
sb.append("]")
130+
return sb.toString()
131+
}
132+
133+
/**
134+
* Constructor.
135+
*
136+
* @param offset the start position of the content
137+
* @param length the length of the content
138+
* @param styleKeys the style keys of the content
139+
*/
140+
init {
141+
this.styleKeys = styleKeys?.toMutableList() ?: mutableListOf()
142+
}
143+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2012 Chan Wai Shing
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining
4+
// a copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to
8+
// permit persons to whom the Software is furnished to do so, subject to
9+
// the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be
12+
// included in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
package com.wakaztahir.codeeditor.parser
22+
23+
/**
24+
* The parser for syntax highlight.
25+
*
26+
* @author Chan Wai Shing <cws1989></cws1989>@gmail.com>
27+
*/
28+
interface Parser {
29+
/**
30+
* Parse the `content` and return the parsed result.
31+
*
32+
* @param fileExtension the file extension of the content, null means not
33+
* provided
34+
* @param content the content
35+
* @return the parsed result
36+
*/
37+
fun parse(fileExtension: String?, content: String): List<ParseResult?>?
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.wakaztahir.codeeditor.prettify
2+
3+
import com.wakaztahir.codeeditor.parser.ParseResult
4+
import com.wakaztahir.codeeditor.parser.Parser
5+
import com.wakaztahir.codeeditor.prettify.parser.Job
6+
import com.wakaztahir.codeeditor.prettify.parser.Prettify
7+
8+
9+
/**
10+
* The prettify parser for syntax highlight.
11+
* @author Chan Wai Shing <cws1989></cws1989>@gmail.com>
12+
*/
13+
class PrettifyParser : Parser {
14+
/**
15+
* The prettify parser.
16+
*/
17+
private var prettify: Prettify = Prettify()
18+
19+
override fun parse(fileExtension: String?, content: String): List<ParseResult> {
20+
val job = Job(0, content)
21+
prettify.langHandlerForExtension(fileExtension, content)?.decorate(job)
22+
val decorations = job.decorations
23+
val returnList: MutableList<ParseResult> = ArrayList()
24+
25+
// apply style according to the style list
26+
var i = 0
27+
val iEnd = decorations.size
28+
while (i < iEnd) {
29+
val endPos = if (i + 2 < iEnd) decorations[i + 2] as Int else content.length
30+
val startPos = decorations[i] as Int
31+
if (endPos != null) {
32+
returnList.add(
33+
ParseResult(startPos, endPos - startPos, listOf((decorations[i + 1] as String)))
34+
)
35+
}
36+
i += 2
37+
}
38+
return returnList
39+
}
40+
}

0 commit comments

Comments
 (0)