Is it possible to set height and width attributes while building an Image mdast node? #115
-
| I have this piece of code that is processing a container directive: import type { VFile } from 'vfile'
import type { ContainerDirective } from 'mdast-util-directive'
import { Image, Paragraph } from 'mdast'
const processImage = (
  node: ContainerDirective,
  index: number,
  parent: any,
  file: VFile
) => {
  const imgPath = node?.attributes?.id
  // Require a `imgPath` attribute, crash otherwise.
  if (typeof imgPath !== 'string') {
    file.fail('Expected `imgPath` attribute on image directive', node)
  }
  const img: Image = {
    type: 'image',
    url: imgPath,
    alt: node?.attributes?.alt || undefined,
    title: null
  }
  // Images cannot be directly in things. They are phrasing content.
  const paragraph: Paragraph = {
    type: 'paragraph',
    children: [img]
  }
  // Replace directive with paragraph.
  parent.children.splice(index, 1, paragraph)
}
export default processImagethe directive looks like: is there any way that I can pass those two  | 
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
| Heya @reypm 👋 
 Yes, by using  | 
Beta Was this translation helpful? Give feedback.
Heya @reypm 👋
Yes, by using
data.hPropertieson the newly created MDASTimagenode, you can add any HTML property you would like.Similar to how you used it to add
classNamein your last discussion thread https://github.com/orgs/syntax-tree/discussions/113#discussion-5544677