@pretextbook/remark-pretext 0.0.4 → 0.0.6

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,5 @@
1
1
  import { BlockContent, DefinitionContent, PhrasingContent } from 'mdast';
2
+ import { DivisionType } from '@pretextbook/ptxast';
2
3
  export interface VisitContext {
3
4
  /** Parent node, if any. */
4
5
  parent?: BlockContent | DefinitionContent | PhrasingContent;
@@ -10,6 +11,8 @@ export interface VisitContext {
10
11
  messages?: ConversionMessage[];
11
12
  /** Raw source markdown (optional, used for delimiter detection). */
12
13
  source?: string;
14
+ /** The division type that a depth-1 heading (`#`) maps to. */
15
+ topLevelDivision: DivisionType;
13
16
  }
14
17
  export interface ConversionMessage {
15
18
  type: 'warning' | 'error';
@@ -0,0 +1,8 @@
1
+ import { DivisionType } from '@pretextbook/ptxast';
2
+ export interface FrontmatterResult {
3
+ /** The declared top-level division type, if present and valid. */
4
+ division?: DivisionType;
5
+ /** The markdown source with the frontmatter block removed. */
6
+ body: string;
7
+ }
8
+ export declare function extractFrontmatter(markdown: string): FrontmatterResult;
@@ -1,3 +1,4 @@
1
+ import { RemarkPretextOptions } from './remark-pretext.js';
1
2
  /**
2
3
  * Convert a markdown string (with PreTeXt directive extensions) to a PreTeXt
3
4
  * XML string.
@@ -6,6 +7,7 @@
6
7
  * node serialized as a string — suitable for embedding in a PreTeXt document.
7
8
  *
8
9
  * @param markdown - The markdown source to convert.
10
+ * @param options - Conversion options, e.g. `topLevelDivision`.
9
11
  * @returns A PreTeXt XML string.
10
12
  *
11
13
  * @example
@@ -16,4 +18,4 @@
16
18
  * // → '<section>\n <title>Hello</title>\n <p>This is a paragraph.</p>\n</section>'
17
19
  * ```
18
20
  */
19
- export declare function markdownToPretext(markdown: string): string;
21
+ export declare function markdownToPretext(markdown: string, options?: RemarkPretextOptions): string;
@@ -1,13 +1,19 @@
1
1
  import { Root as MdastRoot } from 'mdast';
2
2
  import { Root } from 'xast';
3
3
  import { ConversionMessage } from './context.js';
4
+ import { DivisionType } from '@pretextbook/ptxast';
4
5
  /** Result type for conversion: tree + diagnostic messages. */
5
6
  export interface ConversionResult {
6
7
  tree: Root;
7
8
  messages: ConversionMessage[];
8
9
  }
10
+ /** Options controlling heading-to-division conversion. */
11
+ export interface MdastToPtxastOptions {
12
+ /** The division type that a depth-1 heading (`#`) maps to. Defaults to `'chapter'`. */
13
+ topLevelDivision?: DivisionType;
14
+ }
9
15
  /** Transform an mdast Root node into an xast Root node (backwards compatible). */
10
- export declare function mdastToPtxast(tree: MdastRoot, source?: string): Root;
16
+ export declare function mdastToPtxast(tree: MdastRoot, source?: string, options?: MdastToPtxastOptions): Root;
11
17
  export { mdastToPtxast as mdastToXast };
12
18
  /** Transform an mdast Root node, returning tree + diagnostic messages. */
13
- export declare function mdastToPtxastWithDiagnostics(tree: MdastRoot, source?: string): ConversionResult;
19
+ export declare function mdastToPtxastWithDiagnostics(tree: MdastRoot, source?: string, options?: MdastToPtxastOptions): ConversionResult;
@@ -1,8 +1,15 @@
1
1
  import { Plugin } from 'unified';
2
2
  import { Root as MdastRoot } from 'mdast';
3
3
  import { Root } from 'xast';
4
- /** Options for the remark-pretext plugin (currently none, reserved for future use). */
4
+ import { DivisionType } from '@pretextbook/ptxast';
5
+ /** Options for the remark-pretext plugin. */
5
6
  export interface RemarkPretextOptions {
7
+ /**
8
+ * The division type that a depth-1 heading (`#`) maps to. Overrides any
9
+ * `division:` field declared in the markdown's frontmatter. Defaults to
10
+ * `'chapter'` (matching historical behavior) when neither is set.
11
+ */
12
+ topLevelDivision?: DivisionType;
6
13
  }
7
14
  declare const remarkPretext: Plugin<[RemarkPretextOptions?], MdastRoot, Root>;
8
15
  export default remarkPretext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/remark-pretext",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "test": "vitest run"
40
40
  },
41
41
  "dependencies": {
42
- "@pretextbook/ptxast": "^0.0.4",
42
+ "@pretextbook/ptxast": "^0.0.5",
43
43
  "@types/mdast": "^4.0.0",
44
44
  "mdast-util-directive": "^3.0.0",
45
45
  "remark-directive": "^4.0.0",