Skip to content

Commit dc450ea

Browse files
committed
Kotbot 1.6.0
1 parent 32ef4c3 commit dc450ea

File tree

18 files changed

+26788
-63
lines changed

18 files changed

+26788
-63
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
* [Tgkotbot](https://github.com/Heapy/kotbot/tree/main/tgkotbot#readme) – Bot implementation for needs
66
of [Kotlin Community](https://t.me/kotlin_lang) in the telegram
77

8-
## Bot API 9.4
8+
## Bot API 9.5
99

1010
### Install the library
1111

1212
```kotlin
13-
implementation("io.heapy.kotbot:core:1.5.0")
13+
implementation("io.heapy.kotbot:core:1.6.0")
1414
```
1515

1616
### Example

api-parser/src/main/kotlin/io/heapy/kotbot/apiparser/HtmlExtractor.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ data class RawField(
4545
)
4646

4747
object HtmlExtractor {
48-
private val RELEVANT_TAGS = setOf("h3", "h4", "p", "table", "ul")
49-
5048
fun extract(html: String): ExtractedApi {
5149
val doc = Jsoup.parse(html)
5250
val content = doc.select("#dev_page_content").first()
@@ -118,7 +116,7 @@ object HtmlExtractor {
118116
i++
119117
}
120118
is State.GetDescription -> {
121-
val s = state as State.GetDescription
119+
val s = state
122120
if (tag == "p" || tag == "ul") {
123121
s.description.add(elem)
124122
i++
@@ -136,7 +134,7 @@ object HtmlExtractor {
136134
} else {
137135
// For objects with a UL as last description + elements UL
138136
if (hasNextUl && !isMethod) {
139-
s.description.add(nextElem!!)
137+
s.description.add(nextElem)
140138
}
141139

142140
when {
@@ -176,7 +174,7 @@ object HtmlExtractor {
176174
}
177175
}
178176
is State.GetObjectFields -> {
179-
val s = state as State.GetObjectFields
177+
val s = state
180178
if (tag == "table") {
181179
val fields = extractFields(elem)
182180
objects.add(RawObject(
@@ -190,7 +188,7 @@ object HtmlExtractor {
190188
i++
191189
}
192190
is State.GetMethodFields -> {
193-
val s = state as State.GetMethodFields
191+
val s = state
194192
if (tag == "table") {
195193
val args = extractArguments(elem)
196194
methods.add(RawMethod(
@@ -204,7 +202,7 @@ object HtmlExtractor {
204202
i++
205203
}
206204
is State.GetObjectElements -> {
207-
val s = state as State.GetObjectElements
205+
val s = state
208206
if (tag == "ul") {
209207
val elems = elem.select("li").map { it.plainText() }
210208
objects.add(RawObject(

core-gen/src/main/kotlin/Generate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import io.heapy.kotbot.apiparser.model.nullable
3838
import kotlin.io.path.Path
3939

4040
fun main() {
41-
val apiResource = "api940"
41+
val apiResource = "api950"
4242
val apiHtml = {}::class.java
4343
.getResource(apiResource)
4444
?.readText()

core-gen/src/main/kotlin/Parse.kt

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.jsoup.Jsoup
44
import org.jsoup.nodes.Element
5-
import org.jsoup.select.Elements
65
import kotlin.io.path.Path
76
import kotlin.io.path.readText
87
import kotlin.io.path.writeText
@@ -31,6 +30,7 @@ fun main() {
3130
"api900",
3231
"api920",
3332
"api940",
33+
"api950",
3434
).forEach { v ->
3535
val input = rootPath.resolve(v).readText()
3636
val output = processVersion(input)
@@ -96,48 +96,3 @@ fun processVersion(input: String): String {
9696
}
9797
}
9898
}
99-
100-
fun buildGraph(children: Elements) {
101-
val root = Element("h0")
102-
val tree = mutableMapOf<Element, MutableList<Element>>(root to mutableListOf())
103-
val stack = ArrayDeque(listOf(root))
104-
105-
children.forEach { el ->
106-
when (el.tagName()) {
107-
"h1", "h2", "h3", "h4", "h5", "h6" -> {
108-
stack.lastOrNull()?.let { last ->
109-
when {
110-
last.level == el.level -> {
111-
stack.removeLast()
112-
stack.add(el)
113-
tree[el] = mutableListOf()
114-
}
115-
116-
last.level < el.level -> {
117-
stack.add(el)
118-
tree[el] = mutableListOf()
119-
}
120-
121-
last.level > el.level -> {
122-
stack.removeLast()
123-
stack.removeLast()
124-
stack.add(el)
125-
tree[el] = mutableListOf()
126-
}
127-
128-
else -> error("Unhandled case")
129-
}
130-
} ?: run {
131-
tree[el] = mutableListOf()
132-
stack.add(el)
133-
}
134-
}
135-
136-
"p", "ul", "table", "hr", "pre", "ol", "blockquote" -> {
137-
tree[stack.last()]!!.add(el)
138-
}
139-
140-
else -> println("Unknown tag: ${el.tagName()}")
141-
}
142-
}
143-
}

0 commit comments

Comments
 (0)