fika-editor 3.6.13 → 3.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,10 @@ import { math } from 'micromark-extension-llm-math';
4
4
  import { decodeHTML } from 'entities';
5
5
  import MarkdownIt from 'markdown-it';
6
6
  import texmath from 'markdown-it-texmath';
7
- const parseOptions = { extensions: [math()], mdastExtensions: [mathFromMarkdown()] };
7
+ import { inlineDollarEnd } from './inlineDollar.js';
8
+ const mathSyntax = math();
9
+ const dollar = mathSyntax.text[36];
10
+ const mdastExtensions = [mathFromMarkdown()];
8
11
  // Preserve the existing Fika support for bare TeX environments. This parser is
9
12
  // only used for that uncommon syntax; CommonMark code fences still take priority.
10
13
  const environmentParser = new MarkdownIt({ html: false }).use(texmath, {
@@ -28,7 +31,19 @@ function parserInput(source) {
28
31
  }
29
32
  return out.join('');
30
33
  }
31
- const parseGeneratedMarkdown = (source) => fromMarkdown(parserInput(source), parseOptions);
34
+ function parseGeneratedMarkdown(source) {
35
+ const singleOrDisplay = {
36
+ ...dollar,
37
+ tokenize(effects, ok, nok) {
38
+ const start = this.now().offset;
39
+ if (source[start + 1] !== '$' && inlineDollarEnd(source, start) < 0)
40
+ return nok;
41
+ return dollar.tokenize.call(this, effects, ok, nok);
42
+ },
43
+ };
44
+ const extension = { ...mathSyntax, text: { ...mathSyntax.text, 36: singleOrDisplay } };
45
+ return fromMarkdown(parserInput(source), { extensions: [extension], mdastExtensions });
46
+ }
32
47
  function environmentSpans(source) {
33
48
  if (!source.includes('\\begin{'))
34
49
  return [];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The nearest unescaped dollar on the same line must be a closer. Never
3
+ * search past a price or the start of a second formula for a later closer.
4
+ * Digits can start a formula ($2+2$), but cannot follow its closing delimiter.
5
+ */
6
+ export declare function inlineDollarEnd(source: string, start: number): number;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The nearest unescaped dollar on the same line must be a closer. Never
3
+ * search past a price or the start of a second formula for a later closer.
4
+ * Digits can start a formula ($2+2$), but cannot follow its closing delimiter.
5
+ */
6
+ export function inlineDollarEnd(source, start) {
7
+ const first = source[start + 1];
8
+ if (!first || first === '$' || /\s/.test(first))
9
+ return -1;
10
+ for (let i = start + 1; i < source.length; i++) {
11
+ const char = source[i];
12
+ if (char === '\n' || char === '\r')
13
+ return -1;
14
+ if (char === '\\' && (source[i + 1] === '$' || source[i + 1] === '\\')) {
15
+ i++;
16
+ continue;
17
+ }
18
+ if (char !== '$')
19
+ continue;
20
+ const before = source[i - 1];
21
+ const after = source[i + 1] || '';
22
+ if (/\s/.test(before) || after === '$' || /\d/.test(after))
23
+ return -1;
24
+ if (after === '.' && /\d/.test(source[i + 2] || ''))
25
+ return -1;
26
+ // An opening parenthesis, backtick, etc. before $x makes it a new opener.
27
+ if (/[\p{P}\p{S}]/u.test(before) && /\p{L}/u.test(after))
28
+ return -1;
29
+ return i + 1;
30
+ }
31
+ return -1;
32
+ }
@@ -1,25 +1,25 @@
1
1
  import type { Locales, TranslationFunctions } from './i18n-types';
2
2
  declare const TypesafeI18n: import("react").FunctionComponent<import("typesafe-i18n/react").TypesafeI18nProps<Locales>>, I18nContext: import("react").Context<import("typesafe-i18n/react").I18nContextType<Locales, {
3
- canvas: import("./i18n-types").NamespaceCanvasTranslation;
4
- configs: import("./i18n-types").NamespaceConfigsTranslation;
3
+ common: import("./i18n-types").NamespaceCommonTranslation;
5
4
  editor: import("./i18n-types").NamespaceEditorTranslation;
6
5
  myna: import("./i18n-types").NamespaceMynaTranslation;
7
- common: import("./i18n-types").NamespaceCommonTranslation;
6
+ export: import("./i18n-types").NamespaceExportTranslation;
8
7
  mobile: import("./i18n-types").NamespaceMobileTranslation;
9
- components: import("./i18n-types").NamespaceComponentsTranslation;
10
8
  screen: import("./i18n-types").NamespaceScreenTranslation;
11
- export: import("./i18n-types").NamespaceExportTranslation;
9
+ components: import("./i18n-types").NamespaceComponentsTranslation;
10
+ canvas: import("./i18n-types").NamespaceCanvasTranslation;
11
+ configs: import("./i18n-types").NamespaceConfigsTranslation;
12
12
  }, TranslationFunctions>>;
13
13
  export { TypesafeI18n, I18nContext };
14
14
  export declare function useI18nContext(): import("typesafe-i18n/react").I18nContextType<Locales, {
15
- canvas: import("./i18n-types").NamespaceCanvasTranslation;
16
- configs: import("./i18n-types").NamespaceConfigsTranslation;
15
+ common: import("./i18n-types").NamespaceCommonTranslation;
17
16
  editor: import("./i18n-types").NamespaceEditorTranslation;
18
17
  myna: import("./i18n-types").NamespaceMynaTranslation;
19
- common: import("./i18n-types").NamespaceCommonTranslation;
18
+ export: import("./i18n-types").NamespaceExportTranslation;
20
19
  mobile: import("./i18n-types").NamespaceMobileTranslation;
21
- components: import("./i18n-types").NamespaceComponentsTranslation;
22
20
  screen: import("./i18n-types").NamespaceScreenTranslation;
23
- export: import("./i18n-types").NamespaceExportTranslation;
21
+ components: import("./i18n-types").NamespaceComponentsTranslation;
22
+ canvas: import("./i18n-types").NamespaceCanvasTranslation;
23
+ configs: import("./i18n-types").NamespaceConfigsTranslation;
24
24
  }, TranslationFunctions>;
25
25
  export declare const useI18nReact: typeof useI18nContext;