v3.36:未读 RSS 角标去重统计、阅读页空行与字号行距优化
This commit is contained in:
@@ -426,6 +426,58 @@ class ReaderActivity : AppCompatActivity() {
|
||||
return s
|
||||
}
|
||||
|
||||
/** 列表行(无序 / 有序),用于判断两行之间该不该留空行 */
|
||||
private fun isListLine(line: String): Boolean =
|
||||
line.startsWith("- ") || line.startsWith("* ") || line.startsWith("+ ") ||
|
||||
Regex("^\\d+[.)]\\s").containsMatchIn(line)
|
||||
|
||||
/**
|
||||
* 空行收尾。
|
||||
*
|
||||
* Markwon 把每个空行都当成块边界(并叠加 blockMargin),所以「空两行」在阅读页
|
||||
* 会变成明显的空白段,读起来一句一断。多余空行有三个来源:
|
||||
* 1. `</div><br><p>` 这类相邻写法会还原出一行只有反斜杠的硬换行标记;
|
||||
* 2. 块闭合之间夹着源码空白,形成「带空格的空行」,`\n{3,}` 正则匹配不到;
|
||||
* 3. 列表项之间留空行,Markwon 按松散列表把行距整体放大。
|
||||
*
|
||||
* 缩进 4 空格以上的行原样保留(Typecho 正文里的缩进代码块 / 子列表靠它),
|
||||
* 围栏代码块内也原样保留。
|
||||
*/
|
||||
private fun tidyBlank(src: String): String {
|
||||
val out = ArrayList<String>(src.length / 8 + 8)
|
||||
var inFence = false
|
||||
var pendingBlank = false
|
||||
src.lines().forEach { rawLine ->
|
||||
val line = rawLine.trimEnd()
|
||||
val bare = line.trimStart()
|
||||
if (bare.startsWith("```")) {
|
||||
inFence = !inFence
|
||||
if (pendingBlank && out.isNotEmpty()) out.add("")
|
||||
pendingBlank = false
|
||||
out.add(bare)
|
||||
return@forEach
|
||||
}
|
||||
if (inFence) {
|
||||
out.add(line)
|
||||
return@forEach
|
||||
}
|
||||
val text = line.trim()
|
||||
if (text.isEmpty() || text == "\\") {
|
||||
if (out.isNotEmpty()) pendingBlank = true
|
||||
return@forEach
|
||||
}
|
||||
if (pendingBlank) {
|
||||
val prev = out.lastOrNull().orEmpty()
|
||||
if (!(isListLine(prev) && isListLine(text))) out.add("")
|
||||
pendingBlank = false
|
||||
}
|
||||
val indent = line.length - bare.length
|
||||
// 缩进代码块/子列表保缩进;其余按源码缩进剥掉,避免被当成代码块
|
||||
out.add(if (indent >= 4) line else text)
|
||||
}
|
||||
return out.joinToString("\n").trim()
|
||||
}
|
||||
|
||||
/** 渲染:文字段走 Markwon,FlexPhoto 图组横排,独立图片铺满整行 */
|
||||
private fun render(markdown: String) {
|
||||
var raw = if (markdown.contains("<!--markdown-->")) markdown.replace("<!--markdown-->", "")
|
||||
@@ -434,6 +486,8 @@ class ReaderActivity : AppCompatActivity() {
|
||||
raw = raw.replace(Regex("\\{map-\\d+\\}", RegexOption.IGNORE_CASE), "")
|
||||
// 正文混写 HTML 支持:<p>/<br>/<img>/<strong>/<h2> 等转成 Markdown,其余标签剥掉
|
||||
raw = htmlToMarkdownLite(raw)
|
||||
// 空行收尾:Markwon 把每个空行都当块边界,空行一多就成了「一句一断」
|
||||
raw = tidyBlank(raw)
|
||||
// 站里标题常写成 "#标题"(# 后无空格,CommonMark 不识别),补上空格;代码块内不动
|
||||
raw = ensureHeadingSpaces(raw)
|
||||
var body = normalizeFlexTokens(raw)
|
||||
@@ -469,10 +523,10 @@ class ReaderActivity : AppCompatActivity() {
|
||||
private fun addTextSegment(text: String) {
|
||||
if (text.isBlank()) return
|
||||
val tv = TextView(this).apply {
|
||||
textSize = 15f
|
||||
// 正文 16sp + 1.4 倍行高:中文长文按 15sp/1.25 排,段落一多就糊成一片
|
||||
textSize = 16f
|
||||
setTextColor(ContextCompat.getColor(context, R.color.text))
|
||||
// 正文字距放宽一点:15sp 的中文正文按 1.0 行距排,段落一多就糊成一片
|
||||
setLineSpacing(dp(7).toFloat(), 1.25f)
|
||||
setLineSpacing(dp(4).toFloat(), 1.4f)
|
||||
movementMethod = LinkMovementMethod.getInstance()
|
||||
}
|
||||
markwon.setMarkdown(tv, text)
|
||||
@@ -481,7 +535,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
).apply { topMargin = dp(10) },
|
||||
).apply { topMargin = dp(8) },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -561,7 +615,7 @@ class ReaderActivity : AppCompatActivity() {
|
||||
LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
).apply { topMargin = dp(10) },
|
||||
).apply { topMargin = dp(8) },
|
||||
)
|
||||
loadFullWidth(resolved, iv)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user