@b4moss/hyogen-md 0.12.0 → 0.14.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 +24 -3
- package/README_ja.md +24 -3
- package/dist/build/build.d.ts +2 -0
- package/dist/build/buildDependencyGraph.d.ts +22 -0
- package/dist/build/collectDependencies.d.ts +8 -0
- package/dist/build/collectEntryPaths.d.ts +10 -0
- package/dist/build/isUnderscorePartial.d.ts +4 -0
- package/dist/cli.js +5742 -0
- package/dist/client.js +1111 -870
- package/dist/component/ComponentRegistry.d.ts +11 -0
- package/dist/component/parsePropsContract.d.ts +10 -0
- package/dist/component/renderComponent.d.ts +17 -0
- package/dist/component/validateProps.d.ts +7 -0
- package/dist/config/defineConfig.d.ts +5 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +143 -0
- package/dist/config/loadConfig.d.ts +13 -0
- package/dist/config/types.d.ts +26 -0
- package/dist/context/mergeContext.d.ts +3 -0
- package/dist/control/StructureNestTracker.d.ts +14 -0
- package/dist/control/expandControlStructures.d.ts +3 -0
- package/dist/control/parseControlOpener.d.ts +2 -0
- package/dist/control/parseControlStructures.d.ts +2 -0
- package/dist/createError-WZmAl05N.js +30 -0
- package/dist/errors/createError.d.ts +7 -0
- package/dist/errors/formatDiagnosticLog.d.ts +6 -0
- package/dist/errors/formatMessage.d.ts +3 -0
- package/dist/expr/evaluateExpression.d.ts +4 -0
- package/dist/expr/interpolateExpressions.d.ts +4 -0
- package/dist/expr/interpolateFenceExpressions.d.ts +8 -0
- package/dist/expr/parseExpression.d.ts +4 -0
- package/dist/frontmatter/parseFrontMatter.d.ts +3 -0
- package/dist/include/VisitStack.d.ts +13 -0
- package/dist/include/expandIncludes.d.ts +18 -0
- package/dist/index.d.ts +11 -113
- package/dist/index.js +839 -597
- package/dist/io/createFsLoader.d.ts +6 -0
- package/dist/io/createNodeLoader.d.ts +4 -0
- package/dist/io/isRemotePath.d.ts +2 -0
- package/dist/io/loadDataSources.d.ts +8 -0
- package/dist/io/parseCsvFromString.d.ts +1 -0
- package/dist/io/parseDataFile.d.ts +1 -0
- package/dist/io/resolveIncludePath.d.ts +1 -0
- package/dist/layout/expandExtendsAndBlocks.d.ts +19 -0
- package/dist/layout/parseBlockOpener.d.ts +8 -0
- package/dist/layout/parseBlockStructures.d.ts +15 -0
- package/dist/layout/parseExtendBlock.d.ts +12 -0
- package/dist/layout/parseExtendDirective.d.ts +5 -0
- package/dist/logic/executeDeclaration.d.ts +6 -0
- package/dist/logic/executeDeclarations.d.ts +6 -0
- package/dist/logic/executeStatement.d.ts +10 -0
- package/dist/logic/hgBlockUtils.d.ts +3 -0
- package/dist/logic/parseDeclaration.d.ts +5 -0
- package/dist/logic/parseStatement.d.ts +3 -0
- package/dist/logic/reservedWords.d.ts +2 -0
- package/dist/logic/stripComments.d.ts +2 -0
- package/dist/markdown/shiftHeadings.d.ts +25 -0
- package/dist/parse/hgMarkers.d.ts +5 -0
- package/dist/parse/parseComponentDirective.d.ts +6 -0
- package/dist/parse/parseIncludeDirective.d.ts +2 -0
- package/dist/parse/scanHgBlocks.d.ts +10 -0
- package/dist/paths/assertWithinRootDir.d.ts +2 -0
- package/dist/paths/findDocRoot.d.ts +1 -0
- package/dist/paths/resolveRenderInput.d.ts +11 -0
- package/dist/paths/resolveTemplatePath.d.ts +9 -0
- package/dist/pipeline/applyFrontMatterOutputOption.d.ts +4 -0
- package/dist/pipeline/executeHgBlocks.d.ts +9 -0
- package/dist/pipeline/joinRemovalSeam.d.ts +12 -0
- package/dist/pipeline/renderDocument.d.ts +22 -0
- package/dist/pipeline/stripHgComments.d.ts +7 -0
- package/dist/renderClient.d.ts +15 -0
- package/dist/renderServer.d.ts +4 -0
- package/dist/security/forbiddenKeys.d.ts +3 -0
- package/dist/security/scanSuspiciousContext.d.ts +6 -0
- package/dist/shims/fs-browser.d.ts +6 -0
- package/dist/shims/fs-promises-browser.d.ts +5 -0
- package/dist/toc/expandToc.d.ts +8 -0
- package/dist/toc/extractHeadings.d.ts +10 -0
- package/dist/toc/formatTocMarkdown.d.ts +7 -0
- package/dist/toc/githubHeadingSlug.d.ts +11 -0
- package/dist/toc/parseTocDirective.d.ts +10 -0
- package/dist/toc/plainifyHeadingText.d.ts +2 -0
- package/dist/types.d.ts +211 -0
- package/package.json +17 -4
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataSourcesMap, HyogenContext, Loader } from '../types.js';
|
|
2
|
+
/** Max UTF-8 byte length per data source file (5 MiB). */
|
|
3
|
+
export declare const DATA_SOURCE_MAX_BYTES: number;
|
|
4
|
+
export type LoadDataSourcesOptions = {
|
|
5
|
+
root?: string;
|
|
6
|
+
loader?: Loader;
|
|
7
|
+
};
|
|
8
|
+
export declare function loadDataSources(sources: DataSourcesMap, options?: LoadDataSourcesOptions): Promise<HyogenContext>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseCsvFromString(source: string, filePath?: string): Promise<Record<string, string>[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseDataFile(source: string, filePath: string): Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveIncludePath(root: string | undefined, includePath: string, documentPath?: string, fromPath?: string, constrainToRoot?: boolean, hyogenPath?: boolean): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { HyogenContext, HyogenWarning, Loader } from '../types.js';
|
|
2
|
+
import { VisitStack } from '../include/VisitStack.js';
|
|
3
|
+
export type ExpandExtendsAndBlocksOptions = {
|
|
4
|
+
path?: string;
|
|
5
|
+
context: HyogenContext;
|
|
6
|
+
/** Only the updated bindings after `executeDeclarations` (child wins when merging) */
|
|
7
|
+
declarationUpdates: HyogenContext;
|
|
8
|
+
loader?: Loader;
|
|
9
|
+
root?: string;
|
|
10
|
+
constrainToRoot?: boolean;
|
|
11
|
+
visitStack: VisitStack;
|
|
12
|
+
warnings?: HyogenWarning[];
|
|
13
|
+
inComponent?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type ExpandExtendsAndBlocksResult = {
|
|
16
|
+
source: string;
|
|
17
|
+
context: HyogenContext;
|
|
18
|
+
};
|
|
19
|
+
export declare function expandExtendsAndBlocks(source: string, options: ExpandExtendsAndBlocksOptions): Promise<ExpandExtendsAndBlocksResult>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type BlockStructure = {
|
|
2
|
+
name: string;
|
|
3
|
+
body: string;
|
|
4
|
+
/** span start (includes opener) */
|
|
5
|
+
start: number;
|
|
6
|
+
/** span end (includes closer) */
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
export type ParseBlockStructuresOptions = {
|
|
10
|
+
path?: string;
|
|
11
|
+
mode: "layout" | "child";
|
|
12
|
+
/** child parsing rule: blocks are only allowed when extend exists */
|
|
13
|
+
hasExtend?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function parseBlockStructures(source: string, options: ParseBlockStructuresOptions): BlockStructure[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ExtendBlockParseResult = {
|
|
2
|
+
path: string;
|
|
3
|
+
/** remaining lines after `extend <path>` (declaration source) */
|
|
4
|
+
declarationsSource: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Parses an `@hg` block that begins with `extend <path>` and (optionally)
|
|
8
|
+
* contains declaration lines after it.
|
|
9
|
+
*
|
|
10
|
+
* Returns null when the first non-empty line isn't an `extend`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseExtendBlock(inner: string, pathForError?: string): ExtendBlockParseResult | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Declaration, HyogenContext } from '../types.js';
|
|
2
|
+
export type ExecuteDeclarationOptions = {
|
|
3
|
+
path?: string;
|
|
4
|
+
constBindings?: Set<string>;
|
|
5
|
+
};
|
|
6
|
+
export declare function executeDeclaration(declaration: Declaration, context: HyogenContext, options?: ExecuteDeclarationOptions): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ExecuteDeclarationsResult, HyogenContext } from '../types.js';
|
|
2
|
+
export type ExecuteDeclarationsOptions = {
|
|
3
|
+
path?: string;
|
|
4
|
+
context?: HyogenContext;
|
|
5
|
+
};
|
|
6
|
+
export declare function executeDeclarations(source: string, options?: ExecuteDeclarationsOptions): Promise<ExecuteDeclarationsResult>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HyogenContext, Statement } from '../types.js';
|
|
2
|
+
export type ExecuteStatementOptions = {
|
|
3
|
+
path?: string;
|
|
4
|
+
constBindings?: Set<string>;
|
|
5
|
+
onUpdate?: (name: string) => void;
|
|
6
|
+
/** Accumulates stringified `echo` outputs in document order. */
|
|
7
|
+
echoChunks?: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare function executeStatement(statement: Statement, context: HyogenContext, options?: ExecuteStatementOptions): Promise<void>;
|
|
10
|
+
export declare function executeStatementList(statements: Statement[], context: HyogenContext, options?: ExecuteStatementOptions): Promise<void>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Declaration, ExprNode } from '../types.js';
|
|
2
|
+
export declare function parseDeclaration(source: string, path?: string): Declaration;
|
|
3
|
+
export declare function parseDeclarationStatements(source: string, path?: string): Declaration[];
|
|
4
|
+
export declare function isDeclarationSource(source: string): boolean;
|
|
5
|
+
export type { ExprNode };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown heading helpers for include/component hierarchy shifting.
|
|
3
|
+
* ATX + Setext; code fences (``` / ~~~) are excluded.
|
|
4
|
+
*/
|
|
5
|
+
export type FenceState = {
|
|
6
|
+
active: boolean;
|
|
7
|
+
marker: "`" | "~" | null;
|
|
8
|
+
length: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function createFenceState(): FenceState;
|
|
11
|
+
/** Update fence state for a single line; returns whether the line is inside a fence (including fence markers). */
|
|
12
|
+
export declare function consumeFenceLine(state: FenceState, line: string): boolean;
|
|
13
|
+
export declare function parseAtxHeadingLevel(line: string): number | null;
|
|
14
|
+
export declare function parseSetextUnderlineLevel(line: string): number | null;
|
|
15
|
+
/**
|
|
16
|
+
* Return the heading level of the nearest heading before the end of `prefix`.
|
|
17
|
+
* Returns 0 when none found.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findPrecedingHeadingLevel(prefix: string): number;
|
|
20
|
+
/**
|
|
21
|
+
* Shift all headings in `markdown` by `shift` levels (clamped to 6).
|
|
22
|
+
* Setext headings are normalized to ATX when shift is applied (shift > 0).
|
|
23
|
+
* When shift <= 0, returns markdown unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export declare function shiftMarkdownHeadings(markdown: string, shift: number): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type HgMarkerKind = "hg" | "at-at" | "mixed" | "unclosed" | "none";
|
|
2
|
+
/** Classifies hyogen marker usage inside an HTML comment body. */
|
|
3
|
+
export declare function classifyHgMarkers(inner: string): HgMarkerKind;
|
|
4
|
+
/** Strips @hg/@endhg/@@ markers from a hyogen comment inner body. */
|
|
5
|
+
export declare function stripHgMarkers(inner: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HgBlock } from '../types.js';
|
|
2
|
+
/** Finds complete hyogen HTML comment blocks in document order. */
|
|
3
|
+
export declare function scanHgBlocks(source: string): HgBlock[];
|
|
4
|
+
/**
|
|
5
|
+
* Detects unclosed or mixed hyogen markers inside HTML comments (execute stage).
|
|
6
|
+
* Mixed `@hg`/`@@` markers are treated as invalid (same as unclosed for callers).
|
|
7
|
+
*/
|
|
8
|
+
export declare function findUnclosedHgBlock(source: string): boolean;
|
|
9
|
+
/** Returns a parse_error message when markers are mixed or unclosed. */
|
|
10
|
+
export declare function describeHgBlockMarkerError(source: string): string | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findDocRoot(startPath: string): string | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ResolvedRenderInput = {
|
|
2
|
+
source: string;
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
entryPath?: string;
|
|
5
|
+
constrainToRoot?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function resolveRenderInput(input: string | {
|
|
8
|
+
path: string;
|
|
9
|
+
}, options?: {
|
|
10
|
+
root?: string;
|
|
11
|
+
}): Promise<ResolvedRenderInput>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type ResolveTemplatePathOptions = {
|
|
2
|
+
rootDir?: string;
|
|
3
|
+
fromPath?: string;
|
|
4
|
+
documentPath?: string;
|
|
5
|
+
constrainToRoot?: boolean;
|
|
6
|
+
/** When true, `/` paths are hyogen root-relative (require doc root). */
|
|
7
|
+
hyogenPath?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function resolveTemplatePath(templatePath: string, options?: ResolveTemplatePathOptions): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ComponentRegistry } from '../component/ComponentRegistry.js';
|
|
2
|
+
import { ExecuteHgBlocksResult, HyogenContext } from '../types.js';
|
|
3
|
+
export declare function createIncludeMarker(index: number): string;
|
|
4
|
+
export type ExecuteHgBlocksOptions = {
|
|
5
|
+
path?: string;
|
|
6
|
+
registry?: ComponentRegistry;
|
|
7
|
+
context?: HyogenContext;
|
|
8
|
+
};
|
|
9
|
+
export declare function executeHgBlocks(source: string, options?: ExecuteHgBlocksOptions): ExecuteHgBlocksResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Counts trailing `\n` characters. */
|
|
2
|
+
export declare function countTrailingNewlines(text: string): number;
|
|
3
|
+
/** Counts leading `\n` characters. */
|
|
4
|
+
export declare function countLeadingNewlines(text: string): number;
|
|
5
|
+
/**
|
|
6
|
+
* Joins `left` and `right` after a removed directive span.
|
|
7
|
+
* Keeps max(trailing left newlines, leading right newlines) so removal does
|
|
8
|
+
* not invent an extra blank line, while author blank lines are preserved.
|
|
9
|
+
*/
|
|
10
|
+
export declare function joinRemovalSeam(left: string, right: string): string;
|
|
11
|
+
/** Newline characters dropped by {@link joinRemovalSeam} (for offset tracking). */
|
|
12
|
+
export declare function removalSeamNewlineDelta(left: string, right: string): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HyogenContext, HyogenWarning, RenderOptions, RenderResult } from '../types.js';
|
|
2
|
+
import { ComponentRegistry } from '../component/ComponentRegistry.js';
|
|
3
|
+
import { VisitStack } from '../include/VisitStack.js';
|
|
4
|
+
export type RenderDocumentOptions = RenderOptions & {
|
|
5
|
+
path?: string;
|
|
6
|
+
context?: HyogenContext;
|
|
7
|
+
registry?: ComponentRegistry;
|
|
8
|
+
warnings?: HyogenWarning[];
|
|
9
|
+
visitStack?: VisitStack;
|
|
10
|
+
/** When true, renders through the `component` path (extend is skipped with warning). */
|
|
11
|
+
inComponent?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type RenderDocumentBodyOptions = RenderDocumentOptions & {
|
|
14
|
+
context: HyogenContext;
|
|
15
|
+
};
|
|
16
|
+
export declare function renderDocumentBody(body: string, options: RenderDocumentBodyOptions): Promise<string>;
|
|
17
|
+
export declare function renderDocument(source: string, options?: RenderDocumentOptions): Promise<RenderResult>;
|
|
18
|
+
export type RenderChildDocumentOptions = Omit<RenderDocumentOptions, "context"> & {
|
|
19
|
+
context: HyogenContext;
|
|
20
|
+
};
|
|
21
|
+
/** Renders an included child document through the full pipeline. */
|
|
22
|
+
export declare function renderChildDocument(source: string, options: RenderChildDocumentOptions): Promise<string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes complete hyogen HTML comment blocks from source.
|
|
3
|
+
* At each removal seam, joins surrounding newline runs with max(left, right)
|
|
4
|
+
* so directive removal does not invent an extra blank line, while author
|
|
5
|
+
* blank lines around the comment are preserved.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stripHgComments(source: string, preserveHgComments?: boolean): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DataSourcesMap, HyogenContext, RenderOptions, RenderResult } from './types.js';
|
|
2
|
+
type ClientRenderOptions = RenderOptions & {
|
|
3
|
+
/** Rejected on client — use renderServer/build instead */
|
|
4
|
+
serverContext?: HyogenContext;
|
|
5
|
+
/** Rejected on client — use renderServer/build instead */
|
|
6
|
+
dataSources?: DataSourcesMap;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Client-side render entry. Requires an injected loader; never uses
|
|
10
|
+
* createNodeLoader / resolveRenderInput (no FS or network in the library).
|
|
11
|
+
*/
|
|
12
|
+
export declare function renderClient(input: string | {
|
|
13
|
+
path: string;
|
|
14
|
+
}, context?: HyogenContext, options?: ClientRenderOptions): Promise<RenderResult>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HyogenContext, HyogenWarning } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively scans context string leaves for suspicious patterns.
|
|
4
|
+
* Does not mutate context values; only appends warnings.
|
|
5
|
+
*/
|
|
6
|
+
export declare function scanSuspiciousContext(context: HyogenContext, warnings: HyogenWarning[], path?: string): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Browser shim — node:fs/promises must not be used on the client entry. */
|
|
2
|
+
export declare function readFile(_path: string, _encoding?: string): Promise<string>;
|
|
3
|
+
export declare function stat(_path: string): Promise<never>;
|
|
4
|
+
export declare function mkdir(_path: string, _options?: unknown): Promise<void>;
|
|
5
|
+
export declare function writeFile(_path: string, _data: string): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ExpandTocOptions = {
|
|
2
|
+
path?: string;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Replace toc directives with Markdown TOC lists (pipeline step 7).
|
|
6
|
+
* Headings are taken once from the pre-replacement source.
|
|
7
|
+
*/
|
|
8
|
+
export declare function expandToc(source: string, options?: ExpandTocOptions): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ExtractedHeading = {
|
|
2
|
+
level: number;
|
|
3
|
+
text: string;
|
|
4
|
+
explicitId?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Extract ATX / Setext headings from Markdown.
|
|
8
|
+
* Skips fenced code (``` / ~~~), HTML comments, and hyogen blocks (comments).
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractHeadings(source: string): ExtractedHeading[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExtractedHeading } from './extractHeadings.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a nested Markdown TOC list from headings.
|
|
4
|
+
* Anchors are assigned for *all* headings (document order) before filtering by maxLevel,
|
|
5
|
+
* so duplicate suffixes match full-document GitHub IDs.
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatTocMarkdown(headings: ExtractedHeading[], maxLevel: number): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub-compatible heading slug (no external deps).
|
|
3
|
+
* Explicit IDs are used as-is; otherwise lowercase, strip punctuation, spaces→`-`.
|
|
4
|
+
* Duplicate base slugs get `-1`, `-2`, … suffixes (GitHub behavior).
|
|
5
|
+
*/
|
|
6
|
+
export type HeadingSlugger = {
|
|
7
|
+
slug(text: string, explicitId?: string): string;
|
|
8
|
+
};
|
|
9
|
+
export declare function createHeadingSlugger(): HeadingSlugger;
|
|
10
|
+
/** One-shot slug without duplicate tracking. */
|
|
11
|
+
export declare function githubSlugify(text: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type TocDirective = {
|
|
2
|
+
maxLevel: number;
|
|
3
|
+
};
|
|
4
|
+
/** True when a single line looks like a toc directive (args validated later). */
|
|
5
|
+
export declare function isTocDirectiveLine(line: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Parses a toc / toc(N) directive from a block inner or a single source line.
|
|
8
|
+
* N defaults to 6; must be an integer 1–6 when present.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseTocDirective(source: string, path?: string): TocDirective;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export type HyogenContext = Record<string, unknown>;
|
|
2
|
+
export type HyogenDiagnostic = {
|
|
3
|
+
code: string;
|
|
4
|
+
message: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
details?: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export type HyogenWarning = HyogenDiagnostic;
|
|
9
|
+
export type HyogenError = Error & HyogenDiagnostic;
|
|
10
|
+
export type Loader = (path: string) => Promise<string>;
|
|
11
|
+
export type DataSourcesMap = Record<string, string>;
|
|
12
|
+
export type RenderOptions = {
|
|
13
|
+
preserveFrontMatter?: boolean;
|
|
14
|
+
preserveHgComments?: boolean;
|
|
15
|
+
loader?: Loader;
|
|
16
|
+
root?: string;
|
|
17
|
+
path?: string;
|
|
18
|
+
constrainToRoot?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type ServerRenderOptions = RenderOptions & {
|
|
21
|
+
serverContext?: HyogenContext;
|
|
22
|
+
/** Variable name → root-relative data file path (YAML / JSON / CSV). */
|
|
23
|
+
dataSources?: DataSourcesMap;
|
|
24
|
+
};
|
|
25
|
+
export type RenderResult = {
|
|
26
|
+
markdown: string;
|
|
27
|
+
warnings: HyogenWarning[];
|
|
28
|
+
};
|
|
29
|
+
export type BuildOptions = RenderOptions & {
|
|
30
|
+
input: string | string[];
|
|
31
|
+
outDir: string;
|
|
32
|
+
includeUnderscoreEntries?: boolean;
|
|
33
|
+
context?: HyogenContext;
|
|
34
|
+
serverContext?: HyogenContext;
|
|
35
|
+
dataSources?: DataSourcesMap;
|
|
36
|
+
};
|
|
37
|
+
export type BuildResult = {
|
|
38
|
+
files: {
|
|
39
|
+
path: string;
|
|
40
|
+
markdown: string;
|
|
41
|
+
}[];
|
|
42
|
+
warnings: HyogenWarning[];
|
|
43
|
+
};
|
|
44
|
+
export type HgBlock = {
|
|
45
|
+
start: number;
|
|
46
|
+
end: number;
|
|
47
|
+
inner: string;
|
|
48
|
+
raw: string;
|
|
49
|
+
};
|
|
50
|
+
export type IncludeDirective = {
|
|
51
|
+
kind: "include";
|
|
52
|
+
path: string;
|
|
53
|
+
marker: string;
|
|
54
|
+
raw?: string;
|
|
55
|
+
};
|
|
56
|
+
export type ComponentDirective = {
|
|
57
|
+
kind: "component";
|
|
58
|
+
path: string;
|
|
59
|
+
alias: string;
|
|
60
|
+
};
|
|
61
|
+
export type ParseFrontMatterResult = {
|
|
62
|
+
context: HyogenContext;
|
|
63
|
+
body: string;
|
|
64
|
+
rawFrontMatter?: string;
|
|
65
|
+
};
|
|
66
|
+
export type ExecuteHgBlocksResult = {
|
|
67
|
+
source: string;
|
|
68
|
+
directives: IncludeDirective[];
|
|
69
|
+
};
|
|
70
|
+
export type BinaryOp = "+" | "-" | "*" | "/" | "===" | "!==" | "==" | "!=" | ">=" | "<=" | ">" | "<" | "&&" | "||";
|
|
71
|
+
export type ExprNode = {
|
|
72
|
+
type: "identifier";
|
|
73
|
+
name: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: "literal";
|
|
76
|
+
value: unknown;
|
|
77
|
+
} | {
|
|
78
|
+
type: "member";
|
|
79
|
+
object: ExprNode;
|
|
80
|
+
property: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: "default";
|
|
83
|
+
left: ExprNode;
|
|
84
|
+
right: ExprNode;
|
|
85
|
+
} | {
|
|
86
|
+
type: "call";
|
|
87
|
+
callee: string;
|
|
88
|
+
args: Record<string, ExprNode>;
|
|
89
|
+
} | {
|
|
90
|
+
type: "method";
|
|
91
|
+
object: ExprNode;
|
|
92
|
+
method: string;
|
|
93
|
+
args: unknown[];
|
|
94
|
+
} | {
|
|
95
|
+
type: "unary";
|
|
96
|
+
op: "!";
|
|
97
|
+
operand: ExprNode;
|
|
98
|
+
} | {
|
|
99
|
+
type: "binary";
|
|
100
|
+
op: BinaryOp;
|
|
101
|
+
left: ExprNode;
|
|
102
|
+
right: ExprNode;
|
|
103
|
+
} | {
|
|
104
|
+
type: "ternary";
|
|
105
|
+
condition: ExprNode;
|
|
106
|
+
consequent: ExprNode;
|
|
107
|
+
alternate: ExprNode;
|
|
108
|
+
} | {
|
|
109
|
+
type: "template";
|
|
110
|
+
parts: Array<string | ExprNode>;
|
|
111
|
+
};
|
|
112
|
+
export type Declaration = {
|
|
113
|
+
kind: "const";
|
|
114
|
+
name: string;
|
|
115
|
+
expr: ExprNode;
|
|
116
|
+
} | {
|
|
117
|
+
kind: "let";
|
|
118
|
+
name: string;
|
|
119
|
+
expr: ExprNode;
|
|
120
|
+
} | {
|
|
121
|
+
kind: "assign";
|
|
122
|
+
name: string;
|
|
123
|
+
expr: ExprNode;
|
|
124
|
+
};
|
|
125
|
+
export type CompoundAssignOp = "+=" | "-=" | "*=" | "/=";
|
|
126
|
+
export type Statement = Declaration | {
|
|
127
|
+
kind: "for";
|
|
128
|
+
init: Statement | null;
|
|
129
|
+
cond: ExprNode;
|
|
130
|
+
update: Statement | null;
|
|
131
|
+
body: Statement[];
|
|
132
|
+
} | {
|
|
133
|
+
kind: "do_while";
|
|
134
|
+
body: Statement[];
|
|
135
|
+
cond: ExprNode;
|
|
136
|
+
} | {
|
|
137
|
+
kind: "update";
|
|
138
|
+
name: string;
|
|
139
|
+
op: "++" | "--";
|
|
140
|
+
position: "prefix" | "postfix";
|
|
141
|
+
} | {
|
|
142
|
+
kind: "compound_assign";
|
|
143
|
+
name: string;
|
|
144
|
+
op: CompoundAssignOp;
|
|
145
|
+
expr: ExprNode;
|
|
146
|
+
} | {
|
|
147
|
+
kind: "echo";
|
|
148
|
+
expr: ExprNode;
|
|
149
|
+
};
|
|
150
|
+
export type ControlOpener = {
|
|
151
|
+
kind: "if";
|
|
152
|
+
expr: ExprNode;
|
|
153
|
+
} | {
|
|
154
|
+
kind: "else_if";
|
|
155
|
+
expr: ExprNode;
|
|
156
|
+
} | {
|
|
157
|
+
kind: "else";
|
|
158
|
+
} | {
|
|
159
|
+
kind: "endif";
|
|
160
|
+
} | {
|
|
161
|
+
kind: "each";
|
|
162
|
+
item: string;
|
|
163
|
+
expr: ExprNode;
|
|
164
|
+
} | {
|
|
165
|
+
kind: "endeach";
|
|
166
|
+
};
|
|
167
|
+
export type ControlBlockSpan = {
|
|
168
|
+
start: number;
|
|
169
|
+
end: number;
|
|
170
|
+
raw: string;
|
|
171
|
+
};
|
|
172
|
+
export type IfBranch = {
|
|
173
|
+
kind: "if" | "else_if" | "else";
|
|
174
|
+
expr?: ExprNode;
|
|
175
|
+
opener: ControlBlockSpan;
|
|
176
|
+
body: ControlNode[];
|
|
177
|
+
};
|
|
178
|
+
export type ControlNode = {
|
|
179
|
+
kind: "text";
|
|
180
|
+
content: string;
|
|
181
|
+
} | {
|
|
182
|
+
kind: "if";
|
|
183
|
+
branches: IfBranch[];
|
|
184
|
+
closer: ControlBlockSpan;
|
|
185
|
+
} | {
|
|
186
|
+
kind: "each";
|
|
187
|
+
item: string;
|
|
188
|
+
expr: ExprNode;
|
|
189
|
+
opener: ControlBlockSpan;
|
|
190
|
+
body: ControlNode[];
|
|
191
|
+
closer: ControlBlockSpan;
|
|
192
|
+
};
|
|
193
|
+
export type ExecuteDeclarationsResult = {
|
|
194
|
+
source: string;
|
|
195
|
+
context: HyogenContext;
|
|
196
|
+
/** Updated bindings caused by executed declaration blocks. */
|
|
197
|
+
declarationUpdates?: HyogenContext;
|
|
198
|
+
};
|
|
199
|
+
export type EvaluateExpressionOptions = {
|
|
200
|
+
context: HyogenContext;
|
|
201
|
+
path?: string;
|
|
202
|
+
registry?: import('./component/ComponentRegistry.js').ComponentRegistry;
|
|
203
|
+
loader?: Loader;
|
|
204
|
+
rootDir?: string;
|
|
205
|
+
warnings?: HyogenWarning[];
|
|
206
|
+
visitStack?: import('./include/VisitStack.js').VisitStack;
|
|
207
|
+
parentContext?: HyogenContext;
|
|
208
|
+
preserveHgComments?: boolean;
|
|
209
|
+
constrainToRoot?: boolean;
|
|
210
|
+
};
|
|
211
|
+
export type InterpolateExpressionsOptions = EvaluateExpressionOptions;
|