Skip to content

Commit

Permalink
fix(*): fix usage of lookbehind support
Browse files Browse the repository at this point in the history
  • Loading branch information
lyngai authored and humyfred committed Jan 5, 2022
1 parent 525a5ab commit d9dc315
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/core/hooks/BackgroundColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class BackgroundColor extends SyntaxBase {
// super();
// }

toHtml(whole, m1, m2) {
return `<span style="background-color:${m1}">${m2}</span>`;
toHtml(whole, leadingChar, m1, m2) {
return `${leadingChar}<span style="background-color:${m1}">${m2}</span>`;
}

makeHtml(str) {
Expand All @@ -36,8 +36,8 @@ export default class BackgroundColor extends SyntaxBase {

rule() {
const ret = {
begin: isLookbehindSupported() ? '(?<!\\\\)\\!\\!\\!' : '(?:^|[^\\\\])\\!\\!\\!',
end: '\\!\\!\\!',
begin: isLookbehindSupported() ? '((?<!\\\\))!!!' : '(^|[^\\\\])!!!',
end: '!!!',
content: '(#[0-9a-zA-Z]{3,6}|[a-z]{3,10})[\\s]([\\w\\W]+?)',
};
ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
Expand Down
8 changes: 4 additions & 4 deletions src/core/hooks/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default class Color extends SyntaxBase {
// super();
// }

toHtml(whole, m1, m2) {
return `<span style="color:${m1}">${m2}</span>`;
toHtml(whole, leadingChar, m1, m2) {
return `${leadingChar}<span style="color:${m1}">${m2}</span>`;
}

makeHtml(str) {
Expand All @@ -36,8 +36,8 @@ export default class Color extends SyntaxBase {

rule() {
const ret = {
begin: isLookbehindSupported() ? '(?<!\\\\)\\!\\!' : '(?:^|[^\\\\])\\!\\!',
end: '\\!\\!',
begin: isLookbehindSupported() ? '((?<!\\\\))!!' : '(^|[^\\\\])!!',
end: '!!',
content: '(#[0-9a-zA-Z]{3,6}|[a-z]{3,20})[\\s]([\\w\\W]+?)',
};
ret.reg = new RegExp(ret.begin + ret.content + ret.end, 'g');
Expand Down
6 changes: 3 additions & 3 deletions src/core/hooks/Sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default class Sub extends SyntaxBase {
// super();
// }

toHtml(whole, m1) {
return `<sub>${m1}</sub>`;
toHtml(whole, leadingChar, m1) {
return `${leadingChar}<sub>${m1}</sub>`;
}

makeHtml(str) {
Expand All @@ -37,7 +37,7 @@ export default class Sub extends SyntaxBase {

rule() {
const ret = {
begin: isLookbehindSupported() ? '(?<!\\\\)\\^\\^' : '(^|[^\\\\])\\^\\^',
begin: isLookbehindSupported() ? '((?<!\\\\))\\^\\^' : '(^|[^\\\\])\\^\\^',
end: '\\^\\^',
content: '([\\w\\W]+?)',
};
Expand Down
6 changes: 3 additions & 3 deletions src/core/hooks/Sup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default class Sup extends SyntaxBase {
// super();
// }

toHtml(whole, m1) {
return `<sup>${m1}</sup>`;
toHtml(whole, leadingChar, m1) {
return `${leadingChar}<sup>${m1}</sup>`;
}

makeHtml(str) {
Expand All @@ -37,7 +37,7 @@ export default class Sup extends SyntaxBase {

rule() {
const ret = {
begin: isLookbehindSupported() ? '(?<!\\\\)\\^' : '(?:^|[^\\\\])\\^',
begin: isLookbehindSupported() ? '((?<!\\\\))\\^' : '(^|[^\\\\])\\^',
end: '\\^',
content: '([\\w\\W]+?)',
};
Expand Down

0 comments on commit d9dc315

Please sign in to comment.