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

fix(auto-render): strict dollar delimiter #3926

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions contrib/auto-render/splitAtDelimiters.js
Expand Up @@ -63,13 +63,26 @@ const splitAtDelimiters = function(text, delimiters) {
const math = amsRegex.test(rawData)
? rawData
: text.slice(delimiters[i].left.length, index);
data.push({
type: "math",
data: math,
rawData,
display: delimiters[i].display,
});
let previousData = data.slice(-1).pop(),
// Treat current data as plain text if previous data ends with any words or any numbers with optional space after them
currentData = previousData && /(\w|\b[+-]?\d+([,.]\d+)*\s*)$/.test(previousData.data) && rawData[0] === '$' ? {
type: "text",
data: rawData,
} : {
type: "math",
data: math,
rawData,
display: delimiters[i].display,
};
text = text.slice(index + delimiters[i].right.length);
// Treat current data as plain text if next data starts with any words or any numbers with optional space after them
if (currentData.type === "math" && /^(\w|\s*[+-]?\d+([,.]\d+)*\b)/.test(text) && currentData.rawData[0] === '$') {
currentData.type = "text";
currentData.data = currentData.rawData;
delete currentData.display;
delete currentData.rawData;
}
data.push(currentData);
}

if (text !== "") {
Expand All @@ -82,4 +95,4 @@ const splitAtDelimiters = function(text, delimiters) {
return data;
};

export default splitAtDelimiters;
export default splitAtDelimiters;