Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/from-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ function exitAttributes () {
stackTop = stackTop.children[stackTop.children.length - 1]
}

// Add attributes to last child of fragment
// Example: `[![Nuxt](https://nuxtjs.org/design-kit/colored-logo.svg){.nest}](https://nuxtjs.org)`
if (stackTop.type === 'fragment') {
stackTop = stackTop.children[stackTop.children.length - 1]
}

stackTop.attributes = cleaned
}

Expand Down
19 changes: 18 additions & 1 deletion src/to-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
import { stringifyEntitiesLight } from 'stringify-entities'
import type { Parent } from 'mdast-util-to-markdown/lib/types'
import { handle } from 'mdast-util-to-markdown/lib/handle'
import { Context, SafeOptions } from 'mdast-util-to-markdown'
import { containerFlow, containerPhrasing, checkQuote } from './mdast-util-to-markdown'
import { stringifyFrontMatter } from './frontmatter'

Expand Down Expand Up @@ -34,7 +36,22 @@ export default {
handlers: {
containerComponent,
textComponent,
componentContainerSection
componentContainerSection,
image: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
return handle.image(node as any, _, context, safeOptions) + attributes(node, context)
},
link: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
return handle.link(node as any, _, context, safeOptions) + attributes(node, context)
},
strong: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
return handle.strong(node as any, _, context, safeOptions) + attributes(node, context)
},
inlineCode: (node: Parent, _: any, context: Context) => {
return handle.inlineCode(node as any, _, context) + attributes(node, context)
},
emphasis: (node: Parent, _: any, context: Context, safeOptions: SafeOptions) => {
return handle.emphasis(node as any, _, context, safeOptions) + attributes(node, context)
}
}
}

Expand Down
Loading