insert a tag <img>
or <h1>
at the top of body?
#108
-
i found rehype-meta but it only does meta tags.
is there a plugin that inserts a tag at the top of repo → https://github.com/deadcoder0904/mdx-to-pdf-epub-mobi-using-unified/ |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
oops, found out about https://github.com/jaywcjlove/rehype-rewrite in another tab as i posted this. weird. been searching for hours. would love to know if there is a more simpler solution. |
Beta Was this translation helpful? Give feedback.
-
You can also make your own plugin for this, using existing utilities: import {select} from 'hast-util-select'
let tree = getHastTreeSomehow()
let myElement = getMyHastElementSomehow()
let body = select('body', tree)
body.children.unshift(myElement) |
Beta Was this translation helpful? Give feedback.
-
this did the job. just had to be after .use(rehypeDocument, {
title: meta.title || 'book',
css: 'styles/pdf.css',
}) // document should be after sanitize
.use(rehypeRewrite, {
rewrite: (node) => {
if (node.type == 'element' && node.tagName == 'body') {
node.children = [
{
type: 'element',
tagName: 'img',
properties: {
src: meta.cover || '',
alt: 'cover',
},
},
...node.children,
]
}
},
}) |
Beta Was this translation helpful? Give feedback.
this did the job. just had to be after
rehypeDocument
to make surebody
tag is available.