♻️ refactor(vscode): 看板的悬停提示也改走 data-tooltip,插件网页只剩一条提示的路;lint 禁止原生 title
- 看板剩下的原生 title(顶栏按钮、工单卡片、工单详情、会话、Profile 表、改动文件树和 diff、属性表)全部改成 data-tooltip, 禁用的按钮照样弹;只有图标、原来只靠 title 当名字的(审查勾、生成说明、属性说明的 i 图标、没头像的归属人)补上 aria-label - 提示框按原文换行:摘修复弹框里「迁移」列的几个文件一行一个 - 代码阅读 Markdown 链接的标题写成 data-tooltip - eslint 规则:网页 TSX 的 DOM 元素上写 title 报错,iframe 和组件自己的 title 属性不算
This commit is contained in:
1 parent
1f7bf63e27
commit
c8620e6e1b
15 files changed
+86
-46
No files matched your search
@@ -39,4 +39,9 @@ describe('renderMarkdown', () => {
|
||||
expect(renderMarkdown('[相对](./x.md)')).not.toContain('<a')
|
||||
expect(renderMarkdown('')).not.toContain('<img')
|
||||
})
|
||||
|
||||
it('链接的标题走悬停提示(data-tooltip),不写原生 title', () => {
|
||||
expect(renderMarkdown('[文档](https://example.com "接口说明")')).toBe('<p><a href="https://example.com" data-tooltip="接口说明">文档</a></p>\n')
|
||||
expect(renderMarkdown('[文档](https://example.com "")')).toBe('<p><a href="https://example.com">文档</a></p>\n')
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,20 @@ import MarkdownIt from 'markdown-it'
|
||||
const md = new MarkdownIt({ html: false, linkify: true }).disable('image')
|
||||
md.validateLink = url => /^(?:https?|mailto):/i.test(url)
|
||||
|
||||
/** 链接的标题(`[文字](网址 "标题")`)写成 data-tooltip,和页面上别的悬停提示走同一个提示框(components/ui/tooltip.tsx),不用原生 title。 */
|
||||
md.core.ruler.push('link_title_tooltip', (state) => {
|
||||
for (const block of state.tokens) {
|
||||
for (const token of block.children ?? []) {
|
||||
const title = token.type === 'link_open' ? token.attrGet('title') : null
|
||||
if (title === null)
|
||||
continue
|
||||
token.attrs = token.attrs!.filter(([name]) => name !== 'title')
|
||||
if (title)
|
||||
token.attrSet('data-tooltip', title)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
/** 最近渲染过的文字 → HTML,最多留 CACHE_SIZE 段,最久没用的先丢。 */
|
||||
const CACHE_SIZE = 500
|
||||
const cache = new Map<string, string>()
|
||||
|
||||
Reference in new issue
Block a user