Skip to content

Commit 0984175

Browse files
authored
fix: native attributes (#51)
1 parent ccb59b2 commit 0984175

File tree

5 files changed

+464
-2
lines changed

5 files changed

+464
-2
lines changed

src/from-markdown.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,12 @@ function exitAttributes () {
227227
stackTop = stackTop.children[stackTop.children.length - 1]
228228
}
229229

230+
// Add attributes to last child of fragment
231+
// Example: `[![Nuxt](https://nuxtjs.org/design-kit/colored-logo.svg){.nest}](https://nuxtjs.org)`
232+
if (stackTop.type === 'fragment') {
233+
stackTop = stackTop.children[stackTop.children.length - 1]
234+
}
235+
230236
stackTop.attributes = cleaned
231237
}
232238

src/to-markdown.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
import { stringifyEntitiesLight } from 'stringify-entities'
77
import type { Parent } from 'mdast-util-to-markdown/lib/types'
8+
import { handle } from 'mdast-util-to-markdown/lib/handle'
9+
import { Context, SafeOptions } from 'mdast-util-to-markdown'
810
import { containerFlow, containerPhrasing, checkQuote } from './mdast-util-to-markdown'
911
import { stringifyFrontMatter } from './frontmatter'
1012

@@ -34,7 +36,22 @@ export default {
3436
handlers: {
3537
containerComponent,
3638
textComponent,
37-
componentContainerSection
39+
componentContainerSection,
40+
image: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
41+
return handle.image(node as any, _, context, safeOptions) + attributes(node, context)
42+
},
43+
link: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
44+
return handle.link(node as any, _, context, safeOptions) + attributes(node, context)
45+
},
46+
strong: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
47+
return handle.strong(node as any, _, context, safeOptions) + attributes(node, context)
48+
},
49+
inlineCode: (node: Parent, _: any, context: Context) => {
50+
return handle.inlineCode(node as any, _, context) + attributes(node, context)
51+
},
52+
emphasis: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
53+
return handle.emphasis(node as any, _, context, safeOptions) + attributes(node, context)
54+
}
3855
}
3956
}
4057

0 commit comments

Comments
 (0)