@erudit-js/prose 4.2.0-dev.1 → 4.2.0

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.
@@ -1,4 +1,4 @@
1
- import { defineSchema, ensureTagBlockChildren, ensureTagChildren, isRawBlock, isRawElement } from "tsprose";
1
+ import { defineSchema, ensureTagBlockChildren, ensureTagChildren, isRawElement } from "tsprose";
2
2
  import { defineEruditTag } from "../../tag.js";
3
3
  import { uppercaseFirst } from "../../utils/case.js";
4
4
  import { paragraphWrap } from "../../shared/paragraphWrap.js";
@@ -76,7 +76,7 @@ function defineProblemSectionContainer(name) {
76
76
  tagName,
77
77
  schema
78
78
  })(({ element, children }) => {
79
- const head = [];
79
+ const headRaw = [];
80
80
  const sections = [];
81
81
  let seenSection = false;
82
82
  for (const child of children) {
@@ -84,15 +84,13 @@ function defineProblemSectionContainer(name) {
84
84
  seenSection = true;
85
85
  sections.push(child);
86
86
  } else {
87
- if (!isRawBlock(child)) {
88
- throw new EruditProseError(`${tagName} cannot have inline children (found "${child.schema.name}").`);
89
- }
90
87
  if (seenSection) {
91
88
  throw new EruditProseError(`${tagName}: non-section children must come before <ProblemSection>.`);
92
89
  }
93
- head.push(child);
90
+ headRaw.push(child);
94
91
  }
95
92
  }
93
+ const head = headRaw.length > 0 ? toBlockChildren(tagName, headRaw) : [];
96
94
  element.children = [...head, ...sections];
97
95
  });
98
96
  const coreElement = defineProseCoreElement({
@@ -1,11 +1,38 @@
1
1
  import { EruditProseError } from "../error.js";
2
+ function normalizeForCompare(p) {
3
+ return p.replace(/\\/g, "/").replace(/^([A-Za-z]):/, (_, d) => d.toLowerCase() + ":").replace(/\/+$/g, "");
4
+ }
5
+ function isAbsolutePath(p) {
6
+ // After normalization separators are '/', so check for:
7
+ // - Windows drive-root: C:/...
8
+ // - POSIX root: /...
9
+ // - UNC root: //server/share/...
10
+ return /^[A-Za-z]:\//.test(p) || p.startsWith("/") || p.startsWith("//");
11
+ }
12
+ function hasParentTraversal(relPath) {
13
+ return relPath.split("/").some((segment) => segment === "..");
14
+ }
2
15
  /**
3
16
  * Checks that the given absolute file path is within the given absolute project path.
4
17
  * Returns the file path relative to the project path.
5
18
  */
6
19
  export function projectRelFilePath(projectAbsPath, fileAbsPath) {
7
- if (!fileAbsPath.startsWith(projectAbsPath)) {
20
+ const project = normalizeForCompare(projectAbsPath);
21
+ const file = normalizeForCompare(fileAbsPath);
22
+ if (isAbsolutePath(file)) {
23
+ const projectPrefix = project + "/";
24
+ if (!file.startsWith(projectPrefix)) {
25
+ throw new EruditProseError(`File "${fileAbsPath}" is outside of project "${projectAbsPath}"`);
26
+ }
27
+ const rel = file.slice(projectPrefix.length);
28
+ if (!rel || hasParentTraversal(rel)) {
29
+ throw new EruditProseError(`File "${fileAbsPath}" is outside of project "${projectAbsPath}"`);
30
+ }
31
+ return rel;
32
+ }
33
+ const rel = file.replace(/^\.\/+/, "").replace(/^\/+/, "");
34
+ if (!rel || hasParentTraversal(rel)) {
8
35
  throw new EruditProseError(`File "${fileAbsPath}" is outside of project "${projectAbsPath}"`);
9
36
  }
10
- return fileAbsPath.slice(projectAbsPath.length + 1);
37
+ return rel;
11
38
  }
package/dist/toc.js CHANGED
@@ -19,8 +19,8 @@ export function finalizeToc(rawElement, tocTagProp) {
19
19
  return;
20
20
  }
21
21
  if (rawElement.toc === true) {
22
- // Implicitly add to TOC using general title
23
- const tocString = rawElement.title?.trim();
22
+ // Implicitly add to TOC using general title, fall back to finalized snippet title
23
+ const tocString = rawElement.title?.trim() || rawElement.snippet?.title?.trim();
24
24
  if (!tocString) {
25
25
  throw new EruditProseError("Addition to TOC was requested via internal toc: true flag, but unable to retrieve title!");
26
26
  }
@@ -32,8 +32,8 @@ export function finalizeToc(rawElement, tocTagProp) {
32
32
  return;
33
33
  }
34
34
  if (tocTagProp === true) {
35
- // Explicitly add to TOC using general internal toc string or general title
36
- const tocString = rawElement.toc?.trim() || rawElement.title?.trim();
35
+ // Explicitly add to TOC using general internal toc string, general title, or finalized snippet title
36
+ const tocString = rawElement.toc?.trim() || rawElement.title?.trim() || rawElement.snippet?.title?.trim();
37
37
  if (!tocString) {
38
38
  throw new EruditProseError("Addition to TOC was manually requested via true tag toc prop, but unable to retrieve title!");
39
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@erudit-js/prose",
4
- "version": "4.2.0-dev.1",
4
+ "version": "4.2.0",
5
5
  "description": "📝 JSX prose subsystem for Erudit sites",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "files": [
24
24
  "dist",
25
- "types.d.ts"
25
+ "raw.d.ts"
26
26
  ],
27
27
  "license": "MIT",
28
28
  "scripts": {
@@ -32,7 +32,7 @@
32
32
  "prepack": "bun run build"
33
33
  },
34
34
  "dependencies": {
35
- "@erudit-js/core": "4.2.0-dev.1",
35
+ "@erudit-js/core": "4.2.0",
36
36
  "@floating-ui/vue": "^1.1.10",
37
37
  "tsprose": "^1.0.0",
38
38
  "image-size": "^2.0.2",
package/raw.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module '*?raw' {
2
+ const content: string;
3
+ export default content;
4
+ }