版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1 год назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. import { UserConfig, InlineConfig, Plugin } from 'vite';
  2. import MarkdownIt from 'markdown-it';
  3. import { ConfiguredBuilder, BuilderOptions } from '@yankeeinlondon/builder-api';
  4. import { MaybeRef } from '@vueuse/core';
  5. import * as TE from 'fp-ts/lib/TaskEither.js';
  6. import { Either } from 'fp-ts/lib/Either.js';
  7. import { IElement, Fragment } from '@yankeeinlondon/happy-wrapper';
  8. import { ExistingRawSourceMap } from 'rollup';
  9. type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
  10. /**
  11. * **PipelineStage**
  12. *
  13. * The _stage_ in the transformation pipeline:
  14. *
  15. * - `initialize` - meant for configuration settings
  16. * - `metaExtracted` - all frontmatter has been separated from the text content
  17. * giving you a clear but raw markdown content and frontmatter key/value
  18. * - `parser` - a **markdown-it** parser is initialized; providing the `md` prop
  19. * on the payload. This is where builders who want to act as a markdown-it-plugin
  20. * will want to engage.
  21. * - `parsed` - The **MarkdownIt** parser is initialized and all builders
  22. * have been able to apply their customizations to it.
  23. * - `dom` - The HTML has been converted to a HappyDom tree to allow interested builders
  24. * to manipulate contents using DOM based queries
  25. * - `sfcBlocksExtracted` - SFC blocks (template, script, and an array of customBlocks)
  26. * are ready for builders to inspect/mutate/etc.
  27. * - `closeout` - All mutations of page are complete; builders can hook into this stage
  28. * but will _not_ be able to mutate at this stage
  29. */
  30. type PipelineStage = 'initialize' | 'metaExtracted' | 'parser' | 'parsed' | 'dom' | 'sfcBlocksExtracted' | 'closeout';
  31. interface RulesUse {
  32. ruleName: string;
  33. usage: 'adds' | 'patches' | 'modifies';
  34. description?: string;
  35. }
  36. type Parser<S extends PipelineStage> = S extends 'parser' | 'parsed' | 'dom' | 'sfcBlocksExtracted' | 'closeout' ? {
  37. /** the **MarkdownIT** parser instance */
  38. parser: MarkdownIt;
  39. } : {};
  40. /**
  41. * The **Route** custom-block can be configured with these properties.
  42. *
  43. * Note: this is best done with the _meta_ builder
  44. */
  45. interface RouteConfig {
  46. /** The Route's name */
  47. name?: string;
  48. /** The Route's path */
  49. path?: string;
  50. /** A dictionary of key/value pairs for the route */
  51. meta?: Frontmatter;
  52. }
  53. interface LinkProperty {
  54. rel?: string;
  55. href?: string;
  56. integrity?: string;
  57. crossorigin?: string;
  58. [key: string]: unknown;
  59. }
  60. interface StyleProperty {
  61. type?: string;
  62. [key: string]: unknown;
  63. }
  64. /**
  65. * The <base> element specifies the base URL and/or target for all
  66. * relative URLs in a page.
  67. */
  68. interface BaseProperty {
  69. href?: string;
  70. target?: string;
  71. }
  72. interface ScriptProperty {
  73. /**
  74. * For classic scripts, if the async attribute is present, then the classic
  75. * script will be fetched in parallel to parsing and evaluated as soon as it is
  76. * available.
  77. *
  78. * For module scripts, if the async attribute is present then the scripts and
  79. * all their dependencies will be executed in the defer queue, therefore they will
  80. * get fetched in parallel to parsing and evaluated as soon as they are available.
  81. */
  82. async?: boolean;
  83. crossorigin?: string;
  84. /** only to be used alongside the `src` attribute */
  85. defer?: boolean;
  86. /** Provides a hint of the relative priority to use when fetching an external script. */
  87. fetchPriority?: 'high' | 'low' | 'auto';
  88. integrity?: string;
  89. /**
  90. * This Boolean attribute is set to indicate that the script should not be executed
  91. * in browsers that support ES2015 modules — in effect, this can be used to serve
  92. * fallback scripts to older browsers that do not support modular JavaScript code.
  93. */
  94. nomodule?: boolean;
  95. nonce?: string;
  96. referencePolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url';
  97. src?: string;
  98. type?: string;
  99. [key: string]: unknown;
  100. }
  101. /**
  102. * The properties destined for the HEAD block in the HTML
  103. */
  104. interface HeadProps {
  105. title?: MaybeRef<string>;
  106. meta?: MaybeRef<MetaProperty[]>;
  107. link?: MaybeRef<LinkProperty[]>;
  108. base?: MaybeRef<BaseProperty[]>;
  109. style?: MaybeRef<StyleProperty[]>;
  110. script?: MaybeRef<ScriptProperty[]>;
  111. htmlAttrs?: MaybeRef<Record<string, unknown>[]>;
  112. bodyAttrs?: MaybeRef<Record<string, unknown>[]>;
  113. [key: string]: unknown;
  114. }
  115. /** types available _only_ during initialization */
  116. type Initialization<S extends PipelineStage> = S extends 'initialize' ? {} : {};
  117. interface PipelineUtilityFunctions {
  118. /**
  119. * Adds a `<link>` to the page's header section
  120. */
  121. addLink: (link: LinkProperty) => void;
  122. /**
  123. * Adds a `<script>` reference to the page's header section
  124. */
  125. addScriptReference: (script: ScriptProperty) => void;
  126. /**
  127. * Allows the addition of code which will be brought into the
  128. * `<script setup>` block if using VueJS 3.x and into a normal
  129. * `<script>` block in VueJS2
  130. */
  131. addCodeBlock: (name: string, script: string, forVue2?: string[] | undefined) => void;
  132. /**
  133. * Adds a `<style>` reference to the page's header section
  134. */
  135. addStyleReference: (style: StyleProperty) => void;
  136. /**
  137. * Adds meta-properties to the HEAD section of the page
  138. */
  139. addMetaProperty: (meta: MetaProperty) => void;
  140. /**
  141. * Adds a VueJS `<script>` block to the HTML (which VueJS will eventually place in HEAD). A style block should be named so that downstream consumers
  142. * can -- potentially -- override or further modify the style.
  143. */
  144. addStyleBlock: (name: string, style: IElement | string) => void;
  145. }
  146. type MetaExtracted<S extends PipelineStage> = S extends 'initialize' ? {} : {
  147. /** the frontmatter metadata */
  148. frontmatter: Frontmatter;
  149. /**
  150. * The markdown content (after extracting frontmatter)
  151. */
  152. md: string;
  153. /**
  154. * Meta properties that will be put into the HEAD section
  155. *
  156. */
  157. meta: MetaProperty[];
  158. excerpt?: string;
  159. } & PipelineUtilityFunctions;
  160. type HtmlContent<S extends PipelineStage> = S extends 'parsed' | 'sfcBlocksExtracted' | 'closeout' ? {
  161. /**
  162. * the HTML produced from MD content (and using parser rules passed in)
  163. */
  164. html: string;
  165. } : S extends 'dom' ? {
  166. /**
  167. * the HTML wrapped into a HappyDom fragment
  168. */
  169. html: Fragment;
  170. /**
  171. * If any code blocks were found on the page then their languages will be represented
  172. * here as a `Set<string>`
  173. */
  174. fencedLanguages: Set<string>;
  175. } : {};
  176. type Blocks<S extends PipelineStage> = S extends 'sfcBlocksExtracted' | 'closeout' ? {
  177. /** the SFC's template block (aka, html content) */
  178. templateBlock: string;
  179. /**
  180. * The `<script setup ...>` block.
  181. *
  182. * Since there can only be one block, if the markdown has multiple <script setup>
  183. * blocks then the interior code will be moved into the single code block to retain
  184. * the required cardinality.
  185. */
  186. scriptSetup: string;
  187. /** the traditional <script> blocks found on the page */
  188. scriptBlocks: string[];
  189. /** the style blocks found on the page */
  190. styleBlocks: string[];
  191. /** any other top-level SFC blocks besides the traditional */
  192. customBlocks: string[];
  193. } : {};
  194. type Completed<S extends PipelineStage> = S extends 'closeout' ? {
  195. /** the finalized component in string form */
  196. component: string;
  197. /** The sourcemap from Markdown to SFC */
  198. map?: ExistingRawSourceMap | undefined;
  199. } : {};
  200. type Pipeline<S extends PipelineStage, B extends readonly ConfiguredBuilder<string, BuilderOptions, PipelineStage, string>[] = readonly ConfiguredBuilder<string, BuilderOptions, PipelineStage, string>[]> = {
  201. stage: S;
  202. /** the underlying filename of the source */
  203. fileName: string;
  204. /** the raw content in the file being processed */
  205. content: string;
  206. /** the `vite-plugin-md` options */
  207. options: ResolvedOptions<B>;
  208. /** the Vite config */
  209. viteConfig: UserConfig;
  210. /**
  211. * All properties which are destined for the HEAD section of the HTML
  212. */
  213. head: HeadProps;
  214. /**
  215. * Meta properties associated with a page's route; used
  216. * and managed with the "meta" builder.
  217. */
  218. routeMeta?: RouteConfig;
  219. frontmatter?: Frontmatter;
  220. /**
  221. * Indicates which _languages_ were found on the page; this property typically
  222. * shouldn't be set but rather is managed by the `code()` builder and provided
  223. * for contextual decisions.
  224. */
  225. codeBlockLanguages: {
  226. /** the language setting the page author used */
  227. langsRequested: string[];
  228. /** the language used to parse with the highlighter */
  229. langsUsed: string[];
  230. };
  231. /**
  232. * A store for _named_ VueJS `<style>` blocks which will be injected
  233. * into the SFC component at the appropriate time.
  234. */
  235. vueStyleBlocks: Record<string, IElement>;
  236. /**
  237. * Provides a _named_ set of code blocks which will be injected into
  238. * the VueJS's SFC's `<script setup>` section for Vue 3 and in a
  239. * `<script>` block. All blocks will be setup for Typescript.
  240. *
  241. * Note: contributors may optionally include additional trailing lines
  242. * for Vue2; this will allows you to export variables you've defined.
  243. */
  244. vueCodeBlocks: Record<string, string | [base: string, vue2Exports: string[]]>;
  245. } & Parser<S> & MetaExtracted<S> & HtmlContent<S> & Blocks<S> & Completed<S> & Initialization<S>;
  246. /**
  247. * Carries an Either<T> condition which is either:
  248. * - a _string_ error condition
  249. * - a `Pipeline<S>` value
  250. */
  251. type PipeEither<S extends PipelineStage, B extends readonly GenericBuilder[]> = Either<string, Pipeline<S, B>>;
  252. /**
  253. * Carries an `TaskEither<T>` condition which is either:
  254. * - a _string_ error condition
  255. * - a `() => Promise<Pipeline<S>>` task
  256. */
  257. type PipeTask<S extends PipelineStage, B extends readonly ConfiguredBuilder<string, {}, PipelineStage, string>[]> = TE.TaskEither<string, Pipeline<S, B>>;
  258. /**
  259. * A pipeline payload or either an async `PipeTask<S>` or a synchronous `PipeEither<S>`
  260. */
  261. type PipelinePayload<S extends PipelineStage, B extends readonly GenericBuilder[]> = PipeTask<S, B> | PipeEither<S, B>;
  262. /**
  263. * A _synchronous_ transformer function which:
  264. *
  265. * - receives a payload of `PipeEither<F>`, and
  266. * - converts it to a type of `PipeEither<T>`
  267. */
  268. type SyncPipelineTransformer<F extends PipelineStage, T extends PipelineStage, B extends readonly GenericBuilder[]> = (payload: PipeTask<F, B>) => PipeTask<T, B>;
  269. /**
  270. * An _asynchronous_ transformer function which:
  271. *
  272. * - receives a payload of `PipeTask<F>` (async) or `PipeEither<F>` (sync)
  273. * - converts it to a type of `PipeTask<T>`
  274. */
  275. type AsyncPipelineTransformer<F extends PipelineStage, T extends PipelineStage, B extends readonly GenericBuilder[]> = (payload: PipeTask<F, B>) => PipeTask<T, B>;
  276. type GenericBuilder = ConfiguredBuilder<string, BuilderOptions, PipelineStage, string>;
  277. /**
  278. * The key/value definition for Route Properties.
  279. *
  280. * Note: we know that "layout" is likely and a _string_
  281. * but all other props are possible.
  282. */
  283. interface RouteProperties {
  284. layout?: string;
  285. requiresAuth?: boolean;
  286. section?: string;
  287. [key: string]: unknown;
  288. }
  289. interface SfcBlocks {
  290. /** the HTML template block of the SFC */
  291. html: string;
  292. meta: ProcessedFrontmatter;
  293. /** the _script_ blocks */
  294. script: string;
  295. /**
  296. * Any custom blocks which may exist on the page beyond
  297. * just "script" and "template"
  298. */
  299. customBlocks: string[];
  300. /**
  301. * After all processing, the component's definition is available as a string
  302. */
  303. component: string;
  304. }
  305. /** a `<meta />` property in HTML is defined with the following name/values */
  306. interface MetaProperty {
  307. key?: string;
  308. /**
  309. * the "name" property used by Facebook and other providers who
  310. * use the Opengraph standards
  311. */
  312. property?: string;
  313. /**
  314. * used by google to identify the "name" of the name/value pair
  315. */
  316. itemprop?: string;
  317. /**
  318. * used by Twitter to indicate the "name" field in a meta properties
  319. * name/value pairing
  320. */
  321. name?: string;
  322. /**
  323. * The value of the meta property
  324. */
  325. content?: any;
  326. [key: string]: unknown;
  327. }
  328. /**
  329. * Frontmatter content is represented as key/value dictionary
  330. */
  331. interface Frontmatter {
  332. title?: string;
  333. description?: string;
  334. subject?: string;
  335. category?: string;
  336. name?: string;
  337. excerpt?: string;
  338. image?: string;
  339. layout?: string;
  340. requiresAuth?: boolean;
  341. meta?: MetaProperty[];
  342. [key: string]: unknown;
  343. }
  344. type EnumValues<T extends string | number> = `${T}`;
  345. type Include<T, U, L extends boolean = false> = L extends true ? T extends U ? U extends T ? T : never : never : T extends U ? T : never;
  346. type Retain<T, K extends keyof T> = Pick<T, Include<keyof T, K>>;
  347. interface ExcerptMeta {
  348. fileName: string;
  349. frontmatter: Frontmatter;
  350. }
  351. /**
  352. * A function which receives the full content of the page and
  353. * gives control to the function to determine what part should
  354. * be considered the excerpt.
  355. *
  356. * Example:
  357. * ```ts
  358. * function firstFourLines(content, meta) {
  359. * return content
  360. * .split('\n')
  361. * .slice(0, 4)
  362. * .join(' ')
  363. * }
  364. * ```
  365. */
  366. type ExcerptFunction = ((contents: string, meta: ExcerptMeta) => string) | ((contents: string) => string);
  367. /**
  368. * A callback function to dynamically mutate the frontmatter properties
  369. * ```ts
  370. * const cb: FmValueCallback = (fm, filename) => ({
  371. * ...fm,
  372. * category: filename.includes('blog') ? 'blog' : 'unknown
  373. * })
  374. * ```
  375. */
  376. type FmValueCallback = (fm: Frontmatter, filename: string) => Frontmatter;
  377. /**
  378. * Values allowed to be set as frontmatter props
  379. */
  380. type FmAllowedValue = string | number | undefined | any[] | Symbol | boolean;
  381. /**
  382. * Options for Graymatter parser [[Docs](https://github.com/jonschlinkert/gray-matter#options)]
  383. */
  384. interface GraymatterOptions {
  385. excerpt?: boolean | Function;
  386. /**
  387. * Define custom engines for parsing and/or stringifying frontmatter.
  388. *
  389. * Engines may either be an object with `parse` and (optionally) stringify
  390. * methods, or a function that will be used for parsing only.
  391. *
  392. * **Note:** we offer this because the GrayMatter library does but be sure you
  393. * know what you're doing if you're changing this as this repo has no test to ensure
  394. * that modification of this will work here.
  395. */
  396. engines?: Record<string, () => any>;
  397. /**
  398. * Define the engine to use for parsing front-matter.
  399. *
  400. * ```ts
  401. * { language: 'yaml' }
  402. * ```
  403. *
  404. * **Note:** we offer this because the GrayMatter library does but be sure you
  405. * know what you're doing if you're changing this as this repo has no test to ensure
  406. * that modification of this will work here.
  407. *
  408. * @default "yaml"
  409. */
  410. language?: string;
  411. /**
  412. * Open and close delimiters can be passed in as an array of strings.
  413. *
  414. * **Note:** we offer this because the GrayMatter library does but be sure you
  415. * know what you're doing if you're changing this as this repo has no test to ensure
  416. * that modification of this will work here.
  417. */
  418. delimiters?: string | [string, string];
  419. }
  420. interface ProcessedFrontmatter {
  421. /**
  422. * non-meta props intended for the HEAD of the page
  423. */
  424. head: Record<string, any>;
  425. /**
  426. * Meta properties intended for the HEAD of the page
  427. */
  428. metaProps: MetaProperty[];
  429. /**
  430. * The core metadata that a page contains
  431. */
  432. frontmatter: Frontmatter;
  433. /**
  434. * a dictionary of key/values to that are intended to be associated with the route's
  435. * metadata.
  436. */
  437. routeMeta: RouteProperties;
  438. }
  439. interface Options<B extends readonly ConfiguredBuilder<string, BuilderOptions, PipelineStage, string>[]> {
  440. style?: {
  441. baseStyle?: 'none' | 'github';
  442. };
  443. /** allows adding in Builder's which help to expand functionality of this plugin */
  444. builders?: B;
  445. /**
  446. * Explicitly set the Vue version.
  447. *
  448. * @default auto detected
  449. */
  450. vueVersion?: `2.${string}` | `3.${string}`;
  451. /**
  452. * Enable head support.
  453. *
  454. * You will need to install @vueuse/head and register to App in `main.js`/`main.ts`.
  455. *
  456. * @default false
  457. */
  458. headEnabled?: boolean;
  459. /**
  460. * The head field in frontmatter used to be used for `@vueuse/head`
  461. *
  462. * When an empty string is passed, it will use the root properties of the frontmatter
  463. *
  464. * @default ''
  465. */
  466. headField?: string;
  467. /**
  468. * Parse for frontmatter
  469. *
  470. * @default true
  471. */
  472. frontmatter?: boolean;
  473. /**
  474. * Default values for a frontmatter properties. Property defaults can be static
  475. * values or be provided at build time by a callback function. In cases where
  476. * the callback is used, it must conform to the `FrontmatterDefaultValue`
  477. * type.
  478. *
  479. * All values at the page level will override these property values.
  480. *
  481. * @default {}
  482. */
  483. frontmatterDefaults?: FmValueCallback | Record<string, FmAllowedValue>;
  484. /**
  485. * Can _override_ page-level author's frontmatter properties
  486. */
  487. frontmatterOverrides?: FmValueCallback | Record<string, FmAllowedValue>;
  488. /**
  489. * This property determines how to process "excerpts" within your Markdown files.
  490. *
  491. * - a **boolean** true/false simply turns the feature of looking for an excerpt in the body
  492. * of your page on or off respectively and will use the default separator of "---" when turned on
  493. *
  494. * - a **string** value ensures that excerpt parsing is turned on but that the default separator
  495. * is replaced with whatever you provide.
  496. *
  497. * - a **function** gives you a callback to handle this how you see fit. Refer to the `ExcerptFunction`
  498. * symbol to understand the contract of this callback.
  499. *
  500. * **Note**: in all cases, if the frontmatter props are enabled and a user sets the `excerpt` property
  501. * this will be seen as a "default value" for the excerpt.
  502. *
  503. * @default false
  504. */
  505. excerpt?: boolean | ExcerptFunction | string;
  506. /**
  507. * When using the `excerpt` functionality, this flag determines whether the excerpt text
  508. * found in the body should be _extracted_ from the body of the document.
  509. *
  510. * @default false
  511. */
  512. excerptExtract?: boolean;
  513. /**
  514. * Expose excerpt via expose API.
  515. *
  516. * This is on by default and the feature is primarily used to allow excerpts "on page"
  517. * but block them being exposed externally as an export. This is clearly an edge case.
  518. * If you _are_ using excerpts be sure to set the `excerpt` property.
  519. *
  520. * @default true
  521. */
  522. exposeExcerpt?: boolean;
  523. /**
  524. * Remove custom SFC block
  525. *
  526. * @default ['i18n']
  527. */
  528. customSfcBlocks?: string[];
  529. /**
  530. * Custom function to provide defaults to the frontmatter and
  531. * move certain attributes into the "meta" category.
  532. *
  533. * Note: _overriding this will remove built-in functionality setting
  534. * "meta" properties and the built-in "head" support. Do this only
  535. * if you know what you're doing._
  536. *
  537. * @deprecated all use-cases where overriding this have been removed
  538. * with the introduction of the Builder API
  539. */
  540. frontmatterPreprocess?: (frontmatter: Frontmatter, options: ResolvedOptions<B>) => ProcessedFrontmatter;
  541. /**
  542. * Expose frontmatter via expose API
  543. *
  544. * @default true
  545. */
  546. exposeFrontmatter?: boolean;
  547. /**
  548. * Add `v-pre` to `<code>` tag to escape curly brackets interpolation
  549. *
  550. * @see https://github.com/antfu/vite-plugin-md/issues/14
  551. * @default true
  552. */
  553. escapeCodeTagInterpolation?: boolean;
  554. /**
  555. * Options passed to Markdown It
  556. *
  557. * @default { html: true, linkify: true, typographer: true }
  558. */
  559. markdownItOptions?: MarkdownIt.Options;
  560. /**
  561. * Plugins for Markdown It
  562. *
  563. * **Note:** there is no problem using MarkdownIt plugins whatsoever but in many
  564. * cases you may find that Builder APIs are available that provider greater functionality.
  565. */
  566. markdownItUses?: (MarkdownIt.PluginSimple | [MarkdownIt.PluginSimple | MarkdownIt.PluginWithOptions<any>, any] | any)[];
  567. /**
  568. * A function providing the Markdown It instance gets the ability to apply custom
  569. * settings/plugins
  570. *
  571. * @deprecated prefer use of Builder API which provides an easy mechanism to wrap
  572. *
  573. */
  574. markdownItSetup?: (MarkdownIt: MarkdownIt) => void;
  575. /**
  576. * Options which can be passed to [gray-matter](https://github.com/jonschlinkert/gray-matter)
  577. *
  578. * Note: these are a few obscure and advanced settings and should be avoided unless necessary.
  579. * All core functionality -- some of which the graymatter package provides -- is provided directly
  580. * the root of this options hash (e.g., `excerpt`, `frontmatter`, etc.)
  581. */
  582. grayMatterOptions?: Omit<GraymatterOptions, 'excerpt'>;
  583. /**
  584. * Class name for the page's wrapper <div>
  585. *
  586. * @default 'markdown-body'
  587. */
  588. wrapperClasses?: string | string[];
  589. /**
  590. * A component name which the page will be wrapped with (aka,
  591. * the page becomes HTML and is made a _slot_ for this component)
  592. *
  593. * @default undefined
  594. */
  595. wrapperComponent?: string | undefined | null;
  596. /**
  597. * Custom transformations to apply _before_ and/or _after_ the markdown transformation
  598. *
  599. * Note: these transforms provide _raw_ inputs which means that "code" represents
  600. * markdown content along with possibly frontmatter (in the before state) and all of
  601. * of the SFC blocks (e.g., template, script, custom) in string format.
  602. *
  603. * @deprecated these transforms are available using the Builder API -- as well as many more --
  604. * and this is the preferred means of mutating the transformation pipeline.
  605. */
  606. transforms?: {
  607. before?: (code: string, id: string) => string;
  608. after?: (code: string, id: string) => string;
  609. };
  610. /**
  611. * Optionally allows user to explicitly whitelist files which will be transformed
  612. * from markdown to VueJS components. By default all files with `.md` extension
  613. * are included.
  614. */
  615. include?: FilterPattern;
  616. /**
  617. * Allows user to add a blacklist filter to exclude transforming some of the markdown
  618. * files to VueJS components.
  619. */
  620. exclude?: FilterPattern;
  621. }
  622. interface ResolvedOptions<B extends readonly ConfiguredBuilder<string, BuilderOptions, PipelineStage, string>[] = []> extends Required<Options<B>> {
  623. wrapperClasses: string;
  624. frontmatterDefaults: FmValueCallback | Record<string, FmAllowedValue>;
  625. frontmatterOverrides: FmValueCallback | Record<string, FmAllowedValue>;
  626. /**
  627. * a utility which tests whether a given builder is being used
  628. */
  629. usingBuilder: (name: string) => boolean;
  630. }
  631. interface ViteConfigPassthrough {
  632. mode: UserConfig['mode'];
  633. base: UserConfig['base'];
  634. [key: string]: unknown;
  635. }
  636. type WithConfig<T extends ResolvedOptions<any>> = ViteConfigPassthrough & T;
  637. type ReturnValues = string | string[] | number | boolean | Object;
  638. /**
  639. * Composes the `template` and `script` blocks, along with any other `customBlocks` from
  640. * the raw markdown content along with user options.
  641. */
  642. declare function composeSfcBlocks<B extends readonly GenericBuilder[] = []>(id: string, raw: string, opts?: Options<B>, config?: Partial<ViteConfigPassthrough>): Promise<Pipeline<"closeout", B>>;
  643. type ViteConfig = Readonly<Omit<UserConfig, 'plugins' | 'assetsInclude' | 'optimizeDeps' | 'worker'> & {
  644. configFile: string | undefined;
  645. configFileDependencies: string[];
  646. inlineConfig: InlineConfig;
  647. experimental: any;
  648. }>;
  649. declare function VitePluginMarkdown<O extends Options<any>>(userOptions?: O): Plugin;
  650. export { AsyncPipelineTransformer, BaseProperty, Blocks, Completed, EnumValues, ExcerptFunction, ExcerptMeta, FmAllowedValue, FmValueCallback, Frontmatter, GenericBuilder, GraymatterOptions, HeadProps, HtmlContent, Include, Initialization, LinkProperty, MetaExtracted, MetaProperty, Options, Parser, PipeEither, PipeTask, Pipeline, PipelinePayload, PipelineStage, PipelineUtilityFunctions, ProcessedFrontmatter, ResolvedOptions, Retain, ReturnValues, RouteConfig, RouteProperties, RulesUse, ScriptProperty, SfcBlocks, StyleProperty, SyncPipelineTransformer, ViteConfig, ViteConfigPassthrough, WithConfig, composeSfcBlocks, VitePluginMarkdown as default };