-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Unable to parse link #3570
Comments
In the Lines 110 to 112 in 476b85e
|
return
I customized the rules, but there was a problem after parsing. How can I get my original raw |
What do you mean by your "original raw"? The |
This is my custom format. I want to parse this data. How should I handle it? What configuration do I need to make to adapt it to my method? Can I achieve this by setting the token parsing method? |
You can create a custom extension for that |
Has error
|
import { Marked } from 'marked';
// image-custom.js
const imageExtension = {
name: 'pageforgeImage', // 保持您的自定义类型
level: 'inline',
start(src) {
return src.match(/^!\[/)?.index;
},
tokenizer(src, tokens) {
const rule = /^!\[(.*?)\]\((.*?)(?:\s+"(.*?)")?\s*(?:=(\d+)x(\d+))?\)/;
const match = rule.exec(src);
if (match) {
return {
type: 'pageforgeImage', // 保持与 name 一致
raw: match[0],
text: match[1],
alt: match[1],
href: match[2],
title: match[3] || null,
width: match[4] || null,
height: match[5] || null,
tokens: [], // 这是 marked v15 必需的
};
}
return false;
},
renderer(token) {
let html = `<img src="${token.href}" alt="${token.alt}"`;
if (token.title) {
html += ` title="${token.title}"`;
}
if (token.width && token.height) {
html += ` width="${token.width}" height="${token.height}"`;
}
html += '>';
return html;
},
};
const marked = new Marked({
extensions: [imageExtension],
});
console.log(marked.parse(`
![PageForge](https://raw.githubusercontent.com/devlive-community/pageforge/d751a0bdc90e4cdd8b124a6c8b2adb499c47025f/assets/logo.svg "PageForge" =600x600)
`)); |
This way it works, thanks |
Marked version:
15.0.4
Describe the bug
To Reproduce
Steps to reproduce the behavior:
MyCode
Expected behavior
The problem is that type: 'paragraph', but the token is type: 'link', and it is impossible to directly get type: 'link'?
The text was updated successfully, but these errors were encountered: