Skip to content

Commit

Permalink
refactor: call parent class url tokenizer method
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Dec 30, 2021
1 parent 76ee3bc commit 42f0ad4
Showing 1 changed file with 3 additions and 39 deletions.
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
}
]
};
}
return super.url(src, mangle);
}

// Override smartypants
Expand Down

0 comments on commit 42f0ad4

Please sign in to comment.