Skip to content

Commit 7782e7a

Browse files
committed
refactor(markdown): improve type safety and update comments
1 parent 306f96b commit 7782e7a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/dev.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import style from '../index.css?raw'
1010
import katex from '../katex.css?raw'
1111
import { layoutSSR, renderSSRHTML } from './utils/layout-ssr'
1212
import { snapdom } from '@zumer/snapdom'
13+
import type { Tokens } from 'marked'
1314
import { marked } from 'marked'
1415

1516
interface Window {
@@ -48,7 +49,7 @@ const options: Options = {
4849
markdown: (text: string) => {
4950
// Configure marked renderer to add target="_blank" to links
5051
const renderer = {
51-
link(token: any) {
52+
link(token: Tokens.Link) {
5253
const href = token.href || ''
5354
const title = token.title ? ` title="${token.title}"` : ''
5455
const text = token.text || ''

src/utils/layout-ssr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ export const renderSSRHTML = function (
190190
const tagsHtml = node.tags
191191
.map(tag => {
192192
if (typeof tag === 'string') {
193-
// 兼容原来的字符串配置
193+
// Compatible with legacy string configuration
194194
return `<span class="me-tag">${escapeHtml(tag)}</span>`
195195
} else {
196-
// 支持对象配置
196+
// Support object configuration
197197
let classAttr = 'me-tag'
198198
if (tag.className) {
199199
classAttr += ` ${tag.className}`
@@ -204,7 +204,7 @@ export const renderSSRHTML = function (
204204
const styles = Object.entries(tag.style)
205205
.filter(([_, value]) => value !== undefined && value !== null && value !== '')
206206
.map(([key, value]) => {
207-
// 将驼峰命名转换为CSS属性名
207+
// Convert camelCase to CSS property name
208208
const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase()
209209
return `${cssKey}: ${value}`
210210
})

0 commit comments

Comments
 (0)