@erudit-js/prose 4.1.0 → 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.
Files changed (208) hide show
  1. package/dist/app/appElement.d.ts +7 -6
  2. package/dist/app/appElement.js +1 -1
  3. package/dist/app/composables/anchor.d.ts +7 -7
  4. package/dist/app/composables/appElement.d.ts +4 -4
  5. package/dist/app/composables/appElement.js +3 -3
  6. package/dist/app/composables/context.d.ts +3 -2
  7. package/dist/app/composables/elementIcon.d.ts +2 -2
  8. package/dist/app/composables/elementIcon.js +1 -1
  9. package/dist/app/composables/language.d.ts +2 -2
  10. package/dist/app/composables/language.js +1 -1
  11. package/dist/app/composables/storage.d.ts +4 -4
  12. package/dist/app/composables/storage.js +0 -4
  13. package/dist/app/default/Mix.vue +2 -2
  14. package/dist/app/default/Text.vue +2 -2
  15. package/dist/app/shared/Prose.vue +3 -3
  16. package/dist/app/shared/Render.vue +5 -14
  17. package/dist/app/shared/block/AsideMenu.vue +2 -2
  18. package/dist/app/shared/block/AsideMenuCopyLink.vue +1 -1
  19. package/dist/app/shared/block/Block.vue +4 -4
  20. package/dist/app/shared/inliner/Inliner.vue +2 -2
  21. package/dist/coreElement.d.ts +25 -7
  22. package/dist/coreElement.js +2 -2
  23. package/dist/elements/accent/Accent.vue +4 -4
  24. package/dist/elements/accent/AccentColumnSection.vue +2 -2
  25. package/dist/elements/accent/AccentRowSections.vue +2 -2
  26. package/dist/elements/accent/app.d.ts +3 -3
  27. package/dist/elements/accent/app.js +2 -2
  28. package/dist/elements/accent/core.d.ts +61 -300
  29. package/dist/elements/accent/core.js +83 -68
  30. package/dist/elements/callout/Callout.vue +4 -4
  31. package/dist/elements/callout/app.d.ts +1 -8
  32. package/dist/elements/callout/app.js +2 -2
  33. package/dist/elements/callout/core.d.ts +21 -59
  34. package/dist/elements/callout/core.js +18 -17
  35. package/dist/elements/caption/Caption.vue +3 -3
  36. package/dist/elements/caption/app.d.ts +1 -8
  37. package/dist/elements/caption/app.js +2 -2
  38. package/dist/elements/caption/core.d.ts +21 -99
  39. package/dist/elements/caption/core.js +18 -22
  40. package/dist/elements/details/Details.vue +3 -3
  41. package/dist/elements/details/app.d.ts +1 -8
  42. package/dist/elements/details/app.js +2 -2
  43. package/dist/elements/details/core.d.ts +18 -61
  44. package/dist/elements/details/core.js +16 -11
  45. package/dist/elements/diagram/Diagram.vue +14 -11
  46. package/dist/elements/diagram/app.d.ts +1 -29
  47. package/dist/elements/diagram/app.js +2 -2
  48. package/dist/elements/diagram/core.d.ts +14 -177
  49. package/dist/elements/diagram/core.js +5 -8
  50. package/dist/elements/emphasis/Emphasis.vue +3 -3
  51. package/dist/elements/emphasis/app.d.ts +1 -8
  52. package/dist/elements/emphasis/app.js +2 -2
  53. package/dist/elements/emphasis/core.d.ts +13 -76
  54. package/dist/elements/emphasis/core.js +8 -9
  55. package/dist/elements/flex/Flex.vue +3 -3
  56. package/dist/elements/flex/app.d.ts +1 -8
  57. package/dist/elements/flex/app.js +2 -2
  58. package/dist/elements/flex/core.d.ts +16 -58
  59. package/dist/elements/flex/core.js +6 -7
  60. package/dist/elements/gallery/Gallery.vue +3 -3
  61. package/dist/elements/gallery/app.d.ts +1 -22
  62. package/dist/elements/gallery/app.js +2 -2
  63. package/dist/elements/gallery/core.d.ts +11 -132
  64. package/dist/elements/gallery/core.js +4 -5
  65. package/dist/elements/heading/Heading.vue +3 -3
  66. package/dist/elements/heading/_global.d.ts +2 -2
  67. package/dist/elements/heading/app.d.ts +1 -8
  68. package/dist/elements/heading/app.js +2 -2
  69. package/dist/elements/heading/core.d.ts +13 -97
  70. package/dist/elements/heading/core.js +8 -8
  71. package/dist/elements/horizontalLine/app.d.ts +1 -8
  72. package/dist/elements/horizontalLine/app.js +2 -2
  73. package/dist/elements/horizontalLine/core.d.ts +9 -47
  74. package/dist/elements/horizontalLine/core.js +4 -5
  75. package/dist/elements/image/Image.vue +3 -3
  76. package/dist/elements/image/ImageElement.vue +4 -4
  77. package/dist/elements/image/app.d.ts +1 -15
  78. package/dist/elements/image/app.js +2 -2
  79. package/dist/elements/image/core.d.ts +29 -108
  80. package/dist/elements/image/core.js +12 -19
  81. package/dist/elements/image/storage.d.ts +1 -1
  82. package/dist/elements/image/storage.js +6 -6
  83. package/dist/elements/lineBreak/app.d.ts +1 -8
  84. package/dist/elements/lineBreak/app.js +2 -2
  85. package/dist/elements/lineBreak/core.d.ts +9 -47
  86. package/dist/elements/lineBreak/core.js +4 -5
  87. package/dist/elements/link/BlockLink.vue +4 -6
  88. package/dist/elements/link/Link.vue +4 -4
  89. package/dist/elements/link/core.d.ts +8 -7
  90. package/dist/elements/link/core.js +5 -4
  91. package/dist/elements/link/dependency/app.d.ts +1 -15
  92. package/dist/elements/link/dependency/app.js +3 -3
  93. package/dist/elements/link/dependency/core.d.ts +30 -108
  94. package/dist/elements/link/dependency/core.js +6 -8
  95. package/dist/elements/link/hook.d.ts +12 -0
  96. package/dist/elements/link/hook.js +45 -0
  97. package/dist/elements/link/reference/app.d.ts +1 -15
  98. package/dist/elements/link/reference/app.js +3 -3
  99. package/dist/elements/link/reference/core.d.ts +24 -103
  100. package/dist/elements/link/reference/core.js +6 -8
  101. package/dist/elements/link/storage.js +1 -1
  102. package/dist/elements/list/List.vue +7 -5
  103. package/dist/elements/list/_global.d.ts +3 -3
  104. package/dist/elements/list/app.d.ts +1 -15
  105. package/dist/elements/list/app.js +2 -2
  106. package/dist/elements/list/core.d.ts +33 -155
  107. package/dist/elements/list/core.js +20 -18
  108. package/dist/elements/math/app.d.ts +1 -15
  109. package/dist/elements/math/app.js +3 -3
  110. package/dist/elements/math/block.d.ts +31 -43
  111. package/dist/elements/math/block.js +10 -9
  112. package/dist/elements/math/components/BlockMath.vue +4 -4
  113. package/dist/elements/math/components/InlinerMath.vue +4 -4
  114. package/dist/elements/math/core.d.ts +25 -53
  115. package/dist/elements/math/core.js +3 -11
  116. package/dist/elements/math/inliner.d.ts +24 -36
  117. package/dist/elements/math/inliner.js +10 -12
  118. package/dist/elements/paragraph/Paragraph.vue +3 -3
  119. package/dist/elements/paragraph/app.d.ts +1 -8
  120. package/dist/elements/paragraph/app.js +2 -2
  121. package/dist/elements/paragraph/core.d.ts +12 -53
  122. package/dist/elements/paragraph/core.js +6 -7
  123. package/dist/elements/problem/app.d.ts +1 -29
  124. package/dist/elements/problem/app.js +4 -4
  125. package/dist/elements/problem/components/Problem.vue +3 -3
  126. package/dist/elements/problem/components/ProblemContent.vue +15 -21
  127. package/dist/elements/problem/components/ProblemExpanderSection.vue +2 -2
  128. package/dist/elements/problem/components/Problems.vue +11 -7
  129. package/dist/elements/problem/components/SubProblem.vue +3 -4
  130. package/dist/elements/problem/components/expanders/Check.vue +3 -3
  131. package/dist/elements/problem/components/expanders/Checks.vue +6 -3
  132. package/dist/elements/problem/components/expanders/DefaultPlusSections.vue +3 -7
  133. package/dist/elements/problem/components/expanders/Hint.vue +3 -3
  134. package/dist/elements/problem/composables/problemScript.d.ts +2 -2
  135. package/dist/elements/problem/core.d.ts +63 -299
  136. package/dist/elements/problem/core.js +9 -11
  137. package/dist/elements/problem/hook.d.ts +1 -0
  138. package/dist/elements/problem/hook.js +14 -0
  139. package/dist/elements/problem/problem.d.ts +20 -77
  140. package/dist/elements/problem/problem.js +6 -6
  141. package/dist/elements/problem/problemCheck.d.ts +33 -83
  142. package/dist/elements/problem/problemCheck.js +16 -10
  143. package/dist/elements/problem/problemContent.d.ts +54 -401
  144. package/dist/elements/problem/problemContent.js +47 -56
  145. package/dist/elements/problem/problemScript.d.ts +18 -10
  146. package/dist/elements/problem/problemScript.js +15 -26
  147. package/dist/elements/problem/problems.d.ts +29 -188
  148. package/dist/elements/problem/problems.js +11 -15
  149. package/dist/elements/problem/storage.d.ts +1 -1
  150. package/dist/elements/problem/storage.js +2 -3
  151. package/dist/elements/table/Table.vue +3 -3
  152. package/dist/elements/table/app.d.ts +1 -29
  153. package/dist/elements/table/app.js +2 -2
  154. package/dist/elements/table/core.d.ts +28 -309
  155. package/dist/elements/table/core.js +17 -29
  156. package/dist/elements/video/Video.vue +4 -4
  157. package/dist/elements/video/app.d.ts +1 -15
  158. package/dist/elements/video/app.js +2 -2
  159. package/dist/elements/video/core.d.ts +26 -106
  160. package/dist/elements/video/core.js +11 -16
  161. package/dist/elements/video/storage.d.ts +1 -1
  162. package/dist/elements/video/storage.js +2 -3
  163. package/dist/error.d.ts +3 -0
  164. package/dist/error.js +6 -0
  165. package/dist/include.d.ts +4 -4
  166. package/dist/include.js +6 -12
  167. package/dist/index.d.ts +11 -11
  168. package/dist/index.js +11 -11
  169. package/dist/rawElement.d.ts +9 -6
  170. package/dist/rawElement.js +4 -0
  171. package/dist/rawToProse/countSchemas.d.ts +1 -0
  172. package/dist/rawToProse/countSchemas.js +11 -0
  173. package/dist/rawToProse/hook.d.ts +39 -0
  174. package/dist/rawToProse/hook.js +6 -0
  175. package/dist/rawToProse/index.d.ts +34 -0
  176. package/dist/rawToProse/index.js +92 -0
  177. package/dist/rawToProse/uniqueTitles.d.ts +1 -0
  178. package/dist/rawToProse/uniqueTitles.js +11 -0
  179. package/dist/shared/filePath.js +2 -2
  180. package/dist/shared/paragraphWrap.d.ts +3 -3
  181. package/dist/shared/paragraphWrap.js +7 -12
  182. package/dist/slugify/index.d.ts +3 -1
  183. package/dist/slugify/index.js +5 -6
  184. package/dist/slugify/languages/en.js +1 -1
  185. package/dist/slugify/languages/ru.js +1 -1
  186. package/dist/snippet.d.ts +39 -33
  187. package/dist/snippet.js +139 -73
  188. package/dist/tag.d.ts +22 -19
  189. package/dist/tag.js +19 -15
  190. package/dist/toc.d.ts +12 -18
  191. package/dist/toc.js +120 -42
  192. package/package.json +7 -6
  193. package/dist/app/default/Inliners.vue +0 -11
  194. package/dist/context.d.ts +0 -4
  195. package/dist/context.js +0 -1
  196. package/dist/elements/link/step.d.ts +0 -16
  197. package/dist/elements/link/step.js +0 -36
  198. package/dist/elements/problem/step.d.ts +0 -5
  199. package/dist/elements/problem/step.js +0 -13
  200. package/dist/resolve.d.ts +0 -21
  201. package/dist/resolve.js +0 -102
  202. package/dist/resolveStep.d.ts +0 -9
  203. package/dist/resolveStep.js +0 -3
  204. package/dist/title.d.ts +0 -8
  205. package/dist/title.js +0 -6
  206. package/dist/utils/docs.d.ts +0 -1
  207. package/dist/utils/docs.js +0 -22
  208. 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, videoAbsoluteSrc: string): VideoStorage;
2
+ export declare function createVideoStorage(projectAbsPath: string, projectBaseUrl: string, videoRelSrc: string): VideoStorage;
@@ -1,5 +1,4 @@
1
- import { projectRelFilePath } from "../../shared/filePath.js";
2
- export function createVideoStorage(projectAbsPath, projectBaseUrl, videoAbsoluteSrc) {
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
  }
@@ -0,0 +1,3 @@
1
+ export declare class EruditProseError extends Error {
2
+ constructor(message: string);
3
+ }
package/dist/error.js ADDED
@@ -0,0 +1,6 @@
1
+ export class EruditProseError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "EruditProseError";
5
+ }
6
+ }
package/dist/include.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type AnySchema, type AnyUnique, type RawElement } from '@jsprose/core';
1
+ import { type RawElement, type Unique } from 'tsprose';
2
2
  export declare function Include(props: {
3
- children: AnyUnique | RawElement<AnySchema>;
3
+ children: Unique | RawElement;
4
4
  toc?: true | string;
5
- }): RawElement<AnySchema>;
6
- export declare function isIncludedRawElement(rawElement: RawElement<AnySchema>): boolean;
5
+ }): RawElement;
6
+ export declare function isIncludedRawElement(rawElement: RawElement): boolean;
package/dist/include.js CHANGED
@@ -1,6 +1,6 @@
1
- import { isUnique } from "@jsprose/core";
1
+ import { isUnique } from "tsprose";
2
2
  import { finalizeToc } from "./toc.js";
3
- const includedKey = "__ERUDIT_included";
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.toc = finalizeToc({
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[includedKey] = true;
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[includedKey] === true;
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";
@@ -1,6 +1,9 @@
1
- import type { AnySchema, RawElement, schemaKind } from '@jsprose/core';
2
- import type { ObjRawElementSnippet } from './snippet.js';
3
- import type { ObjRawElementToc } from './toc.js';
4
- import type { ObjRawElementTitle } from './title.js';
5
- export type EruditRawElement<TSchema extends AnySchema, TTagName extends string = string> = RawElement<TSchema, TTagName> & ObjRawElementSnippet & ObjRawElementToc & ObjRawElementTitle;
6
- export declare function asEruditRaw<TSchema extends AnySchema, TRawElement extends RawElement<TSchema>>(rawElement: TRawElement): EruditRawElement<TRawElement[typeof schemaKind], TRawElement['tagName']>;
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>;
@@ -1,3 +1,7 @@
1
+ import { isRawElement } from "tsprose";
1
2
  export function asEruditRaw(rawElement) {
2
3
  return rawElement;
3
4
  }
5
+ export function isEruditRawElement(element, schema) {
6
+ return isRawElement(element, schema);
7
+ }
@@ -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,6 @@
1
+ export function defineRawToProseHook(hook) {
2
+ return hook;
3
+ }
4
+ export function defineRawToProseSchemaHook(hook) {
5
+ return hook;
6
+ }
@@ -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
+ });
@@ -1,11 +1,11 @@
1
- import { ProseError } from "@jsprose/core";
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 ProseError(`File "${fileAbsPath}" is outside of project "${projectAbsPath}"`);
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 { type NormalizedChildren, type RawElement } from '@jsprose/core';
2
- import type { paragraphSchema } from '../elements/paragraph/core.js';
3
- export declare function tryParagraphWrap(children: NormalizedChildren): undefined | [RawElement<typeof paragraphSchema>];
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 { PROSE_REGISTRY } from "@jsprose/core";
2
- export function tryParagraphWrap(children) {
3
- const P = PROSE_REGISTRY.getTag("P");
4
- let hasInliners = children?.some((child) => {
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
  }
@@ -1 +1,3 @@
1
- export declare function slugify(text: string, language: string): Promise<string | undefined>;
1
+ import type { EruditRawToProseTask } from '../rawToProse/index.js';
2
+ export type SlugifyCreator = (context: EruditRawToProseTask) => Promise<(text: string) => string>;
3
+ export declare const createDefaultSlugify: SlugifyCreator;
@@ -1,12 +1,11 @@
1
- export async function slugify(text, language) {
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
- const slug = slugifyModule.default(text);
9
- return slug || undefined;
8
+ return slugifyModule.default;
10
9
  }
11
- return undefined;
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
- * Snippet attribute - only contains title and description
6
- */
7
- export interface SnippetData {
8
- /** General snippet title. Used as fallback value for flags. */
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
- * Show element in "Quick Links" sections at start of the page and also in TOC.
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
- * When targeting this element with '#' anchor, adjust SEO metadata (like title and description).
29
- * Search engines should treat it as a different "page" and therefore show it as a standalone search result.
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 ObjPropSnippet = {
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(processTagArgs: EruditProcessTagArgs): SnippetData | undefined;
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
- snippetData: SnippetData;
60
+ snippet: Snippet;
51
61
  }
52
- export declare const snippetStep: ({ rawElement, proseElement }: {
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;