mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-07-12 16:11:34 +08:00
ui(extension): 渲染时剥掉 backend 注入的 '> 来源链接:URL' 行
backend 的 note_helper 会在笔记开头加一行 '> 来源链接:<url>'。侧边栏顶部已经有 封面 + 标题 + 跳原片链接的卡片,再在正文里出现一遍是冗余还吃高度。 MindMap 也会把它当作根节点的兄弟节点,影响导图结构。 加 stripSourceLink() helper(regex 直接复刻 web 端 MarkdownViewer.tsx:468 的处理), 在 MarkdownView 与 MindMap 渲染前剥掉。复制 / 下载导出的 .md 仍保留原行,便于溯源。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import { absolutizeMarkdownImages } from '~/logic/api'
|
import { absolutizeMarkdownImages, stripSourceLink } from '~/logic/api'
|
||||||
|
|
||||||
const props = defineProps<{ markdown: string, title?: string, hideActions?: boolean }>()
|
const props = defineProps<{ markdown: string, title?: string, hideActions?: boolean }>()
|
||||||
|
|
||||||
const md = new MarkdownIt({ html: false, linkify: true, breaks: true })
|
const md = new MarkdownIt({ html: false, linkify: true, breaks: true })
|
||||||
|
|
||||||
const html = computed(() => md.render(absolutizeMarkdownImages(props.markdown || '')))
|
const html = computed(() => md.render(absolutizeMarkdownImages(stripSourceLink(props.markdown || ''))))
|
||||||
|
|
||||||
async function copy() {
|
async function copy() {
|
||||||
await navigator.clipboard.writeText(props.markdown)
|
await navigator.clipboard.writeText(props.markdown)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { onMounted, ref, watch } from 'vue'
|
import { onMounted, ref, watch } from 'vue'
|
||||||
import { Transformer } from 'markmap-lib'
|
import { Transformer } from 'markmap-lib'
|
||||||
import { Markmap } from 'markmap-view'
|
import { Markmap } from 'markmap-view'
|
||||||
import { absolutizeMarkdownImages } from '~/logic/api'
|
import { absolutizeMarkdownImages, stripSourceLink } from '~/logic/api'
|
||||||
|
|
||||||
const props = defineProps<{ markdown: string }>()
|
const props = defineProps<{ markdown: string }>()
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ const transformer = new Transformer()
|
|||||||
function render() {
|
function render() {
|
||||||
if (!svgRef.value)
|
if (!svgRef.value)
|
||||||
return
|
return
|
||||||
const md = absolutizeMarkdownImages(props.markdown || '')
|
const md = absolutizeMarkdownImages(stripSourceLink(props.markdown || ''))
|
||||||
const { root } = transformer.transform(md)
|
const { root } = transformer.transform(md)
|
||||||
if (!mm)
|
if (!mm)
|
||||||
mm = Markmap.create(svgRef.value, undefined, root)
|
mm = Markmap.create(svgRef.value, undefined, root)
|
||||||
|
|||||||
@@ -214,6 +214,13 @@ export function absolutizeMarkdownImages(md: string): string {
|
|||||||
return md.replace(/!\[([^\]]*)\]\((\/static\/[^)]+)\)/g, (_, alt, path) => ``)
|
return md.replace(/!\[([^\]]*)\]\((\/static\/[^)]+)\)/g, (_, alt, path) => ``)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// backend 用 note_helper 在笔记开头插一行 '> 来源链接:URL'。侧边栏顶部已经有原片链接卡片,
|
||||||
|
// 渲染前把它剥掉,避免重复占位。复制/下载的 .md 保留原样以便溯源。
|
||||||
|
// 与 BillNote_frontend/src/pages/HomePage/components/MarkdownViewer.tsx:468 对齐
|
||||||
|
export function stripSourceLink(md: string): string {
|
||||||
|
return md.replace(/^>\s*来源链接:[^\n]*\n*/m, '')
|
||||||
|
}
|
||||||
|
|
||||||
// 单个图片 URL 的处理:相对路径 → 拼后端域名;B 站等带防盗链的封面 → 走后端 image_proxy
|
// 单个图片 URL 的处理:相对路径 → 拼后端域名;B 站等带防盗链的封面 → 走后端 image_proxy
|
||||||
export function resolveImageUrl(url: string | undefined | null): string {
|
export function resolveImageUrl(url: string | undefined | null): string {
|
||||||
if (!url)
|
if (!url)
|
||||||
|
|||||||
Reference in New Issue
Block a user