Skip to content

Commit

Permalink
fix: update the placeholder to still render the unhighlighted code
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 22, 2025
1 parent c828244 commit d0db092
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export interface MarkdownItAsyncOptions extends Omit<Options, 'highlight'> {

export type { MarkdownItAsyncOptions as Options }

const placeholder = (id: string): string => `<pre>::markdown-it-async::${id}::</pre>`
const placeholderRe = /<pre>::markdown-it-async::(\w+)::<\/pre>/g
const placeholder = (id: string, code: string): string => `<pre><!--::markdown-it-async::${id}::--><code>${code}</code></pre>`
const placeholderRe = /<pre><!--::markdown-it-async::(\w+)::--><code>[\s\S]*?<\/code><\/pre>/g

function randStr(): string {
return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2)
Expand Down Expand Up @@ -141,7 +141,7 @@ function wrapHightlight(highlight: MarkdownItAsyncOptions['highlight'], map: Mar
return promise
const id = randStr()
map.set(id, [promise, str, lang, attrs])
return placeholder(id)
return placeholder(id, str)
}

wrappedSet.add(wrapped)
Expand Down

0 comments on commit d0db092

Please sign in to comment.