diff --git a/src/transform/md.ts b/src/transform/md.ts index cd0e11a0..fd8fced1 100644 --- a/src/transform/md.ts +++ b/src/transform/md.ts @@ -9,7 +9,6 @@ import attrs from 'markdown-it-attrs'; import extractTitle from './title'; import getHeadings from './headings'; import sanitizeHtml from './sanitize'; -import {getDefaultPublicPath} from './utils'; function initMarkdownit(options: OptionsType) { const {allowHTML = false, linkify = false, breaks = true, highlightLangs = {}} = options; @@ -88,10 +87,10 @@ function initParser(md: MarkdownIt, options: OptionsType, env: EnvType) { extractTitle: extractTitleOption, needTitle, needFlatListHeadings = false, - getPublicPath = getDefaultPublicPath, + getPublicPath, } = options; - const href = getPublicPath(options); + const href = getPublicPath ? getPublicPath(options) : ''; let tokens = md.parse(input, env); diff --git a/src/transform/plugins/anchors/index.ts b/src/transform/plugins/anchors/index.ts index 6c82af00..6a1b65fe 100644 --- a/src/transform/plugins/anchors/index.ts +++ b/src/transform/plugins/anchors/index.ts @@ -1,7 +1,7 @@ import {bold} from 'chalk'; import GithubSlugger from 'github-slugger'; -import {getDefaultPublicPath, headingInfo} from '../../utils'; +import {headingInfo} from '../../utils'; import {CUSTOM_ID_EXCEPTION, CUSTOM_ID_REGEXP} from './constants'; import StateCore from 'markdown-it/lib/rules_core/state_core'; import Token from 'markdown-it/lib/token'; @@ -76,17 +76,11 @@ interface Options { extractTitle?: boolean; supportGithubAnchors?: boolean; transformLink: (v: string) => string; - getPublicPath: (options: Options, v?: string) => string; + getPublicPath?: (options: Options, v?: string) => string; } const index: MarkdownItPluginCb = (md, options) => { - const { - extractTitle, - path, - log, - supportGithubAnchors, - getPublicPath = getDefaultPublicPath, - } = options; + const {extractTitle, path, log, supportGithubAnchors, getPublicPath} = options; const plugin = (state: StateCore) => { /* Do not use the plugin if it is included in the file */ @@ -94,7 +88,7 @@ const index: MarkdownItPluginCb = (md, options) => { return; } - const href = getPublicPath(options, state.env.path); + const href = getPublicPath ? getPublicPath(options, state.env.path) : ''; const ids: Record = {}; const tokens = state.tokens; diff --git a/src/transform/utils.ts b/src/transform/utils.ts index df047fa4..52777dfc 100644 --- a/src/transform/utils.ts +++ b/src/transform/utils.ts @@ -102,19 +102,3 @@ export function defaultTransformLink(href: string) { return href; } - -export function getDefaultPublicPath( - { - path, - transformLink, - }: { - path?: string; - transformLink?: (href: string) => string; - }, - input?: string | null, -) { - const currentPath = input || path || ''; - const transformer = transformLink || defaultTransformLink; - const href = transformer?.(currentPath) ?? currentPath; - return href; -}