From 463a03a9815ce8fc9f55293dda07bc211ef4f62b Mon Sep 17 00:00:00 2001 From: Christopher Shank Date: Tue, 17 Nov 2020 23:38:44 -0800 Subject: [PATCH] feat: add ability to configure markdown options (#127) (#128) close #127 Co-authored-by: Kia Ishii --- src/node/build/bundle.ts | 2 +- src/node/config.ts | 6 +++++- src/node/server.ts | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 7cdabfe755d2..fab681de1c43 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -36,7 +36,7 @@ export async function bundle( const root = config.root const userConfig = await resolveUserConfig(root) const resolver = createResolver(config.themeDir, userConfig) - const markdownToVue = createMarkdownToVueRenderFn(root) + const markdownToVue = createMarkdownToVueRenderFn(root, userConfig.markdown) let isClientBuild = true const pageToHashMap = Object.create(null) diff --git a/src/node/config.ts b/src/node/config.ts index 963596f7aa44..f59cefda3b9b 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -5,6 +5,7 @@ import globby from 'globby' import { createResolver, APP_PATH } from './resolver' import { Resolver } from 'vite' import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared' +import { MarkdownOptions } from './markdown/markdown' export { resolveSiteDataByRoute } from './shared/config' const debug = require('debug')('vitepress:config') @@ -18,6 +19,7 @@ export interface UserConfig { themeConfig?: ThemeConfig locales?: Record alias?: Record + markdown?: MarkdownOptions // TODO locales support etc. } @@ -30,6 +32,7 @@ export interface SiteConfig { tempDir: string resolver: Resolver pages: string[] + markdown?: MarkdownOptions } const resolve = (root: string, file: string) => @@ -55,7 +58,8 @@ export async function resolveConfig( configPath: resolve(root, 'config.js'), outDir: resolve(root, 'dist'), tempDir: path.resolve(APP_PATH, 'temp'), - resolver: createResolver(themeDir, userConfig) + resolver: createResolver(themeDir, userConfig), + markdown: userConfig.markdown } return config diff --git a/src/node/server.ts b/src/node/server.ts index 9ca08a991d58..bc3fb3fe152e 100644 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -15,10 +15,11 @@ const debugHmr = require('debug')('vitepress:hmr') function createVitePressPlugin({ configPath, + markdown, site: initialSiteData }: SiteConfig): ServerPlugin { return ({ app, root, watcher, resolver }) => { - const markdownToVue = createMarkdownToVueRenderFn(root) + const markdownToVue = createMarkdownToVueRenderFn(root, markdown) // hot reload .md files as .vue files watcher.on('change', async (file) => {