Open RoxyHana opened 5 years ago
I use Kotlin and here's my code:
I created a function so I don't have to repeat the same lines all the time
fun generateNodeElement(tag: String, attrs: String, children: String):NodeElement{
return when (tag){
"a" -> NodeElement("a",hashMapOf("href" to attrs), listOf(NodeText(children)))
"img" -> NodeElement("img",hashMapOf("src" to attrs), emptyList())
else -> NodeElement(tag, emptyMap(), listOf(NodeText(children)))
}
}
fun lineJump(): NodeElement{
return NodeElement("br", emptyMap(), emptyList())
}
fun separator(): NodeElement{
return NodeElement("hr", emptyMap(), emptyList())
}
And I add the content like:
val content = ArrayList<Node>()
content.apply {
add(Aux.generateNodeElement("h3","","Some text")) // has children but not attrs
add(Aux.generateNodeElement("img","http://your_url","")) // has attrs but not children
... // So you don't have to worry about what kind of tag it is to create attrs or children.
}
But I still struggle about the images. An img creates a figure with a figcaption but I have no idea how to put text in the caption.
How do you use formatting for the content?
Thanks!