Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
calculuschild committed Jul 8, 2020
1 parent cc778ad commit 226bbe7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
50 changes: 19 additions & 31 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,31 +491,25 @@ module.exports = class Tokenizer {

strong(src, maskedSrc, prevChar = '') {
let match = this.rules.inline.strStart.exec(src);

if (match && (!match[1] || (match[1] && (prevChar === '' || this.rules.inline.punctuation.exec(prevChar))))) {
maskedSrc = maskedSrc.slice(-1 * src.length);
let strEnd;

if(match[0] == "**")
strEnd = this.rules.inline.strEndAst;
else
strEnd = this.rules.inline.strEndUnd;
if (match[0] === '**') { strEnd = this.rules.inline.strEndAst; } else { strEnd = this.rules.inline.strEndUnd; }

strEnd.lastIndex = 0;

let cap;
while ((match = strEnd.exec(maskedSrc)) != null) {
cap = this.rules.inline.strong.exec(maskedSrc.slice(0,match.index+3));
if (cap)
break;
}

if (cap) {
return {
type: 'strong',
raw: src.slice(0, cap[0].length),
text: src.slice(2, cap[0].length - 2)
};
cap = this.rules.inline.strong.exec(maskedSrc.slice(0, match.index + 3));
if (cap) {
return {
type: 'strong',
raw: src.slice(0, cap[0].length),
text: src.slice(2, cap[0].length - 2)
};
}
}
}
}
Expand All @@ -527,26 +521,20 @@ module.exports = class Tokenizer {
maskedSrc = maskedSrc.slice(-1 * src.length);
let emEnd;

if(match[0] == "*")
emEnd = this.rules.inline.emEndAst;
else
emEnd = this.rules.inline.emEndUnd;
if (match[0] === '*') { emEnd = this.rules.inline.emEndAst; } else { emEnd = this.rules.inline.emEndUnd; }

emEnd.lastIndex = 0;

let cap;
while ((match = emEnd.exec(maskedSrc)) != null) {
cap = this.rules.inline.em.exec(maskedSrc.slice(0,match.index+2));
if (cap)
break;
}

if (cap) {
return {
type: 'em',
raw: src.slice(0, cap[0].length),
text: src.slice(1, cap[0].length - 1)
};
cap = this.rules.inline.em.exec(maskedSrc.slice(0, match.index + 2));
if (cap) {
return {
type: 'em',
raw: src.slice(0, cap[0].length),
text: src.slice(1, cap[0].length - 1)
};
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const inline = {
emStart: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/, // (1) returns if starts w/ punctuation
emEndAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation\s]|$))/, // last char can't be punct, or final * must also be followed by punct (or endline)
emEndUnd: /[^\s]_(?!_)(?:(?=[punctuation\s])|$)/, // last char can't be a space, and final _ must preceed punct or \s (or endline)
// ⬐ skip overlapping Strong ⬐repeat logic for inner *'s (must be in pairs)| Underscores ⬐ skip overlapping Strong ⬐repeat logic for inner _'s (must be in pairs)⬎
// ⬐ skip overlapping Strong ⬐repeat logic for inner *'s (must be in pairs)| Underscores ⬐ skip overlapping Strong ⬐repeat logic for inner _'s (must be in pairs)⬎
em: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
br: /^( {2,}|\\)\n(?!\s*$)/,
Expand All @@ -200,8 +200,8 @@ inline.em = edit(inline.em)
.getRegex();

inline.emStart = edit(inline.emStart)
.replace(/punctuation/g, inline._punctuation)
.getRegex();
.replace(/punctuation/g, inline._punctuation)
.getRegex();

inline.emEndAst = edit(inline.emEndAst, 'g')
.replace(/punctuation/g, inline._punctuation)
Expand All @@ -223,8 +223,8 @@ inline.strong = edit(inline.strong)
.getRegex();

inline.strStart = edit(inline.strStart)
.replace(/punctuation/g, inline._punctuation)
.getRegex();
.replace(/punctuation/g, inline._punctuation)
.getRegex();

inline.strEndAst = edit(inline.strEndAst, 'g')
.replace(/punctuation/g, inline._punctuation)
Expand Down

0 comments on commit 226bbe7

Please sign in to comment.