Skip to content

Commit

Permalink
Fix markdoc shiki
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Nov 13, 2023
1 parent a9e8ce0 commit 3b0d7d0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/integrations/markdoc/src/extensions/shiki.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import Markdoc from '@markdoc/markdoc';
import { createShikiHighlighter, type ShikiHighlighter } from '@astrojs/markdown-remark';
import { createShikiHighlighter } from '@astrojs/markdown-remark';
import type { ShikiConfig } from 'astro';
import { unescapeHTML } from 'astro/runtime/server/index.js';
import type { AstroMarkdocConfig } from '../config.js';

export default async function shiki(config?: ShikiConfig): Promise<AstroMarkdocConfig> {
let highlighterAsync: Promise<ShikiHighlighter> | undefined;
const highlighter = await createShikiHighlighter(config);

return {
nodes: {
fence: {
attributes: Markdoc.nodes.fence.attributes!,
async transform({ attributes }) {
highlighterAsync ??= createShikiHighlighter(config);
const highlighter = await highlighterAsync;

transform({ attributes }) {
const lang = typeof attributes.language === 'string' ? attributes.language : 'plaintext';
const html = highlighter.highlight(attributes.content, lang);

Expand Down

0 comments on commit 3b0d7d0

Please sign in to comment.