Revert "Add client-side note encryption"

This reverts commit 5cf5a45682.
This commit is contained in:
eezd committed 2026-10-17 14:56:23 +08:00
1 parent 5cf5a45682
commit b26c5aa693
20 files changed
+39 -899

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
import { expect, it } from 'vitest'
import { imageLinks, rewriteImageLinks } from './links'
it('只列出图片与引用定义的地址,跳过普通链接和代码', () => {
const src = [
'![a](a.assets/1.png) [链接](a.assets/2.png) ![b](<a.assets/有 空格.png> "标题")',
'',
'`![c](a.assets/3.png)`',
'',
'```',
'![d](a.assets/4.png)',
'```',
'',
'![e][ref]',
'',
'[ref]: a.assets/5.png',
].join('\n')
expect(imageLinks(src).map((l) => l.url)).toEqual(['a.assets/1.png', 'a.assets/有 空格.png', 'a.assets/5.png'])
expect(rewriteImageLinks(src, (u) => (u.endsWith('5.png') ? undefined : u.replace('a.assets', 'b.assets')))).toBe(
src.replace('a.assets/1.png', 'b.assets/1.png').replace('a.assets/有 空格', 'b.assets/有 空格'),
)
})
-37
View File
@@ -1,37 +0,0 @@
import { markdownParser } from './html'
/** 图片地址在源码中的位置;url 为书写形式(尖括号已去掉,未解码) */
export interface ImageLink {
from: number
to: number
url: string
}
/** 列出图片 ![](url) 与链接引用定义 [x]: url 中的地址(引用定义可能被图片使用);代码中的不算 */
export function imageLinks(src: string): ImageLink[] {
const out: ImageLink[] = []
markdownParser.parse(src).iterate({
enter(ref) {
if (ref.name !== 'Image' && ref.name !== 'LinkReference') return
const url = ref.node.getChild('URL')
if (!url) return
let { from, to } = url
if (src[from] === '<' && src[to - 1] === '>') [from, to] = [from + 1, to - 1]
out.push({ from, to, url: src.slice(from, to) })
},
})
return out
}
/** 替换图片地址:map 返回 undefined 的保持不变 */
export function rewriteImageLinks(src: string, map: (url: string) => string | undefined): string {
let out = ''
let at = 0
for (const l of imageLinks(src)) {
const next = map(l.url)
if (next === undefined) continue
out += src.slice(at, l.from) + next
at = l.to
}
return out + src.slice(at)
}