Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): update dependency mdast-util-to-hast to v13 #2176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"json5": "^2.2.3",
"knitwork": "^1.0.0",
"listhen": "^1.0.4",
"mdast-util-to-hast": "^12.3.0",
"mdurl": "^1.0.1",
"mdast-util-to-hast": "^13.0.0",
"micromark-util-sanitize-uri": "^2.0.0",
"ohash": "^1.1.2",
"pathe": "^1.1.1",
"property-information": "^6.2.0",
Expand Down
76 changes: 67 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ export default defineNuxtModule<ModuleOptions>({
defaultLocale: undefined,
highlight: false,
markdown: {
tags: Object.fromEntries(PROSE_TAGS.map(t => [t, `prose-${t}`])),
tags: {
...Object.fromEntries(PROSE_TAGS.map(t => [t, `prose-${t}`])),
code: 'ProseCodeInline'
},
anchorLinks: {
depth: 4,
exclude: [1]
Expand Down
38 changes: 38 additions & 0 deletions src/runtime/components/Prose/ProsePre.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<script lang="ts">
import { defineComponent } from '#imports'

export default defineComponent({
props: {
code: {
type: String,
default: ''
},
language: {
type: String,
default: null
},
filename: {
type: String,
default: null
},
highlights: {
type: Array as () => number[],
default: () => []
},
meta: {
type: String,
default: null
},
class: {
type: String,
default: ''
}
}
})
</script>

<template>
<ProseCode>
<pre :class="$props.class"><slot /></pre>
</ProseCode>
</template>
8 changes: 0 additions & 8 deletions src/runtime/markdown-parser/handler/blockquote.ts

This file was deleted.

60 changes: 36 additions & 24 deletions src/runtime/markdown-parser/handler/code.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import type { H } from 'mdast-util-to-hast'
import { type State } from 'mdast-util-to-hast'
import { type Element, type Properties } from 'hast'
import { type Code } from 'mdast'
import { detab } from 'detab'
import { u } from 'unist-builder'
import type { MdastContent } from 'mdast-util-to-hast/lib'
import { parseThematicBlock } from './utils'

type Node = MdastContent & {
lang: string
meta: string
value: string
}

export default (h: H, node: Node) => {
export default (state: State, node: Code) => {
const lang = (node.lang || '') + ' ' + (node.meta || '')
const { language, highlights, filename, meta } = parseThematicBlock(lang)
const code = node.value ? detab(node.value + '\n') : ''
const value = node.value ? detab(node.value + '\n') : ''

// Create `<code>`.
let result: Element = {
type: 'element',
tagName: 'code',
properties: { __ignoreMap: '' },
children: [{ type: 'text', value }]
}

if (node.meta) {
result.data = { meta: node.meta }
}

state.patch(node, result)
result = state.applyData(node, result)

const properties: Properties = {
language,
filename,
highlights,
meta,
code: value
}

if (node.lang) {
properties.className = ['language-' + node.lang]
}

return h(
node.position,
'code',
{
language,
filename,
highlights,
meta,
code,
className: [`language-${language}`]
},
[h(node, 'pre', {}, [h(node, 'code', { __ignoreMap: '' }, [u('text', code)])])]
)
// Create `<pre>`.
result = { type: 'element', tagName: 'pre', properties, children: [result] }
state.patch(node, result)
return result
}
35 changes: 22 additions & 13 deletions src/runtime/markdown-parser/handler/containerComponent.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import type { H } from 'mdast-util-to-hast'
import { all } from 'mdast-util-to-hast'
import type { MdastContent } from 'mdast-util-to-hast/lib'
import { type State } from 'mdast-util-to-hast'
import { type Element, type Properties } from 'hast'
import { type Nodes as MdastContent } from 'mdast'

type Node = MdastContent & {
tagName: string
attributes?: any
fmAttributes?: any
name: string
attributes?: Properties
fmAttributes?: Properties
}

export default function containerComponent (h: H, node: Node) {
const hast: any = h(node, node.tagName, node.attributes, all(h, node))
export default function containerComponent (state: State, node: Node) {
const result: Element = {
type: 'element',
tagName: node.name,
properties: {
...node.attributes,
...node.data?.hProperties
},
children: state.all(node)
}
state.patch(node, result)

// Inline attributes that passed in MDC sysntax `:component{...attributes}`
hast.attributes = node.attributes
// @ts-ignore Inline attributes that passed in MDC sysntax `:component{...attributes}`
result.attributes = node.attributes

// Attributes define using FrontMatter syntax and YAML format
hast.fmAttributes = node.fmAttributes
// @ts-ignore Attributes define using FrontMatter syntax and YAML format
result.fmAttributes = node.fmAttributes

return hast
return result
}
21 changes: 12 additions & 9 deletions src/runtime/markdown-parser/handler/emphasis.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { H } from 'mdast-util-to-hast'
import { all } from 'mdast-util-to-hast'
import type { MdastContent } from 'mdast-util-to-hast/lib'
import { type State } from 'mdast-util-to-hast'
import { type Element, type Properties } from 'hast'
import { type Emphasis } from 'mdast'

type Node = MdastContent & {
attributes?: any
}

export default function emphasis (h: H, node: Node) {
return h(node, 'em', node.attributes, all(h, node))
export default function emphasis (state: State, node: Emphasis & { attributes?: Properties }) {
const result: Element = {
type: 'element',
tagName: 'em',
properties: node.attributes || {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}
17 changes: 12 additions & 5 deletions src/runtime/markdown-parser/handler/heading.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { H } from 'mdast-util-to-hast'
import { all } from 'mdast-util-to-hast'
import type { MdastContent } from 'mdast-util-to-hast/lib'
import { type State } from 'mdast-util-to-hast'
import { type Element, type Properties } from 'hast'
import { type Heading } from 'mdast'

export default function heading (h: H, node: MdastContent) {
return h(node, 'h' + (node as any).depth, all(h, node))
export default function heading (state: State, node: Heading & { attributes?: Properties }) {
const result: Element = {
type: 'element',
tagName: 'h' + node.depth,
properties: node.attributes || {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}
Loading
Loading