Skip to content
\n

Into the following:

\n
testing **image** <img href=\"...\" alt=\"test\" />
\n

Where it only converts the image portion of the string into an HTML tag. (As I would like to replace what is in href alone)

\n

As opposed to it currently doing:

\n
<p>testing <strong>image</strong> <img href=\"...\" alt=\"test\"/></p>
\n

Is there a way to do this, or will I have to let it convert everything in the string to HTML tags? Thank you

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Do you want to change the href in the middle of marked outputting html? In that case I would use use walkTokens to look for link tokens and update the href accordingly.

\n

If you actually only want link tokens to generate html, you can update all other renderers to just output the raw text instead of html.

\n
const renderer = {\n  heading(token) {\n    return token.raw;\n  },\n  ...\n}
","upvoteCount":2,"url":"https://github.com/markedjs/marked/discussions/3467#discussioncomment-10767337"}}}
Discussion options

You must be logged in to vote

Do you want to change the href in the middle of marked outputting html? In that case I would use use walkTokens to look for link tokens and update the href accordingly.

If you actually only want link tokens to generate html, you can update all other renderers to just output the raw text instead of html.

const renderer = {
  heading(token) {
    return token.raw;
  },
  ...
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@spifory
Comment options

Answer selected by spifory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants