@pretextbook/remark-pretext 0.1.0 → 0.3.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.
- package/README.md +44 -1
- package/dist/index.cjs +15 -6
- package/dist/index.js +1948 -613
- package/dist/lib/context.d.ts +2 -0
- package/dist/lib/heading-attributes.d.ts +8 -0
- package/dist/lib/math-parser.d.ts +8 -2
- package/dist/lib/mdast-to-ptxast.d.ts +6 -3
- package/dist/lib/parse-markdown.d.ts +16 -0
- package/dist/lib/raw-pretext.d.ts +28 -0
- package/dist/lib/remark-pretext.d.ts +4 -4
- package/package.json +2 -1
package/dist/lib/context.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface VisitContext {
|
|
|
11
11
|
messages?: ConversionMessage[];
|
|
12
12
|
/** Raw source markdown (optional, used for delimiter detection). */
|
|
13
13
|
source?: string;
|
|
14
|
+
/** Turns a slice of `source` back into what the author wrote. */
|
|
15
|
+
restoreSource: (text: string) => string;
|
|
14
16
|
/** The division type that a depth-1 heading (`#`) maps to. */
|
|
15
17
|
topLevelDivision: TopLevelDivisionType;
|
|
16
18
|
/** When set, the whole document is wrapped in this root element
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Root } from 'mdast';
|
|
2
|
+
/** What a heading keeps in `data`, once its attributes are read. */
|
|
3
|
+
export interface HeadingAttributes {
|
|
4
|
+
id?: string;
|
|
5
|
+
attributes?: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
/** Move any trailing attributes out of each heading's text and into `data`. */
|
|
8
|
+
export declare function applyHeadingAttributes(tree: Root, source?: string): void;
|
|
@@ -10,9 +10,13 @@ declare module "mdast" {
|
|
|
10
10
|
math: Math;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
/** A math node standing in for a token, plus the source it replaced. */
|
|
14
|
+
export interface MathToken extends Math {
|
|
15
|
+
source: string;
|
|
16
|
+
}
|
|
13
17
|
export interface MathTokenizationResult {
|
|
14
18
|
markdown: string;
|
|
15
|
-
tokens: Map<string,
|
|
19
|
+
tokens: Map<string, MathToken>;
|
|
16
20
|
}
|
|
17
21
|
export declare function tokenizeMathInMarkdown(markdown: string): MathTokenizationResult;
|
|
18
22
|
/**
|
|
@@ -26,6 +30,8 @@ export declare function splitTextWithMath(text: string): (Text | Math)[];
|
|
|
26
30
|
* Remark plugin that detects and parses math delimiters in text nodes.
|
|
27
31
|
*/
|
|
28
32
|
export declare function applyMathDelimiters(tree: Root): void;
|
|
29
|
-
|
|
33
|
+
/** Put back the source of any tokens in `text`. */
|
|
34
|
+
export declare function restoreMathTokens(text: string, tokens: Map<string, MathToken>): string;
|
|
35
|
+
export declare function applyMathTokens(tree: Root, tokens: Map<string, MathToken>): void;
|
|
30
36
|
declare const remarkMath: Plugin<[], Root>;
|
|
31
37
|
export default remarkMath;
|
|
@@ -19,10 +19,13 @@ export interface MdastToPtxastOptions {
|
|
|
19
19
|
* root-level division built from the document, e.g. from frontmatter. */
|
|
20
20
|
topLevelAttributes?: Record<string, string>;
|
|
21
21
|
/** Title of the document's top-level division (or document root), e.g.
|
|
22
|
-
* from frontmatter `title
|
|
23
|
-
* heading (`#`) no longer supplies that title —
|
|
24
|
-
* subdivision instead. */
|
|
22
|
+
* from frontmatter `title`, written as inline markdown. When set for a
|
|
23
|
+
* non-root document, a depth-1 heading (`#`) no longer supplies that title —
|
|
24
|
+
* it starts the first subdivision instead. */
|
|
25
25
|
topLevelTitle?: string;
|
|
26
|
+
/** Turns a slice of `source` back into what the author wrote, if `source`
|
|
27
|
+
* isn't already that (math is tokenized before parsing). */
|
|
28
|
+
restoreSource?: (text: string) => string;
|
|
26
29
|
}
|
|
27
30
|
/** Transform an mdast Root node into an xast Root node (backwards compatible). */
|
|
28
31
|
export declare function mdastToPtxast(tree: MdastRoot, source?: string, options?: MdastToPtxastOptions): Root;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PhrasingContent, Root } from 'mdast';
|
|
2
|
+
export interface ParsedMarkdown<T> {
|
|
3
|
+
tree: T;
|
|
4
|
+
/** The text that was parsed, which node positions are offsets into. */
|
|
5
|
+
source: string;
|
|
6
|
+
/** Turns a slice of `source` back into what the author wrote. */
|
|
7
|
+
restoreSource: (text: string) => string;
|
|
8
|
+
}
|
|
9
|
+
/** Parse a markdown document, directives included. */
|
|
10
|
+
export declare function parseMarkdown(markdown: string): ParsedMarkdown<Root>;
|
|
11
|
+
/**
|
|
12
|
+
* Parse a string that can only be inline content, such as a title from
|
|
13
|
+
* frontmatter: `1. Intro` is a title, not a list, and `Groups:Rings` has no
|
|
14
|
+
* directive in it.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseInlineMarkdown(markdown: string): ParsedMarkdown<PhrasingContent[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Root } from 'mdast';
|
|
2
|
+
import { Element, ElementContent } from 'xast';
|
|
3
|
+
/** A block of raw PreTeXt, standing in the mdast tree in place of `html` nodes. */
|
|
4
|
+
export interface RawBlock {
|
|
5
|
+
type: "ptxRaw";
|
|
6
|
+
element: Element;
|
|
7
|
+
}
|
|
8
|
+
/** Elements whose content is LaTeX or code, which Markdown must not touch. */
|
|
9
|
+
export declare const VERBATIM_ELEMENTS: Set<string>;
|
|
10
|
+
/** The nodes in a fragment of XML, or null if it isn't well-formed PreTeXt. */
|
|
11
|
+
export declare function parseRawXml(xml: string): ElementContent[] | null;
|
|
12
|
+
/** A raw inline tag: the nodes it stands for, plus the element it opens if any. */
|
|
13
|
+
export interface RawInlineTag {
|
|
14
|
+
children: ElementContent[];
|
|
15
|
+
opens?: Element;
|
|
16
|
+
}
|
|
17
|
+
export declare function parseRawInlineTag(value: string): RawInlineTag | null;
|
|
18
|
+
/**
|
|
19
|
+
* The index of the tag in `nodes` closing the element opened at `start`, or -1.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findClosingTag(nodes: {
|
|
22
|
+
type: string;
|
|
23
|
+
}[], start: number, name: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Replace the raw blocks in `tree` with {@link RawBlock} nodes. This has to run
|
|
26
|
+
* before sections are built, since a block can span what look like headings.
|
|
27
|
+
*/
|
|
28
|
+
export declare function collectRawBlocks(tree: Root, source: string | undefined, restoreSource: (text: string) => string): void;
|
|
@@ -25,10 +25,10 @@ export interface RemarkPretextOptions {
|
|
|
25
25
|
topLevelAttributes?: Record<string, string>;
|
|
26
26
|
/**
|
|
27
27
|
* Title of the document's top-level division (or, when `documentRoot` is
|
|
28
|
-
* set, the root's own title)
|
|
29
|
-
* markdown's frontmatter. When set for a
|
|
30
|
-
* heading (`#`) no longer supplies that title —
|
|
31
|
-
* subdivision instead.
|
|
28
|
+
* set, the root's own title), written as inline markdown. Overrides any
|
|
29
|
+
* `title:` field declared in the markdown's frontmatter. When set for a
|
|
30
|
+
* non-root document, a depth-1 heading (`#`) no longer supplies that title —
|
|
31
|
+
* it starts the first subdivision instead.
|
|
32
32
|
*/
|
|
33
33
|
topLevelTitle?: string;
|
|
34
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/remark-pretext",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "remark plugin to transform markdown-style PreTeXt directives into ptxast",
|
|
5
5
|
"author": "Oscar Levin",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"remark-parse": "^11.0.0",
|
|
47
47
|
"unified": "^11.0.0",
|
|
48
48
|
"unist-util-visit": "^5.0.0",
|
|
49
|
+
"xast-util-from-xml": "^4.0.0",
|
|
49
50
|
"xast-util-to-xml": "^4.0.0"
|
|
50
51
|
},
|
|
51
52
|
"publishConfig": {
|