diff options
author | pacien | 2018-07-26 11:34:06 +0200 |
---|---|---|
committer | pacien | 2018-07-26 11:34:06 +0200 |
commit | 69bc6c2ae35883286d9c2b8cc77d5fa0a8c37351 (patch) | |
tree | 26d8635694b9d7f61b77772b29a9c980b632cc2c /src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt | |
parent | 4d80dd03b75421f2fb40cb89f9634be47b09a779 (diff) | |
download | pandoc-filter-plantuml-69bc6c2ae35883286d9c2b8cc77d5fa0a8c37351.tar.gz |
Kotlin rewrite, adding diagram options
Diffstat (limited to 'src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt')
-rw-r--r-- | src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt b/src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt new file mode 100644 index 0000000..8b3ddde --- /dev/null +++ b/src/main/kotlin/org/pacien/pandoc/filter/plantuml/PandocNode.kt | |||
@@ -0,0 +1,30 @@ | |||
1 | package org.pacien.pandoc.filter.plantuml | ||
2 | |||
3 | import com.fasterxml.jackson.databind.JsonNode | ||
4 | import com.fasterxml.jackson.databind.node.ObjectNode | ||
5 | import com.fasterxml.jackson.databind.node.TextNode | ||
6 | |||
7 | // Structure of a content node: | ||
8 | // { | ||
9 | // "t": "CodeBlock", | ||
10 | // "c": [ | ||
11 | // [ | ||
12 | // "", | ||
13 | // [ "puml", "otherClass" ], | ||
14 | // [ ["scale", "0.5"], ["key", "value"] ] | ||
15 | // ], | ||
16 | // "@startuml\n@enduml" | ||
17 | // ] | ||
18 | // } | ||
19 | |||
20 | fun JsonNode.type(): String = path("t").asText() | ||
21 | fun JsonNode.classes(): JsonNode = path("c").path(0).path(1) | ||
22 | fun JsonNode.classNames(): List<String> = classes().map(JsonNode::asText) | ||
23 | fun JsonNode.attributes(): JsonNode = path("c").path(0).path(2) | ||
24 | fun JsonNode.attributePair(): Pair<String, String> = Pair(path(0).asText(), path(1).asText()) | ||
25 | fun JsonNode.attributeMap(): Map<String, String> = attributes().associate(JsonNode::attributePair) | ||
26 | fun JsonNode.content(): String = path("c").path(1).asText() | ||
27 | |||
28 | fun ObjectNode.setBlockType(type: String) = apply { set("t", TextNode.valueOf(type)) } | ||
29 | fun ObjectNode.setBlockContent(content: JsonNode) = apply { set("c", content) } | ||
30 | fun ObjectNode.setBlock(type: String, content: JsonNode) = setBlockType(type).setBlockContent(content) | ||