Skip to content

Inline SVG as options.content for remark-autolink-headings #732

Answered by wooorm
janosh asked this question in Q&A
Discussion options

You must be logged in to vote

I would recommend rehypejs/rehype-autolink-headings. It’s closer to what you’re
doing and we’ll deprecate the remark version soonish.

You can create hast nodes with hastscript. Specifically, in this case,
it exposes an SVG builder, s.

Something like this pseudo code should do the trick:

import {s} from 'hastscript'

const content = s(
  'svg',
  {
    xmlns: 'http://www.w3.org/2000/svg',
    width: 16,
    height: 16,
    fill: 'black',
    viewBox: '0 0 16 16'
  },
  s('path', {
    d: 'M7.775 3.275a.75.75 0 0 0 1.06 1.06l1.25-1.25a2 2 0 1 1 2.83 2.83l-2.5 2.5a2 2 0 0 1-2.83 0 .75.75 0 0 0-1.06 1.06 3.5 3.5 0 0 0 4.95 0l2.5-2.5a3.5 3.5 0 0 0-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 0 1 0-2…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@wooorm
Comment options

@janosh
Comment options

Answer selected by wooorm
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