Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 922d31b7df |
@@ -20,8 +20,8 @@ android {
|
||||
applicationId = "com.docmost.app"
|
||||
minSdk = 26
|
||||
targetSdk = 34
|
||||
versionCode = 5
|
||||
versionName = "1.0.4"
|
||||
versionCode = 6
|
||||
versionName = "1.0.5"
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
|
||||
@@ -109,13 +109,26 @@ class VersionViewerActivity : AppCompatActivity() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val history = api.getPageHistoryInfo(pageId, historyId)
|
||||
val htmlContent = if (history.content != null) {
|
||||
val htmlContent: String
|
||||
if (history.content != null) {
|
||||
val content = history.content
|
||||
if (content is String && content.trimStart().startsWith("<")) {
|
||||
htmlContent = content
|
||||
originalTipTapJson = ""
|
||||
} else if (content is Map<*, *>) {
|
||||
val gson = Gson()
|
||||
val json = gson.toJson(history.content)
|
||||
originalTipTapJson = json
|
||||
ContentConverter.tipTapToHtml(json)
|
||||
originalTipTapJson = gson.toJson(content)
|
||||
htmlContent = ContentConverter.contentToHtml(content)
|
||||
} else if (content is String) {
|
||||
originalTipTapJson = content
|
||||
htmlContent = ContentConverter.tipTapToHtml(content)
|
||||
} else {
|
||||
"<p>Sin contenido</p>"
|
||||
htmlContent = "<p>Sin contenido</p>"
|
||||
originalTipTapJson = ""
|
||||
}
|
||||
} else {
|
||||
htmlContent = "<p>Sin contenido</p>"
|
||||
originalTipTapJson = ""
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.docmost.app.utils
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
object ContentConverter {
|
||||
private val gson = Gson()
|
||||
|
||||
fun tipTapJsonToHtml(tipTapJson: String): String {
|
||||
return try {
|
||||
val doc = gson.fromJson(tipTapJson, JsonObject::class.java).asMap()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
nodeToHtml(doc as Map<String, Any?>)
|
||||
val type = object : TypeToken<Map<String, Any?>>() {}.type
|
||||
val doc: Map<String, Any?> = gson.fromJson(tipTapJson, type)
|
||||
nodeToHtml(doc)
|
||||
} catch (e: Exception) {
|
||||
tipTapJson
|
||||
}
|
||||
@@ -18,14 +18,34 @@ object ContentConverter {
|
||||
|
||||
fun tipTapToHtml(tipTapJson: String): String {
|
||||
return try {
|
||||
val doc = gson.fromJson(tipTapJson, JsonObject::class.java).asMap()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
nodeToHtml(doc as Map<String, Any?>)
|
||||
val type = object : TypeToken<Map<String, Any?>>() {}.type
|
||||
val doc: Map<String, Any?> = gson.fromJson(tipTapJson, type)
|
||||
nodeToHtml(doc)
|
||||
} catch (e: Exception) {
|
||||
tipTapJson
|
||||
}
|
||||
}
|
||||
|
||||
fun contentToHtml(content: Any?): String {
|
||||
if (content == null) return "<p>Sin contenido</p>"
|
||||
if (content is String) {
|
||||
return if (content.trimStart().startsWith("<")) {
|
||||
content
|
||||
} else {
|
||||
tipTapToHtml(content)
|
||||
}
|
||||
}
|
||||
if (content is Map<*, *>) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return try {
|
||||
nodeToHtml(content as Map<String, Any?>)
|
||||
} catch (e: Exception) {
|
||||
"<p>Error converting content</p>"
|
||||
}
|
||||
}
|
||||
return "<p>Sin contenido</p>"
|
||||
}
|
||||
|
||||
private fun nodeToHtml(node: Map<String, Any?>): String {
|
||||
val type = node["type"] as? String
|
||||
|
||||
@@ -74,7 +94,13 @@ object ContentConverter {
|
||||
sb.append("</p>")
|
||||
}
|
||||
"heading" -> {
|
||||
val level = (node["attrs"] as? Map<*, *>)?.get("level") as? Int ?: 1
|
||||
val levelRaw = (node["attrs"] as? Map<*, *>)?.get("level")
|
||||
val level = when (levelRaw) {
|
||||
is Int -> levelRaw
|
||||
is Double -> levelRaw.toInt()
|
||||
is Number -> levelRaw.toInt()
|
||||
else -> 1
|
||||
}
|
||||
sb.append("<h$level>")
|
||||
content?.forEach { child ->
|
||||
if (child is Map<*, *>) {
|
||||
|
||||
Reference in New Issue
Block a user