v3.39(versionCode 60)

This commit is contained in:
XIGE
2026-11-27 10:33:56 +08:00
parent 2f75bcf559
commit fb491c9658
2 changed files with 51 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
## 2026-11-27 · v3.39(versionCode 60)
- 阅读页代码块改为独立代码卡:左侧行号、语法高亮、内容可横向滚动,顶部标注语言;长按整段复制。
- Markwon core 不带表格插件,正文里的 pipe 表格改按「- **键**:值」列表重排,多列用 ` · ` 连接,不再是一片 `| a | b |` 的竖线文本。
- 新增本地语法高亮 `CodeHighlight`:一趟扫描识别注释(`//`、`#`、`/* */`)、字符串(含三引号跨行)、数字、关键字、注解与函数调用;配色分深浅两套并跟随夜间模式。未引入 Prism4j,不增加依赖和包体。
- 行号与代码放进同一个 TextView:中文注释回退字体导致行高变化时也不会错位半行。
- `RssApi` 从 `<pre><code class="language-xxx">` 提取语言标注,随围栏代码块一起带到阅读页。

View File

@@ -105,6 +105,9 @@ class ReaderActivity : AppCompatActivity() {
/** 正文短于这么多字就不必麻烦 AI 了 */
private const val BRIEF_MIN_CHARS = 200
/** pipe 表格的分隔行(| --- | :---: |),用来确认上面一行是表头 */
private val PIPE_SEP = Regex("^\\|[\\s:|-]+\\|$")
const val KIND_RSS = "rss"
const val KIND_ARTICLE = "article"
const val KIND_MEMO = "memo"
@@ -781,6 +784,8 @@ class ReaderActivity : AppCompatActivity() {
// 代码块单独成卡(行号 + 高亮):先抽成占位符,剩下的文字段才交给 Markwon
val codeBlocks = ArrayList<CodeBlock>()
raw = extractCodeBlocks(raw, codeBlocks)
// 表格重排成列表(代码块已占位,不会被误改)
raw = pipeTablesToLists(raw)
var body = normalizeFlexTokens(raw)
// 收集文末引用定义行(站里的定义行带前导空格),供引用式图片解析
val refs = Regex("(?m)^\\s*\\[([^\\]]+)\\]:\\s*(\\S+)")
@@ -820,6 +825,51 @@ class ReaderActivity : AppCompatActivity() {
/** 抽出来的围栏代码块:语言标注 + 原始代码 */
private class CodeBlock(val lang: String, val code: String)
/**
* pipe 表格 → 列表。
*
* Markwon core 不渲染表格(tables 插件不在离线依赖里),原样留着就是一片
* `| 维度 | 结果 |` 的竖线文本。这里按「- **键**:值」重排,多列用 ` · ` 连接,
* 内容一个字不丢,读起来也还是成对的。
*/
private fun pipeTablesToLists(markdown: String): String {
if (!markdown.contains('|')) return markdown
val lines = markdown.lines()
val out = ArrayList<String>(lines.size)
var i = 0
while (i < lines.size) {
val line = lines[i].trim()
val sep = lines.getOrNull(i + 1)?.trim().orEmpty()
if (isPipeRow(line) && PIPE_SEP.matches(sep)) {
out.add(pipeCellsToBullet(splitPipeRow(line)))
var j = i + 2
while (j < lines.size && isPipeRow(lines[j].trim())) {
out.add(pipeCellsToBullet(splitPipeRow(lines[j].trim())))
j++
}
i = j
continue
}
out.add(lines[i])
i++
}
return out.joinToString("\n")
}
private fun isPipeRow(line: String): Boolean =
line.length > 2 && line.startsWith("|") && line.endsWith("|")
private fun splitPipeRow(line: String): List<String> =
line.trim('|').split('|').map { it.trim() }
private fun pipeCellsToBullet(cells: List<String>): String {
val clean = cells.filter { it.isNotEmpty() }
if (clean.isEmpty()) return ""
val key = clean.first()
val rest = clean.drop(1)
return if (rest.isEmpty()) "- **$key**" else "- **$key**:${rest.joinToString(" · ")}"
}
/**
* 把 ``` 围栏代码块换成 `%%CODEn%%` 占位符。
*