You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like your rule searches for a pattern anywhere in the source. It should only look for tokens at the beginning. Try adding ^ at the beginning of the regexp
It also looks like you are setting it as a block level token which won't be inside a <p> tag. You can change it to inline to parse it as an inline token.
import{Marked}from"marked";import"./styles.css";document.getElementById("app").innerHTML=`<h1>Hello Vanilla!</h1><div> We use the same configuration as Parcel to bundle this sandbox, you can find more info about Parcel <a href="https://parceljs.org" target="_blank" rel="noopener noreferrer">here</a>.</div>`;constmarked=newMarked();marked.use({extensions: [{name: "customImage",level: "inline",start: (source: string)=>{returnsource.match(/!\[/)?.index;},tokenizer(source,tokens){construle=/^!\[\]\((.+?)\){: width=(\d+?) }/;constmatch=rule.exec(source);if(match){consttoken={type: "customImage",raw: match[0],src: match[1],width: match[2],};returntoken;}returnundefined;},renderer(token){return`<img src="${token.src}" data-width="${token.width}" />`;},},],});constrawText=`aaainline ![](imagelink){: width=50 }ccc`;constparsedText=marked.parse(rawText);console.log(parsedText);
Marked version: 12.0.2
I tried to write an extension that also stores image's width, but despite following the example, I couldn't make it to output what I expected.
To Reproduce
Codesandbox.io
outputs
Expected behavior
Thank you in advance.
The text was updated successfully, but these errors were encountered: