New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block level extension not rendering correctly #3272
Labels
Comments
It looks like your |
It also looks like you are setting it as a 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>`;
const marked = new Marked();
marked.use({
extensions: [
{
name: "customImage",
level: "inline",
start: (source: string) => {
return source.match(/!\[/)?.index;
},
tokenizer(source, tokens) {
const rule = /^!\[\]\((.+?)\){: width=(\d+?) }/;
const match = rule.exec(source);
if (match) {
const token = {
type: "customImage",
raw: match[0],
src: match[1],
width: match[2],
};
return token;
}
return undefined;
},
renderer(token) {
return `<img src="${token.src}" data-width="${token.width}" />`;
},
},
],
});
const rawText = `aaa
inline ![](imagelink){: width=50 }
ccc`;
const parsedText = marked.parse(rawText);
console.log(parsedText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: