@erudit-js/prose 4.1.1 → 4.2.0-dev.1
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.
- package/dist/app/appElement.d.ts +7 -6
- package/dist/app/appElement.js +1 -1
- package/dist/app/composables/anchor.d.ts +7 -7
- package/dist/app/composables/appElement.d.ts +4 -4
- package/dist/app/composables/appElement.js +3 -3
- package/dist/app/composables/context.d.ts +3 -2
- package/dist/app/composables/elementIcon.d.ts +2 -2
- package/dist/app/composables/elementIcon.js +1 -1
- package/dist/app/composables/language.d.ts +2 -2
- package/dist/app/composables/language.js +1 -1
- package/dist/app/composables/storage.d.ts +4 -4
- package/dist/app/composables/storage.js +0 -4
- package/dist/app/default/Mix.vue +2 -2
- package/dist/app/default/Text.vue +2 -2
- package/dist/app/shared/Prose.vue +3 -3
- package/dist/app/shared/Render.vue +5 -14
- package/dist/app/shared/block/AsideMenu.vue +2 -2
- package/dist/app/shared/block/AsideMenuCopyLink.vue +1 -1
- package/dist/app/shared/block/Block.vue +4 -4
- package/dist/app/shared/inliner/Inliner.vue +2 -2
- package/dist/coreElement.d.ts +25 -7
- package/dist/coreElement.js +2 -2
- package/dist/elements/accent/Accent.vue +4 -4
- package/dist/elements/accent/AccentColumnSection.vue +2 -2
- package/dist/elements/accent/AccentRowSections.vue +2 -2
- package/dist/elements/accent/app.d.ts +3 -3
- package/dist/elements/accent/app.js +2 -2
- package/dist/elements/accent/core.d.ts +61 -300
- package/dist/elements/accent/core.js +83 -68
- package/dist/elements/callout/Callout.vue +4 -4
- package/dist/elements/callout/app.d.ts +1 -8
- package/dist/elements/callout/app.js +2 -2
- package/dist/elements/callout/core.d.ts +21 -59
- package/dist/elements/callout/core.js +18 -17
- package/dist/elements/caption/Caption.vue +3 -3
- package/dist/elements/caption/app.d.ts +1 -8
- package/dist/elements/caption/app.js +2 -2
- package/dist/elements/caption/core.d.ts +21 -99
- package/dist/elements/caption/core.js +18 -22
- package/dist/elements/details/Details.vue +3 -3
- package/dist/elements/details/app.d.ts +1 -8
- package/dist/elements/details/app.js +2 -2
- package/dist/elements/details/core.d.ts +18 -61
- package/dist/elements/details/core.js +16 -11
- package/dist/elements/diagram/Diagram.vue +14 -11
- package/dist/elements/diagram/app.d.ts +1 -29
- package/dist/elements/diagram/app.js +2 -2
- package/dist/elements/diagram/core.d.ts +14 -177
- package/dist/elements/diagram/core.js +5 -8
- package/dist/elements/emphasis/Emphasis.vue +3 -3
- package/dist/elements/emphasis/app.d.ts +1 -8
- package/dist/elements/emphasis/app.js +2 -2
- package/dist/elements/emphasis/core.d.ts +13 -76
- package/dist/elements/emphasis/core.js +8 -9
- package/dist/elements/flex/Flex.vue +3 -3
- package/dist/elements/flex/app.d.ts +1 -8
- package/dist/elements/flex/app.js +2 -2
- package/dist/elements/flex/core.d.ts +16 -58
- package/dist/elements/flex/core.js +6 -7
- package/dist/elements/gallery/Gallery.vue +3 -3
- package/dist/elements/gallery/app.d.ts +1 -22
- package/dist/elements/gallery/app.js +2 -2
- package/dist/elements/gallery/core.d.ts +11 -132
- package/dist/elements/gallery/core.js +4 -5
- package/dist/elements/heading/Heading.vue +3 -3
- package/dist/elements/heading/_global.d.ts +2 -2
- package/dist/elements/heading/app.d.ts +1 -8
- package/dist/elements/heading/app.js +2 -2
- package/dist/elements/heading/core.d.ts +13 -97
- package/dist/elements/heading/core.js +8 -8
- package/dist/elements/horizontalLine/app.d.ts +1 -8
- package/dist/elements/horizontalLine/app.js +2 -2
- package/dist/elements/horizontalLine/core.d.ts +9 -47
- package/dist/elements/horizontalLine/core.js +4 -5
- package/dist/elements/image/Image.vue +3 -3
- package/dist/elements/image/ImageElement.vue +4 -4
- package/dist/elements/image/app.d.ts +1 -15
- package/dist/elements/image/app.js +2 -2
- package/dist/elements/image/core.d.ts +29 -108
- package/dist/elements/image/core.js +12 -19
- package/dist/elements/image/storage.d.ts +1 -1
- package/dist/elements/image/storage.js +6 -6
- package/dist/elements/lineBreak/app.d.ts +1 -8
- package/dist/elements/lineBreak/app.js +2 -2
- package/dist/elements/lineBreak/core.d.ts +9 -47
- package/dist/elements/lineBreak/core.js +4 -5
- package/dist/elements/link/BlockLink.vue +4 -6
- package/dist/elements/link/Link.vue +4 -4
- package/dist/elements/link/core.d.ts +6 -6
- package/dist/elements/link/core.js +4 -3
- package/dist/elements/link/dependency/app.d.ts +1 -15
- package/dist/elements/link/dependency/app.js +3 -3
- package/dist/elements/link/dependency/core.d.ts +27 -105
- package/dist/elements/link/dependency/core.js +6 -8
- package/dist/elements/link/hook.d.ts +12 -0
- package/dist/elements/link/hook.js +45 -0
- package/dist/elements/link/reference/app.d.ts +1 -15
- package/dist/elements/link/reference/app.js +3 -3
- package/dist/elements/link/reference/core.d.ts +24 -103
- package/dist/elements/link/reference/core.js +6 -8
- package/dist/elements/link/storage.js +1 -1
- package/dist/elements/list/List.vue +7 -5
- package/dist/elements/list/_global.d.ts +3 -3
- package/dist/elements/list/app.d.ts +1 -15
- package/dist/elements/list/app.js +2 -2
- package/dist/elements/list/core.d.ts +33 -155
- package/dist/elements/list/core.js +20 -18
- package/dist/elements/math/app.d.ts +1 -15
- package/dist/elements/math/app.js +3 -3
- package/dist/elements/math/block.d.ts +31 -43
- package/dist/elements/math/block.js +10 -9
- package/dist/elements/math/components/BlockMath.vue +4 -4
- package/dist/elements/math/components/InlinerMath.vue +4 -4
- package/dist/elements/math/core.d.ts +25 -53
- package/dist/elements/math/core.js +3 -11
- package/dist/elements/math/inliner.d.ts +24 -36
- package/dist/elements/math/inliner.js +10 -12
- package/dist/elements/paragraph/Paragraph.vue +3 -3
- package/dist/elements/paragraph/app.d.ts +1 -8
- package/dist/elements/paragraph/app.js +2 -2
- package/dist/elements/paragraph/core.d.ts +12 -53
- package/dist/elements/paragraph/core.js +6 -7
- package/dist/elements/problem/app.d.ts +1 -29
- package/dist/elements/problem/app.js +4 -4
- package/dist/elements/problem/components/Problem.vue +3 -3
- package/dist/elements/problem/components/ProblemContent.vue +15 -21
- package/dist/elements/problem/components/ProblemExpanderSection.vue +2 -2
- package/dist/elements/problem/components/Problems.vue +11 -7
- package/dist/elements/problem/components/SubProblem.vue +3 -4
- package/dist/elements/problem/components/expanders/Check.vue +3 -3
- package/dist/elements/problem/components/expanders/Checks.vue +6 -3
- package/dist/elements/problem/components/expanders/DefaultPlusSections.vue +3 -7
- package/dist/elements/problem/components/expanders/Hint.vue +3 -3
- package/dist/elements/problem/composables/problemScript.d.ts +2 -2
- package/dist/elements/problem/core.d.ts +63 -299
- package/dist/elements/problem/core.js +9 -11
- package/dist/elements/problem/hook.d.ts +1 -0
- package/dist/elements/problem/hook.js +14 -0
- package/dist/elements/problem/problem.d.ts +20 -77
- package/dist/elements/problem/problem.js +6 -6
- package/dist/elements/problem/problemCheck.d.ts +33 -83
- package/dist/elements/problem/problemCheck.js +16 -10
- package/dist/elements/problem/problemContent.d.ts +54 -401
- package/dist/elements/problem/problemContent.js +47 -56
- package/dist/elements/problem/problemScript.d.ts +18 -10
- package/dist/elements/problem/problemScript.js +15 -26
- package/dist/elements/problem/problems.d.ts +29 -188
- package/dist/elements/problem/problems.js +11 -15
- package/dist/elements/problem/storage.d.ts +1 -1
- package/dist/elements/problem/storage.js +2 -3
- package/dist/elements/table/Table.vue +3 -3
- package/dist/elements/table/app.d.ts +1 -29
- package/dist/elements/table/app.js +2 -2
- package/dist/elements/table/core.d.ts +28 -309
- package/dist/elements/table/core.js +17 -29
- package/dist/elements/video/Video.vue +4 -4
- package/dist/elements/video/app.d.ts +1 -15
- package/dist/elements/video/app.js +2 -2
- package/dist/elements/video/core.d.ts +26 -106
- package/dist/elements/video/core.js +11 -16
- package/dist/elements/video/storage.d.ts +1 -1
- package/dist/elements/video/storage.js +2 -3
- package/dist/error.d.ts +3 -0
- package/dist/error.js +6 -0
- package/dist/include.d.ts +4 -4
- package/dist/include.js +6 -12
- package/dist/index.d.ts +11 -11
- package/dist/index.js +11 -11
- package/dist/rawElement.d.ts +9 -6
- package/dist/rawElement.js +4 -0
- package/dist/rawToProse/countSchemas.d.ts +1 -0
- package/dist/rawToProse/countSchemas.js +11 -0
- package/dist/rawToProse/hook.d.ts +39 -0
- package/dist/rawToProse/hook.js +6 -0
- package/dist/rawToProse/index.d.ts +34 -0
- package/dist/rawToProse/index.js +92 -0
- package/dist/rawToProse/uniqueTitles.d.ts +1 -0
- package/dist/rawToProse/uniqueTitles.js +11 -0
- package/dist/shared/filePath.js +2 -2
- package/dist/shared/paragraphWrap.d.ts +3 -3
- package/dist/shared/paragraphWrap.js +7 -12
- package/dist/slugify/index.d.ts +3 -1
- package/dist/slugify/index.js +5 -6
- package/dist/slugify/languages/en.js +1 -1
- package/dist/slugify/languages/ru.js +1 -1
- package/dist/snippet.d.ts +39 -33
- package/dist/snippet.js +139 -73
- package/dist/tag.d.ts +22 -19
- package/dist/tag.js +19 -15
- package/dist/toc.d.ts +12 -18
- package/dist/toc.js +120 -42
- package/package.json +7 -6
- package/dist/app/default/Inliners.vue +0 -11
- package/dist/context.d.ts +0 -4
- package/dist/context.js +0 -1
- package/dist/elements/link/step.d.ts +0 -16
- package/dist/elements/link/step.js +0 -36
- package/dist/elements/problem/step.d.ts +0 -5
- package/dist/elements/problem/step.js +0 -13
- package/dist/resolve.d.ts +0 -21
- package/dist/resolve.js +0 -102
- package/dist/resolveStep.d.ts +0 -9
- package/dist/resolveStep.js +0 -3
- package/dist/title.d.ts +0 -8
- package/dist/title.js +0 -6
- package/dist/utils/docs.d.ts +0 -1
- package/dist/utils/docs.js +0 -22
- package/types.d.ts +0 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { VideoStorage } from './core.js';
|
|
2
|
-
export declare function createVideoStorage(projectAbsPath: string, projectBaseUrl: string,
|
|
2
|
+
export declare function createVideoStorage(projectAbsPath: string, projectBaseUrl: string, videoRelSrc: string): VideoStorage;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const resolvedSrc = projectBaseUrl + "file/" + projectRelFilePath(projectAbsPath, videoAbsoluteSrc);
|
|
1
|
+
export function createVideoStorage(projectAbsPath, projectBaseUrl, videoRelSrc) {
|
|
2
|
+
const resolvedSrc = projectBaseUrl + "file/" + videoRelSrc;
|
|
4
3
|
return { resolvedSrc };
|
|
5
4
|
}
|
package/dist/error.d.ts
ADDED
package/dist/error.js
ADDED
package/dist/include.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type RawElement, type Unique } from 'tsprose';
|
|
2
2
|
export declare function Include(props: {
|
|
3
|
-
children:
|
|
3
|
+
children: Unique | RawElement;
|
|
4
4
|
toc?: true | string;
|
|
5
|
-
}): RawElement
|
|
6
|
-
export declare function isIncludedRawElement(rawElement: RawElement
|
|
5
|
+
}): RawElement;
|
|
6
|
+
export declare function isIncludedRawElement(rawElement: RawElement): boolean;
|
package/dist/include.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isUnique } from "
|
|
1
|
+
import { isUnique } from "tsprose";
|
|
2
2
|
import { finalizeToc } from "./toc.js";
|
|
3
|
-
const
|
|
3
|
+
const ERUDIT_INCLUDE_FLAG = "__ERUDIT_included";
|
|
4
4
|
export function Include(props) {
|
|
5
5
|
const rawElement = isUnique(props.children) ? props.children.rawElement : props.children;
|
|
6
6
|
function augmentRawElement(element) {
|
|
@@ -8,15 +8,9 @@ export function Include(props) {
|
|
|
8
8
|
if (isRoot) {
|
|
9
9
|
if (props.toc) {
|
|
10
10
|
if (props.toc === true) {
|
|
11
|
-
element
|
|
12
|
-
props: { toc: props.toc },
|
|
13
|
-
element
|
|
14
|
-
});
|
|
11
|
+
finalizeToc(element, true);
|
|
15
12
|
} else {
|
|
16
|
-
element.toc
|
|
17
|
-
add: true,
|
|
18
|
-
title: props.toc
|
|
19
|
-
};
|
|
13
|
+
finalizeToc(element, props.toc);
|
|
20
14
|
}
|
|
21
15
|
} else {
|
|
22
16
|
delete element.toc;
|
|
@@ -26,7 +20,7 @@ export function Include(props) {
|
|
|
26
20
|
}
|
|
27
21
|
delete element.snippet;
|
|
28
22
|
delete element.uniqueName;
|
|
29
|
-
element[
|
|
23
|
+
element[ERUDIT_INCLUDE_FLAG] = true;
|
|
30
24
|
if (element.children) {
|
|
31
25
|
for (const child of element.children) {
|
|
32
26
|
augmentRawElement(child);
|
|
@@ -37,5 +31,5 @@ export function Include(props) {
|
|
|
37
31
|
return rawElement;
|
|
38
32
|
}
|
|
39
33
|
export function isIncludedRawElement(rawElement) {
|
|
40
|
-
return rawElement[
|
|
34
|
+
return rawElement[ERUDIT_INCLUDE_FLAG] === true;
|
|
41
35
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
export * from './rawToProse/index.js';
|
|
2
|
+
export * from './rawToProse/hook.js';
|
|
3
|
+
export * from './shared/filePath.js';
|
|
4
|
+
export * from './shared/invert.js';
|
|
5
|
+
export * from './shared/paragraphWrap.js';
|
|
6
|
+
export * from './shared/photoswipe.js';
|
|
7
|
+
export * from './slugify/index.js';
|
|
8
|
+
export * from './utils/case.js';
|
|
1
9
|
export * from './coreElement.js';
|
|
10
|
+
export * from './error.js';
|
|
11
|
+
export * from './include.js';
|
|
2
12
|
export * from './rawElement.js';
|
|
3
|
-
export * from './resolve.js';
|
|
4
|
-
export * from './tag.js';
|
|
5
13
|
export * from './snippet.js';
|
|
14
|
+
export * from './tag.js';
|
|
6
15
|
export * from './toc.js';
|
|
7
|
-
export * from './title.js';
|
|
8
|
-
export * from './resolveStep.js';
|
|
9
|
-
export * from './include.js';
|
|
10
|
-
export * from './slugify/index.js';
|
|
11
|
-
export * from './utils/docs.js';
|
|
12
|
-
export * from './utils/case.js';
|
|
13
|
-
export * from './shared/filePath.js';
|
|
14
|
-
export * from './shared/invert.js';
|
|
15
|
-
export * from './shared/photoswipe.js';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
export * from "./rawToProse/index.js";
|
|
2
|
+
export * from "./rawToProse/hook.js";
|
|
3
|
+
export * from "./shared/filePath.js";
|
|
4
|
+
export * from "./shared/invert.js";
|
|
5
|
+
export * from "./shared/paragraphWrap.js";
|
|
6
|
+
export * from "./shared/photoswipe.js";
|
|
7
|
+
export * from "./slugify/index.js";
|
|
8
|
+
export * from "./utils/case.js";
|
|
1
9
|
export * from "./coreElement.js";
|
|
10
|
+
export * from "./error.js";
|
|
11
|
+
export * from "./include.js";
|
|
2
12
|
export * from "./rawElement.js";
|
|
3
|
-
export * from "./resolve.js";
|
|
4
|
-
export * from "./tag.js";
|
|
5
13
|
export * from "./snippet.js";
|
|
14
|
+
export * from "./tag.js";
|
|
6
15
|
export * from "./toc.js";
|
|
7
|
-
export * from "./title.js";
|
|
8
|
-
export * from "./resolveStep.js";
|
|
9
|
-
export * from "./include.js";
|
|
10
|
-
export * from "./slugify/index.js";
|
|
11
|
-
export * from "./utils/docs.js";
|
|
12
|
-
export * from "./utils/case.js";
|
|
13
|
-
export * from "./shared/filePath.js";
|
|
14
|
-
export * from "./shared/invert.js";
|
|
15
|
-
export * from "./shared/photoswipe.js";
|
package/dist/rawElement.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { type RawElement, type Schema, type ToRawElement } from 'tsprose';
|
|
2
|
+
import type { TocRawElementProp } from './toc.js';
|
|
3
|
+
import type { SnippetRawElementProp } from './snippet.js';
|
|
4
|
+
export type ToEruditRawElement<TSchema extends Schema, TagName extends string = string> = ToRawElement<TSchema, TagName> & SnippetRawElementProp & TocRawElementProp & {
|
|
5
|
+
title?: string;
|
|
6
|
+
};
|
|
7
|
+
export type EruditRawElement = ToEruditRawElement<Schema>;
|
|
8
|
+
export declare function asEruditRaw<TSchema extends Schema>(rawElement: RawElement): ToEruditRawElement<TSchema>;
|
|
9
|
+
export declare function isEruditRawElement<TSchema extends Schema>(element: any, schema?: TSchema): element is ToEruditRawElement<TSchema>;
|
package/dist/rawElement.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const countSchemasHook: import("./hook.js").RawToProseHook;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isIncludedRawElement } from "../include.js";
|
|
2
|
+
import { defineRawToProseHook } from "./hook.js";
|
|
3
|
+
export const countSchemasHook = defineRawToProseHook(({ result }) => {
|
|
4
|
+
return { step({ rawElement }) {
|
|
5
|
+
if (isIncludedRawElement(rawElement)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const schemaName = rawElement.schema.name;
|
|
9
|
+
result.schemaCounts[schemaName] = (result.schemaCounts[schemaName] || 0) + 1;
|
|
10
|
+
} };
|
|
11
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ProseElement, Schema } from 'tsprose';
|
|
2
|
+
import type { EruditRawElement, ToEruditRawElement } from '../rawElement.js';
|
|
3
|
+
import type { EruditRawToProseTask, EruditRawToProseResult } from './index.js';
|
|
4
|
+
export type RawToProseHookReturn = void | {
|
|
5
|
+
step?: (elements: {
|
|
6
|
+
rawElement: EruditRawElement;
|
|
7
|
+
proseElement: ProseElement;
|
|
8
|
+
}) => void | Promise<void>;
|
|
9
|
+
finally?: () => void | Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
export type RawToProseHook = (args: {
|
|
12
|
+
task: EruditRawToProseTask;
|
|
13
|
+
result: EruditRawToProseResult;
|
|
14
|
+
}) => RawToProseHookReturn | Promise<RawToProseHookReturn>;
|
|
15
|
+
export declare function defineRawToProseHook(hook: RawToProseHook): RawToProseHook;
|
|
16
|
+
export type RawToProseSchemaHookReturn<TSchema extends Schema = Schema> = void | (({
|
|
17
|
+
anyStep(elements: {
|
|
18
|
+
rawElement: EruditRawElement;
|
|
19
|
+
proseElement: ProseElement;
|
|
20
|
+
}): void | Promise<void>;
|
|
21
|
+
} | {
|
|
22
|
+
anyStep?: undefined;
|
|
23
|
+
}) & ({
|
|
24
|
+
matchStep(elements: {
|
|
25
|
+
rawElement: ToEruditRawElement<TSchema>;
|
|
26
|
+
proseElement: ProseElement;
|
|
27
|
+
}): void | Promise<void>;
|
|
28
|
+
} | {
|
|
29
|
+
matchStep?: undefined;
|
|
30
|
+
}) & {
|
|
31
|
+
finally?: () => void | Promise<void>;
|
|
32
|
+
});
|
|
33
|
+
export type RawToProseSchemaHook<TSchema extends Schema = Schema> = (args: {
|
|
34
|
+
task: EruditRawToProseTask;
|
|
35
|
+
result: EruditRawToProseResult;
|
|
36
|
+
}) => RawToProseSchemaHookReturn<TSchema> | Promise<RawToProseSchemaHookReturn<TSchema>>;
|
|
37
|
+
export type RawToProseHooks = RawToProseHook[];
|
|
38
|
+
export type RawToProseSchemaHooks = Map<Schema, RawToProseSchemaHook>;
|
|
39
|
+
export declare function defineRawToProseSchemaHook<TSchema extends Schema>(hook: RawToProseSchemaHook<TSchema>): RawToProseSchemaHook<TSchema>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type IdMaker, type RawToProseResult, type Schema } from 'tsprose';
|
|
2
|
+
import type { EruditLanguageCode } from '@erudit-js/core/eruditConfig/language';
|
|
3
|
+
import type { EruditRawElement } from '../rawElement.js';
|
|
4
|
+
import { type ResolvedSnippet } from '../snippet.js';
|
|
5
|
+
import type { RawToProseHooks, RawToProseSchemaHooks } from './hook.js';
|
|
6
|
+
import { type ResolvedTocItem } from '../toc.js';
|
|
7
|
+
import { type SlugifyCreator } from '../slugify/index.js';
|
|
8
|
+
import { type ContentLinks } from '../elements/link/hook.js';
|
|
9
|
+
export type EruditRawToProseTask = {
|
|
10
|
+
rawProse: EruditRawElement;
|
|
11
|
+
language?: EruditLanguageCode;
|
|
12
|
+
snippets?: {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
};
|
|
15
|
+
toc?: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
/** Try to add elements with provided schemas. They must have title and not be manually excluded from TOC. */
|
|
18
|
+
addSchemas?: Schema[];
|
|
19
|
+
};
|
|
20
|
+
hooks?: RawToProseHooks;
|
|
21
|
+
schemaHooks?: RawToProseSchemaHooks;
|
|
22
|
+
idMaker?: IdMaker;
|
|
23
|
+
createSlugify?: SlugifyCreator;
|
|
24
|
+
};
|
|
25
|
+
export interface EruditRawToProseResult extends RawToProseResult {
|
|
26
|
+
toc: ResolvedTocItem[];
|
|
27
|
+
snippets: ResolvedSnippet[];
|
|
28
|
+
files: Set<string>;
|
|
29
|
+
problemScripts: Set<string>;
|
|
30
|
+
contentLinks: ContentLinks;
|
|
31
|
+
schemaCounts: Record<string, number>;
|
|
32
|
+
uniqueTitles: Record<string, string>;
|
|
33
|
+
}
|
|
34
|
+
export declare function eruditRawToProse(task: EruditRawToProseTask): Promise<EruditRawToProseResult>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isRawElement, rawToProse } from "tsprose";
|
|
2
|
+
import { snippetHook } from "../snippet.js";
|
|
3
|
+
import { tocHook } from "../toc.js";
|
|
4
|
+
import { createDefaultSlugify } from "../slugify/index.js";
|
|
5
|
+
import { problemScriptHook } from "../elements/problem/hook.js";
|
|
6
|
+
import { linkHook } from "../elements/link/hook.js";
|
|
7
|
+
import { countSchemasHook } from "./countSchemas.js";
|
|
8
|
+
import { uniqueTitlesHook } from "./uniqueTitles.js";
|
|
9
|
+
export async function eruditRawToProse(task) {
|
|
10
|
+
const { rawProse, hooks, schemaHooks } = task;
|
|
11
|
+
const result = {
|
|
12
|
+
prose: undefined,
|
|
13
|
+
uniques: {},
|
|
14
|
+
takenIds: new Map(),
|
|
15
|
+
toc: [],
|
|
16
|
+
snippets: [],
|
|
17
|
+
files: new Set(),
|
|
18
|
+
problemScripts: new Set(),
|
|
19
|
+
contentLinks: new Map(),
|
|
20
|
+
schemaCounts: {},
|
|
21
|
+
uniqueTitles: {}
|
|
22
|
+
};
|
|
23
|
+
const _hooks = [
|
|
24
|
+
snippetHook,
|
|
25
|
+
tocHook,
|
|
26
|
+
problemScriptHook,
|
|
27
|
+
linkHook,
|
|
28
|
+
countSchemasHook,
|
|
29
|
+
uniqueTitlesHook,
|
|
30
|
+
...hooks || []
|
|
31
|
+
];
|
|
32
|
+
const createdHooks = [];
|
|
33
|
+
for (const hook of _hooks) {
|
|
34
|
+
const createdHook = await hook({
|
|
35
|
+
task,
|
|
36
|
+
result
|
|
37
|
+
});
|
|
38
|
+
if (createdHook) {
|
|
39
|
+
createdHooks.push(createdHook);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const createdSchemaHooks = new Map();
|
|
43
|
+
for (const [schema, hook] of schemaHooks || []) {
|
|
44
|
+
const createdHook = await hook({
|
|
45
|
+
task,
|
|
46
|
+
result
|
|
47
|
+
});
|
|
48
|
+
if (createdHook) {
|
|
49
|
+
createdSchemaHooks.set(schema, createdHook);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const step = async (elements) => {
|
|
53
|
+
for (const [schema, schemaHook] of createdSchemaHooks) {
|
|
54
|
+
if (schemaHook.anyStep) {
|
|
55
|
+
await schemaHook.anyStep(elements);
|
|
56
|
+
}
|
|
57
|
+
if (isRawElement(elements.rawElement, schema)) {
|
|
58
|
+
if (schemaHook.matchStep) {
|
|
59
|
+
await schemaHook.matchStep({
|
|
60
|
+
rawElement: elements.rawElement,
|
|
61
|
+
proseElement: elements.proseElement
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const hook of createdHooks) {
|
|
67
|
+
if (hook.step) {
|
|
68
|
+
await hook.step(elements);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const baseRawToProseResult = await rawToProse({
|
|
73
|
+
rawProse,
|
|
74
|
+
step,
|
|
75
|
+
idMaker: task.idMaker,
|
|
76
|
+
slugify: task.createSlugify ? await task.createSlugify(task) : await createDefaultSlugify(task)
|
|
77
|
+
});
|
|
78
|
+
result.prose = baseRawToProseResult.prose;
|
|
79
|
+
result.uniques = baseRawToProseResult.uniques;
|
|
80
|
+
result.takenIds = baseRawToProseResult.takenIds;
|
|
81
|
+
for (const schemaHook of createdSchemaHooks.values()) {
|
|
82
|
+
if (schemaHook.finally) {
|
|
83
|
+
await schemaHook.finally();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (const hook of createdHooks) {
|
|
87
|
+
if (hook.finally) {
|
|
88
|
+
await hook.finally();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const uniqueTitlesHook: import("./hook.js").RawToProseHook;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineRawToProseHook } from "./hook.js";
|
|
2
|
+
export const uniqueTitlesHook = defineRawToProseHook(({ result }) => {
|
|
3
|
+
return { step({ rawElement }) {
|
|
4
|
+
if (rawElement.uniqueName) {
|
|
5
|
+
const title = rawElement.title || rawElement.snippet?.title;
|
|
6
|
+
if (title) {
|
|
7
|
+
result.uniqueTitles[rawElement.uniqueName] = title;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
} };
|
|
11
|
+
});
|
package/dist/shared/filePath.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EruditProseError } from "../error.js";
|
|
2
2
|
/**
|
|
3
3
|
* Checks that the given absolute file path is within the given absolute project path.
|
|
4
4
|
* Returns the file path relative to the project path.
|
|
5
5
|
*/
|
|
6
6
|
export function projectRelFilePath(projectAbsPath, fileAbsPath) {
|
|
7
7
|
if (!fileAbsPath.startsWith(projectAbsPath)) {
|
|
8
|
-
throw new
|
|
8
|
+
throw new EruditProseError(`File "${fileAbsPath}" is outside of project "${projectAbsPath}"`);
|
|
9
9
|
}
|
|
10
10
|
return fileAbsPath.slice(projectAbsPath.length + 1);
|
|
11
11
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
export declare function
|
|
1
|
+
import type { NormalizedChildren, ToRawElement } from 'tsprose';
|
|
2
|
+
import { type ParagraphSchema } from '../elements/paragraph/core.js';
|
|
3
|
+
export declare function paragraphWrap(children: NormalizedChildren): undefined | [ToRawElement<ParagraphSchema>];
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const schema = PROSE_REGISTRY.getSchema(child.schemaName);
|
|
6
|
-
return schema.type === "inliner";
|
|
7
|
-
});
|
|
8
|
-
if (hasInliners) {
|
|
9
|
-
return [P({
|
|
10
|
-
children,
|
|
11
|
-
__JSPROSE_registryProp: PROSE_REGISTRY
|
|
12
|
-
})];
|
|
1
|
+
import { P } from "../elements/paragraph/core.js";
|
|
2
|
+
export function paragraphWrap(children) {
|
|
3
|
+
if (!children) {
|
|
4
|
+
return undefined;
|
|
13
5
|
}
|
|
6
|
+
try {
|
|
7
|
+
return [P({ children })];
|
|
8
|
+
} catch {}
|
|
14
9
|
return undefined;
|
|
15
10
|
}
|
package/dist/slugify/index.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { EruditRawToProseTask } from '../rawToProse/index.js';
|
|
2
|
+
export type SlugifyCreator = (context: EruditRawToProseTask) => Promise<(text: string) => string>;
|
|
3
|
+
export declare const createDefaultSlugify: SlugifyCreator;
|
package/dist/slugify/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
export async
|
|
1
|
+
export const createDefaultSlugify = async (context) => {
|
|
2
2
|
const slugifiers = {
|
|
3
3
|
en: async () => await import("./languages/en.js"),
|
|
4
4
|
ru: async () => await import("./languages/ru.js")
|
|
5
5
|
};
|
|
6
|
-
const slugifyModule = language in slugifiers ? await slugifiers[language]() : undefined;
|
|
6
|
+
const slugifyModule = context.language && context.language in slugifiers ? await slugifiers[context.language]() : undefined;
|
|
7
7
|
if (slugifyModule) {
|
|
8
|
-
|
|
9
|
-
return slug || undefined;
|
|
8
|
+
return slugifyModule.default;
|
|
10
9
|
}
|
|
11
|
-
return
|
|
12
|
-
}
|
|
10
|
+
return (text) => text;
|
|
11
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export default (text) => {
|
|
2
|
-
return text.toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
2
|
+
return text.replace(/(\p{Lu}{2,})(\p{Ll})/gu, "$1-$2").replace(/(\p{Ll})(\p{Lu})/gu, "$1-$2").replace(/(\p{L})(\d)/gu, "$1-$2").replace(/(\d)(\p{L})/gu, "$1-$2").toLowerCase().replace(/[^a-z0-9]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
3
3
|
};
|
|
@@ -34,5 +34,5 @@ export default (text) => {
|
|
|
34
34
|
ю: "yu",
|
|
35
35
|
я: "ya"
|
|
36
36
|
};
|
|
37
|
-
return text.toLowerCase().split("").map((char) => cyrillicToLatin[char] !== undefined ? cyrillicToLatin[char] : /[a-z0-9]/.test(char) ? char : "-").join("").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
37
|
+
return text.replace(/(\p{Lu}{2,})(\p{Ll})/gu, "$1-$2").replace(/(\p{Ll})(\p{Lu})/gu, "$1-$2").replace(/(\p{L})(\d)/gu, "$1-$2").replace(/(\d)(\p{L})/gu, "$1-$2").toLowerCase().split("").map((char) => cyrillicToLatin[char] !== undefined ? cyrillicToLatin[char] : /[a-z0-9]/.test(char) ? char : "-").join("").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
38
38
|
};
|
package/dist/snippet.d.ts
CHANGED
|
@@ -1,56 +1,62 @@
|
|
|
1
|
-
import { type AnySchema, type ProseElement } from '@jsprose/core';
|
|
2
|
-
import type { EruditProcessTagArgs } from './tag.js';
|
|
3
1
|
import type { EruditRawElement } from './rawElement.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export declare const NO_SNIPPET_PREFIX = "__ERDUIT_tagNoSnippet";
|
|
3
|
+
export type NoSnippet = {
|
|
4
|
+
[NO_SNIPPET_PREFIX]: true;
|
|
5
|
+
};
|
|
6
|
+
export interface SnippetTagProp {
|
|
7
|
+
/** Compact summary of the element and where to show it (search results, preamble, SEO). */
|
|
8
|
+
snippet?: SnippetRaw;
|
|
9
|
+
}
|
|
10
|
+
export interface SnippetRawElementProp {
|
|
11
|
+
snippet?: SnippetRaw;
|
|
12
|
+
}
|
|
13
|
+
export interface SnippetRaw {
|
|
9
14
|
title?: string;
|
|
10
|
-
/** General snippet description. Used as fallback value for flags. */
|
|
11
15
|
description?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Show element in search results.
|
|
14
|
-
*/
|
|
16
|
+
/** Show element in search results. */
|
|
15
17
|
search?: boolean | string | string[] | {
|
|
16
18
|
title?: string;
|
|
17
19
|
description?: string;
|
|
18
20
|
synonyms?: string[];
|
|
19
21
|
};
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
quick?: boolean | string | {
|
|
22
|
+
/** Show element in "Key elements" section of content preamble. */
|
|
23
|
+
key?: boolean | string | {
|
|
24
24
|
title?: string;
|
|
25
25
|
description?: string;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
* Search engines
|
|
28
|
+
* Set custom page SEO metadata when targeting this element.
|
|
29
|
+
* Search engines treat it as a different "page" and therefore show it as a standalone search result.
|
|
30
30
|
*/
|
|
31
31
|
seo?: boolean | string | {
|
|
32
32
|
title?: string;
|
|
33
33
|
description?: string;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export type
|
|
37
|
-
|
|
38
|
-
* Compact summary of the element and where to show it (search, quick links, SEO).
|
|
39
|
-
*/
|
|
40
|
-
snippet?: SnippetData;
|
|
41
|
-
};
|
|
42
|
-
export type ObjRawElementSnippet = {
|
|
43
|
-
snippet?: SnippetData;
|
|
36
|
+
export type Snippet = Omit<SnippetRaw, 'title'> & {
|
|
37
|
+
title: string;
|
|
44
38
|
};
|
|
45
|
-
export declare function finalizeSnippet(
|
|
39
|
+
export declare function finalizeSnippet(rawElement: EruditRawElement, snippetTagProp: SnippetTagProp['snippet']): void;
|
|
40
|
+
export declare function normalizeSnippet(snippet: SnippetRaw, ...fallbackTitles: (string | undefined)[]): Snippet;
|
|
41
|
+
export interface SearchSnippet {
|
|
42
|
+
title: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
synonyms?: string[];
|
|
45
|
+
}
|
|
46
|
+
export declare function toSearchSnippet(snippet?: Snippet): SearchSnippet | undefined;
|
|
47
|
+
export interface KeySnippet {
|
|
48
|
+
title: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function toKeySnippet(snippet?: Snippet): KeySnippet | undefined;
|
|
52
|
+
export interface SeoSnippet {
|
|
53
|
+
title: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare function toSeoSnippet(snippet?: Snippet): SeoSnippet | undefined;
|
|
46
57
|
export interface ResolvedSnippet {
|
|
47
58
|
schemaName: string;
|
|
48
|
-
isUnique: boolean;
|
|
49
59
|
elementId: string;
|
|
50
|
-
|
|
60
|
+
snippet: Snippet;
|
|
51
61
|
}
|
|
52
|
-
export declare const
|
|
53
|
-
context: import("./context.js").EruditProseContext;
|
|
54
|
-
rawElement: EruditRawElement<AnySchema>;
|
|
55
|
-
proseElement: ProseElement<AnySchema>;
|
|
56
|
-
}) => ResolvedSnippet | undefined;
|
|
62
|
+
export declare const snippetHook: import("./rawToProse/hook.js").RawToProseHook;
|