Skip to content

Commit

Permalink
Merge pull request #457 from StaloneLab/fix-v11
Browse files Browse the repository at this point in the history
Two fixes on V11
  • Loading branch information
LikaKavkasidze committed Mar 30, 2022
2 parents 15394ca + 198d4d9 commit 47c66c2
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,14 @@ exports[`math 1`] = `
hehe
We also want escaping like so: $$ or like so:
$\\\\frac{1}{2}$
"
`;
Expand Down
8 changes: 8 additions & 0 deletions packages/rebber-plugins/__tests__/rebber.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const emoticonsConfig = {
},
}

const mathEscape = require('../src/preprocessors/mathEscape')

const integrationConfig = {
preprocessors: {
tableCell: require('../src/preprocessors/codeVisitor'),
Expand All @@ -36,6 +38,8 @@ const integrationConfig = {
'secretCustomBlock',
]),
heading: require('../src/preprocessors/headingVisitor'),
inlineMath: mathEscape,
math: mathEscape,
},
overrides: {
abbr: require('../src/type/abbr'),
Expand Down Expand Up @@ -439,6 +443,10 @@ test('math', () => {
$$
hehe
We also want escaping like so: $\alphb$ or like so:
$$\ve\frac{1}{2}$$
`)
expect(contents).toMatchSnapshot()
})
Expand Down
9 changes: 7 additions & 2 deletions packages/rebber-plugins/dist/preprocessors/mathEscape.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ module.exports = function () {
var commandStart = node.value.indexOf('\\');

while (commandStart !== -1) {
var commandEnd = node.value.substr(commandStart).search(/[{[\s]/);
var commandName = node.value.substr(commandStart, commandEnd); // Check for unknown commands
var commandEnd = node.value.substr(commandStart + 1).search(/[{[\s\\]/); // End not found is end of line

if (commandEnd === -1) {
commandEnd = node.value.length - 1;
}

var commandName = node.value.substr(commandStart, commandEnd + 1); // Check for unknown commands

if (!katexConstants.includes(commandName)) {
node.value = node.value.replace(commandName, ' ');
Expand Down
10 changes: 8 additions & 2 deletions packages/rebber-plugins/src/preprocessors/mathEscape.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ module.exports = () => node => {
let commandStart = node.value.indexOf('\\')

while (commandStart !== -1) {
const commandEnd = node.value.substr(commandStart).search(/[{[\s]/)
const commandName = node.value.substr(commandStart, commandEnd)
let commandEnd = node.value.substr(commandStart + 1).search(/[{[\s\\]/)

// End not found is end of line
if (commandEnd === -1) {
commandEnd = node.value.length - 1
}

const commandName = node.value.substr(commandStart, commandEnd + 1)

// Check for unknown commands
if (!katexConstants.includes(commandName)) {
Expand Down
93 changes: 89 additions & 4 deletions packages/remark-ping/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,8 @@ Object {
exports[`fixture suite 3 compiles to HTML: h3 1`] = `
"<p><a href=\\"/membres/voir/Moté/\\" rel=\\"nofollow\\" class=\\"ping ping-link\\">@<span class=\\"ping-username\\">Moté</span></a> @Phigger</p>
<p><a href=\\"/membres/voir/Phigger Moté/\\" rel=\\"nofollow\\" class=\\"ping ping-link\\">@<span class=\\"ping-username\\">Phigger Moté</span></a></p>
<p>@Digitals@m <a href=\\"/membres/voir/Digitals@m/\\" rel=\\"nofollow\\" class=\\"ping ping-link\\">@<span class=\\"ping-username\\">Digitals@m</span></a></p>"
<p>@Digitals@m <a href=\\"/membres/voir/Digitals@m/\\" rel=\\"nofollow\\" class=\\"ping ping-link\\">@<span class=\\"ping-username\\">Digitals@m</span></a></p>
<p><a href=\\"/membres/voir/empty/\\" rel=\\"nofollow\\" class=\\"ping ping-link\\">@<span class=\\"ping-username\\">empty</span></a> @</p>"
`;
exports[`fixture suite 3 compiles to Markdown: m3 1`] = `
Expand All @@ -1286,6 +1287,8 @@ exports[`fixture suite 3 compiles to Markdown: m3 1`] = `
@**Phigger Moté**
@Digitals@m @**Digitals@m**
@empty @
"
`;
Expand Down Expand Up @@ -1521,12 +1524,94 @@ Object {
},
"type": "paragraph",
},
Object {
"children": Array [
Object {
"children": Array [
Object {
"type": "text",
"value": "@",
},
Object {
"children": Array [
Object {
"type": "text",
"value": "empty",
},
],
"data": Object {
"hName": "span",
"hProperties": Object {
"class": "ping-username",
},
},
"type": "emphasis",
},
],
"data": Object {
"hName": "a",
"hProperties": Object {
"class": "ping ping-link",
"href": "/membres/voir/empty/",
"rel": "nofollow",
},
},
"position": Position {
"end": Object {
"column": 7,
"line": 7,
"offset": 70,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 7,
"offset": 64,
},
},
"type": "ping",
"url": "/membres/voir/empty/",
"username": "empty",
},
Object {
"position": Position {
"end": Object {
"column": 9,
"line": 7,
"offset": 72,
},
"indent": Array [],
"start": Object {
"column": 7,
"line": 7,
"offset": 70,
},
},
"type": "text",
"value": " @",
},
],
"position": Position {
"end": Object {
"column": 9,
"line": 7,
"offset": 72,
},
"indent": Array [],
"start": Object {
"column": 1,
"line": 7,
"offset": 64,
},
},
"type": "paragraph",
},
],
"position": Object {
"end": Object {
"column": 28,
"line": 5,
"offset": 62,
"column": 9,
"line": 7,
"offset": 72,
},
"start": Object {
"column": 1,
Expand Down
5 changes: 4 additions & 1 deletion packages/remark-ping/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const mockUsernames = [
'Moté',
'Phigger Moté',
'Digitals@m',
'empty',
]

function pingUsername (username) {
Expand Down Expand Up @@ -82,14 +83,16 @@ const fixtures = [
@**Phigger Moté**
@Digitals@m @**Digitals@m**
@empty @
`,
]

const pings = [
['I AM CLEM', 'baz baz'],
['I AM CLEM', 'I AM CLEM', 'I AM CLEM'],
['foo', 'bar'],
['Moté', 'Phigger Moté', 'Digitals@m'],
['Moté', 'Phigger Moté', 'Digitals@m', 'empty'],
]

fixtures.forEach((fixture, i) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-ping/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = function plugin(_ref) {
username = username.slice(0, -fencedEndSequence.length);
}

if (pingUsername(username) === true) {
if (pingUsername(username) === true && username.trim() !== '') {
var url = userURL(username);
return eat(eaten)({
type: 'ping',
Expand Down
2 changes: 1 addition & 1 deletion packages/remark-ping/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = function plugin ({
username = username.slice(0, -fencedEndSequence.length)
}

if (pingUsername(username) === true) {
if (pingUsername(username) === true && username.trim() !== '') {
const url = userURL(username)

return eat(eaten)({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ exports[`math 1`] = `
This should be escaped: $\\\\pink{\\\\text{I love {ls / > outputrce} {outputrce}}}$.
This should be escaped: $\\\\pink{\\\\text{I love {ls / > outputrce} {outputrce}}}$.
Expand Down

0 comments on commit 47c66c2

Please sign in to comment.