Skip to content

insert a tag <img> or <h1> at the top of body? #108

Discussion options

You must be logged in to vote

this did the job. just had to be after rehypeDocument to make sure body tag is available.

.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,
          ]
        }
      },
    })

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by deadcoder0904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants