chore: format

This commit is contained in:
Timothy J. Baek 2024-08-14 16:39:02 +02:00
parent 9f0c9d973c
commit 04e2b6e2bd
2 changed files with 96 additions and 89 deletions

View File

@ -159,7 +159,7 @@
const res = await synthesizeOpenAISpeech(
localStorage.token,
$settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice
? $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice
? ($settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice)
: $config?.audio?.tts?.voice,
sentence
).catch((error) => {

View File

@ -9,7 +9,7 @@ const DELIMITER_LIST = [
{ left: '( ', right: ' )', display: false },
{ left: '\\[', right: '\\]', display: true },
{ left: '[', right: ']', display: true }
]
];
// const DELIMITER_LIST = [
// { left: '$$', right: '$$', display: false },
@ -27,7 +27,7 @@ function escapeRegex(string) {
}
function generateRegexRules(delimiters) {
delimiters.forEach(delimiter => {
delimiters.forEach((delimiter) => {
const { left, right } = delimiter;
// Ensure regex-safe delimiters
const escapedLeft = escapeRegex(left);
@ -35,7 +35,9 @@ function generateRegexRules(delimiters) {
// Inline pattern - Capture group $1, token content, followed by end delimiter and normal punctuation marks.
// Example: $text$
inlinePatterns.push(`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`);
inlinePatterns.push(
`${escapedLeft}((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n${escapedRight}]))${escapedRight}`
);
// Block pattern - Starts and ends with the delimiter on new lines. Example:
// $$\ncontent here\n$$
@ -50,19 +52,19 @@ function generateRegexRules(delimiters) {
const { inlineRule, blockRule } = generateRegexRules(DELIMITER_LIST);
export default function (options = {}) {
return {
extensions: [
inlineKatex(options, createRenderer(options, false)),
blockKatex(options, createRenderer(options, true)),
],
blockKatex(options, createRenderer(options, true))
]
};
}
function createRenderer(options, newlineAfter) {
return (token) => katex.renderToString(token.text, { ...options, displayMode: token.displayMode }) + (newlineAfter ? '\n' : '');
return (token) =>
katex.renderToString(token.text, { ...options, displayMode: token.displayMode }) +
(newlineAfter ? '\n' : '');
}
function inlineKatex(options, renderer) {
@ -95,16 +97,19 @@ function inlineKatex(options, renderer) {
const match = src.match(ruleReg);
if (match) {
const text = match.slice(2).filter((item) => item).find((item) => item.trim());
const text = match
.slice(2)
.filter((item) => item)
.find((item) => item.trim());
return {
type: 'inlineKatex',
raw: match[0],
text: text,
text: text
};
}
},
renderer,
renderer
};
}
@ -116,16 +121,18 @@ function blockKatex(options, renderer) {
const match = src.match(blockRule);
if (match) {
const text = match.slice(2).filter((item) => item).find((item) => item.trim());
const text = match
.slice(2)
.filter((item) => item)
.find((item) => item.trim());
return {
type: 'blockKatex',
raw: match[0],
text: text,
text: text
};
}
},
renderer,
renderer
};
}