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

That will work but link has sub tokens in token.tokens that the parser uses to render the text.

\n

So it will have to be something like

\n
  try {\n\t\t// ![](https://invalid-image.com)\n\t\tconst image = await fetch(token.href)\n\t} except {\n\t\ttoken.text = 'link'\n\t\ttoken.type = 'link'\n    token.tokens = lexer.inlineTokens(token.text); // This will tell the parser what to output\n\t}\n
","upvoteCount":1,"url":"https://github.com/markedjs/marked/discussions/3476#discussioncomment-10845268"}}}

How to convert a token's type #3476

Answered by UziTech
spifory asked this question in Q&A
Oct 4, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

That will work but link has sub tokens in token.tokens that the parser uses to render the text.

So it will have to be something like

  try {
		// ![](https://invalid-image.com)
		const image = await fetch(token.href)
	} except {
		token.text = 'link'
		token.type = 'link'
    token.tokens = lexer.inlineTokens(token.text); // This will tell the parser what to output
	}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@spifory
Comment options

@UziTech
Comment options

@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
None yet
2 participants