Skip to content
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

refactor: call parent class url tokenizer method #218

Merged
merged 1 commit into from
Dec 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 3 additions & 39 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,48 +171,12 @@ const smartypants = (str, quotes) => {

class Tokenizer extends MarkedTokenizer {
// Support AutoLink option
// https://github.com/markedjs/marked/blob/b6773fca412c339e0cedd56b63f9fa1583cfd372/src/Tokenizer.js#L606-L641
url(src, mangle) {
const { options, rules } = this;
const { mangle: isMangle, autolink } = options;
const { options } = this;
const { autolink } = options;

if (!autolink) return;

const cap = rules.inline.url.exec(src);
if (cap) {
let text, href;
if (cap[2] === '@') {
text = escape(isMangle ? mangle(cap[0]) : cap[0]);
href = 'mailto:' + text;
} else {
// do extended autolink path validation
let prevCapZero;
do {
prevCapZero = cap[0];
cap[0] = rules.inline._backpedal.exec(cap[0])[0];
} while (prevCapZero !== cap[0]);
text = escape(cap[0]);
if (cap[1] === 'www.') {
href = 'http://' + text;
} else {
href = text;
}
}

return {
type: 'link',
raw: cap[0],
text,
href,
tokens: [
{
type: 'text',
raw: text,
text
}
]
};
}
Comment on lines -181 to -215
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems just copy from marked Tokenizer.js url method.

return super.url(src, mangle);
}

// Override smartypants
Expand Down