Skip to content

Commit 0899618

Browse files
committed
fix: disable markdown-it-attrs for fenced code blocks
BREAKING CHANGE: `markdown-it-attrs` is disabled for fenced code blocks. For most users no change is required. If you want to add classes to code blocks, do it using shiki transformers instead.
1 parent a6e6e59 commit 0899618

File tree

6 files changed

+30
-56
lines changed

6 files changed

+30
-56
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/patterns.js b/patterns.js
2+
index e56a3b785df29e726194f2b30e86bb19a78ef902..e1f6211b92cbb2bbbe2a3c317dd9e5f1f41ab8d1 100644
3+
--- a/patterns.js
4+
+++ b/patterns.js
5+
@@ -28,7 +28,8 @@ module.exports = options => {
6+
{
7+
shift: 0,
8+
block: true,
9+
- info: utils.hasDelimiters('end', options)
10+
+ info: utils.hasDelimiters('end', options),
11+
+ markup: (str) => !/^[`~]{3,}$/.test(str)
12+
}
13+
],
14+
transform: (tokens, i) => {

pnpm-lock.yaml

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ patchedDependencies:
1717
'@types/markdown-it-attrs': patches/@types__markdown-it-attrs.patch
1818
'@types/mdurl@2.0.0': patches/@types__mdurl@2.0.0.patch
1919
markdown-it-anchor@9.2.0: patches/markdown-it-anchor@9.2.0.patch
20+
markdown-it-attrs@4.3.1: patches/markdown-it-attrs@4.3.1.patch
2021

2122
shellEmulator: true

src/node/markdown/markdown.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import type { Awaitable } from '../shared'
3030
import { containerPlugin, type ContainerOptions } from './plugins/containers'
3131
import { gitHubAlertsPlugin } from './plugins/githubAlerts'
3232
import { highlight as createHighlighter } from './plugins/highlight'
33-
import { highlightLinePlugin } from './plugins/highlightLines'
3433
import { imagePlugin, type Options as ImageOptions } from './plugins/image'
3534
import { lineNumberPlugin } from './plugins/lineNumbers'
3635
import { linkPlugin } from './plugins/link'
@@ -271,7 +270,6 @@ export async function createMarkdownRenderer(
271270

272271
// custom plugins
273272
componentPlugin(md, options.component)
274-
highlightLinePlugin(md)
275273
preWrapperPlugin(md, {
276274
codeCopyButtonTitle,
277275
languageLabel: options.languageLabel

src/node/markdown/plugins/highlight.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,16 @@ export async function highlight(
100100
const vueRE = /-vue$/
101101

102102
return [
103-
async (str: string, lang: string, attrs: string) => {
104-
lang = langRE.exec(lang)?.[0].toLowerCase() || defaultLang
103+
async (str, lang, attrs) => {
104+
const match = langRE.exec(lang)
105+
if (match) {
106+
const orig = lang
107+
lang = match[0].toLowerCase()
108+
attrs = orig.slice(lang.length).replace(/(?<!=)\{/g, ' {') + ' ' + attrs
109+
attrs = attrs.trim().replace(/\s+/g, ' ')
110+
}
111+
112+
lang ||= defaultLang
105113

106114
const vPre = !vueRE.test(lang)
107115
if (!vPre) lang = lang.slice(0, -4)

src/node/markdown/plugins/highlightLines.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)