mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-10 03:10:42 +01:00
chore: various markdown fixes
This commit is contained in:
parent
bd486855f8
commit
242c329d33
@ -19,8 +19,8 @@ internal fun ASTNode.findChildOfTypeRecursive(type: IElementType): ASTNode? {
|
|||||||
|
|
||||||
internal fun String.sanitize(): String = this
|
internal fun String.sanitize(): String = this
|
||||||
.removeEntities()
|
.removeEntities()
|
||||||
.spoilerFixup()
|
.spoilerFixUp()
|
||||||
.quoteFixup()
|
.quoteFixUp()
|
||||||
.expandLemmyHandles()
|
.expandLemmyHandles()
|
||||||
|
|
||||||
private fun String.removeEntities(): String =
|
private fun String.removeEntities(): String =
|
||||||
@ -29,11 +29,12 @@ private fun String.removeEntities(): String =
|
|||||||
.replace("…", "…")
|
.replace("…", "…")
|
||||||
|
|
||||||
|
|
||||||
private fun String.spoilerFixup(): String = run {
|
private fun String.spoilerFixUp(): String = run {
|
||||||
val finalLines = mutableListOf<String>()
|
val finalLines = mutableListOf<String>()
|
||||||
var finalLinesSizeAtLastSpoiler = 0
|
var finalLinesSizeAtLastSpoiler = 0
|
||||||
lines().forEach { line ->
|
lines().forEach { line ->
|
||||||
val isSpoilerOnTopOfStack = finalLinesSizeAtLastSpoiler == finalLines.size
|
val isSpoilerOnTopOfStack =
|
||||||
|
finalLines.isNotEmpty() && finalLinesSizeAtLastSpoiler == finalLines.size
|
||||||
if (line.contains(SpoilerRegex.spoilerOpening)) {
|
if (line.contains(SpoilerRegex.spoilerOpening)) {
|
||||||
if (finalLines.lastOrNull()?.isEmpty() == false) {
|
if (finalLines.lastOrNull()?.isEmpty() == false) {
|
||||||
finalLines += ""
|
finalLines += ""
|
||||||
@ -57,18 +58,15 @@ private fun String.spoilerFixup(): String = run {
|
|||||||
finalLines.joinToString("\n")
|
finalLines.joinToString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.quoteFixup(): String = run {
|
private fun String.quoteFixUp(): String = run {
|
||||||
val finalLines = mutableListOf<String>()
|
val finalLines = mutableListOf<String>()
|
||||||
lines().forEach { line ->
|
lines().forEach { line ->
|
||||||
// removes list inside quotes
|
// removes list inside quotes
|
||||||
val quoteAndList = Regex("^>\\s*?-")
|
val quoteAndList = Regex("^>-")
|
||||||
if (quoteAndList.matches(line)) {
|
val cleanLine = line.replace(quoteAndList, "-")
|
||||||
val cleanLine = line.replace(quoteAndList, ">")
|
val isLastEmpty = finalLines.isNotEmpty() && finalLines.last().isEmpty()
|
||||||
if (cleanLine.isNotEmpty()) {
|
if (!isLastEmpty || cleanLine.isNotEmpty()) {
|
||||||
finalLines += cleanLine
|
finalLines += cleanLine
|
||||||
}
|
|
||||||
} else {
|
|
||||||
finalLines += line
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finalLines.joinToString("\n")
|
finalLines.joinToString("\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user