Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Sep 3, 2024
1 parent fcd245c commit 65ded21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export interface Theme {
inline: Record<Inline, PropertiesHyphen>
}

export interface IOpts {
theme: Theme
fonts: string
size: string
legend: string
status: boolean
}

export type ThemeStyles = Record<Block | Inline, ExtendedProperties>

export interface IConfigOption {
Expand Down
23 changes: 5 additions & 18 deletions src/utils/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mermaid from 'mermaid'
import { toMerged } from 'es-toolkit'

import type { PropertiesHyphen } from 'csstype'
import type { ExtendedProperties, Theme, ThemeStyles } from '@/types'
import type { ExtendedProperties, IOpts, ThemeStyles } from '@/types'

marked.use(
markedKatex({
Expand All @@ -16,16 +16,7 @@ marked.use(
}),
)

interface IOpts {
theme: Theme
fonts: string
size: string
legend: string
status: boolean
}

function buildTheme(opts: IOpts): ThemeStyles {
const { theme, fonts, size } = opts
function buildTheme({ theme, fonts, size }: IOpts): ThemeStyles {
const base = toMerged(theme.base, {
'font-family': fonts,
'font-size': size,
Expand Down Expand Up @@ -85,6 +76,9 @@ export function initRenderer(opts: IOpts) {
const footnotes: [number, string, string][] = []
let footnoteIndex: number = 0
let styleMapping: ThemeStyles = buildTheme(opts)
let codeIndex: number = 0
let listIndex: number = 0
let isOrdered: boolean = false

function styledContent(styleLabel: string, content: string, tagName?: string): string {
const tag = tagName ?? styleLabel
Expand Down Expand Up @@ -118,13 +112,6 @@ export function initRenderer(opts: IOpts) {
)
}

// 用于 Mermaid 渲染
let codeIndex = 0

// 用于列表渲染
let listIndex = 0
let isOrdered = false

const renderer: RendererObject = {
heading({ tokens, depth }) {
const text = this.parser.parseInline(tokens)
Expand Down

0 comments on commit 65ded21

Please sign in to comment.