8000 Created sample folder with library usage · SnipMeDev/Highlights@d42ac81 · GitHub
[go: up one dir, main page]

Skip to content

Commit d42ac81

Browse files
committed
Created sample folder with library usage
1 parent 2cc5c45 commit d42ac81

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

sample/build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
kotlin("jvm") version "1.8.21"
5+
application
6+
}
7+
8+
group = "dev.snipme"
9+
version = "1.0-SNAPSHOT"
10+
11+
repositories {
12+
mavenCentral()
13+
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
14+
}
15+
16+
dependencies {
17+
testImplementation(kotlin("test"))
18+
}
19+
20+
tasks.test {
10000 21+
useJUnitPlatform()
22+
}
23+
24+
tasks.withType<KotlinCompile> {
25+
kotlinOptions.jvmTarget = "1.8"
26+
}
27+
28+
application {
29+
mainClass.set("MainKt")
30+
}
31+
32+
dependencies {
33+
implementation("dev.snipme:highlights:0.3.0-SNAPSHOT")
34+
}

sample/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

sample/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "sample"

sample/src/main/kotlin/Main.kt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import dev.snipme.highlights.Highlights
2+
import dev.snipme.highlights.model.BoldHighlight
3+
import dev.snipme.highlights.model.PhraseLocation
4+
import dev.snipme.highlights.model.SyntaxLanguage
5+
6+
val sampleClass = """
7+
@Serializable
8+
public class ExampleClass {
9+
// Single-line comment
10+
11+
/* Multi-line
12+
* comment */
13+
14+
// Class variables
15+
private int x;
16+
protected float y;
17+
public static final String MESSAGE = "Hello!";
18+
19+
// Constructor
20+
public ExampleClass() {
21+
this.x = 0;
22+
this.y = 0.0f;
23+
}
24+
25+
// Method with parameters and return type
26+
public static int calculateSum(int a, int b) {
27+
int sum = a + b;
28+
return sum;
29+
}
30+
}
31+
""".trimIndent()
32+
33+
fun main(args: Array<String>) {
34+
println("### HIGHLIGHTS ###")
35+
println()
36+
println("Available languages:")
37+
println("${SyntaxLanguage.getNames()}")
38+
println()
39+
println("Available themes:")
40+
println("${Highlights.themes(darkMode = false).keys}")
41+
println()
42+
println("This is a sample class:")
43+
println(sampleClass)
44+
println()
45+
46+
val highlights = Highlights.Builder()
47+
.code(sampleClass)
48+
.language(SyntaxLanguage.JAVA)
49+
.build()
50+
51+
val structure = highlights.getCodeStructure()
52+
53+
println("After analysis there has been found:")
54+
println("${structure.printPhrases(sampleClass)}")
55+
println()
56+
57+
val newInstance = highlights.getBuilder()
58+
.emphasis(PhraseLocation(0, 13))
59+
.build()
60+
61+
println("The emphasis was put on the word:")
62+
val emphasisLocation = newInstance
63+
.getHighlights()
64+
.filterIsInstance<BoldHighlight>()
65+
.first()
66+
.location
67+
68+
println(sampleClass.substring(emphasisLocation.start, emphasisLocation.end))
69+
}

0 commit comments

Comments
 (0)
0