myst-transforms
Advanced tools
Comparing version 1.1.19 to 1.2.0
@@ -12,2 +12,3 @@ import { toText } from 'myst-common'; | ||
.filter(([abbr]) => abbr.length > 1) // We can't match on single characters! | ||
.sort((a, b) => b[0].length - a[0].length || a[0].localeCompare(b[0])) // Sort by length (longest-first) then locale-ordering | ||
.map(([abbr, title]) => [ | ||
@@ -29,2 +30,4 @@ abbr, | ||
return; | ||
// Inline abbreviations have lower priority to passed-in abbreviations | ||
// So, we replace conflicting titles with those that have been passed-in | ||
const abbreviations = selectAll('abbreviation', mdast); | ||
@@ -40,2 +43,3 @@ abbreviations.forEach((node) => { | ||
}); | ||
// Replace instances of abbreviated constructs with their titles | ||
replaceText(mdast, opts); | ||
@@ -42,0 +46,0 @@ if (opts.firstTimeLong) { |
@@ -13,2 +13,3 @@ import { liftMystDirectivesAndRolesTransform } from './liftMystDirectivesAndRoles.js'; | ||
import { containerChildrenTransform } from './containers.js'; | ||
import { headingDepthTransform } from './headings.js'; | ||
export function basicTransformations(tree, file, opts) { | ||
@@ -39,2 +40,3 @@ // lifting roles and directives must happen before the mystTarget transformation | ||
removeUnicodeTransform(tree); | ||
headingDepthTransform(tree, file, opts); | ||
} | ||
@@ -41,0 +43,0 @@ export const basicTransformationsPlugin = (opts) => (tree, file) => { |
@@ -32,3 +32,3 @@ import type { Plugin } from 'unified'; | ||
type TargetCounts = { | ||
heading?: (number | null)[]; | ||
heading: (number | null)[]; | ||
} & Record<string, { | ||
@@ -39,12 +39,15 @@ main: number; | ||
export type StateOptions = { | ||
state: IReferenceState; | ||
state: ReferenceState; | ||
}; | ||
export type StateResolverOptions = { | ||
state: IReferenceStateResolver; | ||
}; | ||
export type NumberingOptions = { | ||
enumerator?: string; | ||
figure?: boolean; | ||
subfigure?: boolean; | ||
equation?: boolean; | ||
subequation?: boolean; | ||
table?: boolean; | ||
code?: boolean; | ||
figure?: boolean | number; | ||
subfigure?: boolean | number; | ||
equation?: boolean | number; | ||
subequation?: boolean | number; | ||
table?: boolean | number; | ||
code?: boolean | number; | ||
heading_1?: boolean; | ||
@@ -75,6 +78,4 @@ heading_2?: boolean; | ||
export declare function formatHeadingEnumerator(counts: (number | null)[], prefix?: string): string; | ||
export interface IReferenceState { | ||
file?: VFile; | ||
initializeNumberedHeadingDepths: (tree: GenericParent) => void; | ||
addTarget: (node: TargetNodes) => void; | ||
export interface IReferenceStateResolver { | ||
vfile?: VFile; | ||
/** | ||
@@ -84,6 +85,11 @@ * If the page is provided, it will only look at that page. | ||
getTarget: (identifier?: string, page?: string) => Target | undefined; | ||
getFileTarget: (identifier?: string) => ReferenceState | undefined; | ||
resolveReferenceContent: (node: ResolvableCrossReference) => void; | ||
} | ||
export declare class ReferenceState implements IReferenceState { | ||
file?: VFile; | ||
export declare class ReferenceState implements IReferenceStateResolver { | ||
vfile?: VFile; | ||
filePath: string; | ||
url?: string; | ||
title?: string; | ||
dataUrl?: string; | ||
numberAll: boolean | null; | ||
@@ -93,6 +99,11 @@ numbering: NumberingOptions; | ||
targetCounts: TargetCounts; | ||
constructor(opts?: { | ||
identifiers: string[]; | ||
constructor(filePath: string, opts?: { | ||
url?: string; | ||
dataUrl?: string; | ||
title?: string; | ||
targetCounts?: TargetCounts; | ||
numbering?: boolean | NumberingOptions; | ||
file?: VFile; | ||
identifiers?: string[]; | ||
vfile?: VFile; | ||
}); | ||
@@ -110,24 +121,13 @@ addTarget(node: TargetNodes): void; | ||
getTarget(identifier?: string): Target | undefined; | ||
getFileTarget(identifier?: string): ReferenceState | undefined; | ||
resolveReferenceContent(node: ResolvableCrossReference): void; | ||
warnNodeTargetNotFound(node: ResolvableCrossReference): void; | ||
} | ||
type StateAndFile = { | ||
state: ReferenceState; | ||
file: string; | ||
url: string | null; | ||
dataUrl: string | null; | ||
}; | ||
type IStateList = StateAndFile[]; | ||
export declare class MultiPageReferenceState implements IReferenceState { | ||
file?: VFile; | ||
states: StateAndFile[]; | ||
fileState: ReferenceState; | ||
export declare class MultiPageReferenceResolver implements IReferenceStateResolver { | ||
states: ReferenceState[]; | ||
filePath: string; | ||
url: string; | ||
dataUrl: string; | ||
constructor(states: IStateList, filePath: string); | ||
resolveStateProvider(identifier?: string, page?: string): StateAndFile | undefined; | ||
addTarget(node: TargetNodes): void; | ||
initializeNumberedHeadingDepths(tree: GenericParent): void; | ||
vfile?: VFile; | ||
constructor(states: ReferenceState[], filePath: string, vfile?: VFile); | ||
resolveStateProvider(identifier?: string, page?: string): ReferenceState | undefined; | ||
getTarget(identifier?: string, page?: string): Target | undefined; | ||
getFileTarget(identifier?: string): ReferenceState | undefined; | ||
resolveReferenceContent(node: ResolvableCrossReference): void; | ||
@@ -142,11 +142,13 @@ } | ||
* By default, captionNumber is only added if caption already exists. | ||
* However, for subcontainers, captionNumber is always added. | ||
* However, for sub-containers, captionNumber is always added. | ||
*/ | ||
export declare function addContainerCaptionNumbersTransform(tree: GenericParent, file: VFile, opts: StateOptions): void; | ||
export declare const resolveReferenceLinksTransform: (tree: GenericParent, opts: StateOptions) => void; | ||
export declare const resolveUnlinkedCitations: (tree: GenericParent, opts: StateOptions) => void; | ||
export declare const resolveCrossReferencesTransform: (tree: GenericParent, opts: StateOptions) => void; | ||
export declare const resolveReferencesTransform: (tree: GenericParent, file: VFile, opts: StateOptions) => void; | ||
export declare const resolveReferencesPlugin: Plugin<[StateOptions], GenericParent, GenericParent>; | ||
export declare function addContainerCaptionNumbersTransform(tree: GenericParent, file: VFile, opts: StateResolverOptions): void; | ||
export declare const resolveReferenceLinksTransform: (tree: GenericParent, opts: StateResolverOptions) => void; | ||
export declare const resolveUnlinkedCitations: (tree: GenericParent, opts: StateResolverOptions) => void; | ||
export declare const resolveCrossReferencesTransform: (tree: GenericParent, opts: StateResolverOptions) => void; | ||
export declare const resolveReferencesTransform: (tree: GenericParent, file: VFile, opts: StateResolverOptions) => void; | ||
export declare const resolveReferencesPlugin: Plugin<[ | ||
StateResolverOptions | ||
], GenericParent, GenericParent>; | ||
export {}; | ||
//# sourceMappingURL=enumerate.d.ts.map |
@@ -5,2 +5,3 @@ import { visit } from 'unist-util-visit'; | ||
import { createHtmlId, fileWarn, normalizeLabel, setTextAsChild, copyNode, liftChildren, TargetKind, RuleId, } from 'myst-common'; | ||
import { updateLinkTextIfEmpty } from './links/utils.js'; | ||
const TRANSFORM_NAME = 'myst-transforms:enumerate'; | ||
@@ -107,7 +108,7 @@ function getDefaultNumberedReferenceLabel(kind) { | ||
if (kind === 'heading' && node.type === 'heading') { | ||
return ((_a = numbering[`heading_${node.depth}`]) !== null && _a !== void 0 ? _a : false); | ||
return ((_a = !!numbering[`heading_${node.depth}`]) !== null && _a !== void 0 ? _a : false); | ||
} | ||
if (node.subcontainer) | ||
return (_b = numbering.subfigure) !== null && _b !== void 0 ? _b : false; | ||
return (_c = numbering[kind]) !== null && _c !== void 0 ? _c : false; | ||
return (_b = !!numbering.subfigure) !== null && _b !== void 0 ? _b : false; | ||
return (_c = !!numbering[kind]) !== null && _c !== void 0 ? _c : false; | ||
} | ||
@@ -150,5 +151,9 @@ /** | ||
export class ReferenceState { | ||
constructor(opts) { | ||
constructor(filePath, opts) { | ||
var _a, _b, _c; | ||
var _d; | ||
this.numberAll = null; | ||
this.targetCounts = (opts === null || opts === void 0 ? void 0 : opts.targetCounts) || {}; | ||
// Initialize the heading counts (it is different) | ||
(_a = (_d = this.targetCounts).heading) !== null && _a !== void 0 ? _a : (_d.heading = [0, 0, 0, 0, 0, 0]); | ||
if (typeof (opts === null || opts === void 0 ? void 0 : opts.numbering) === 'boolean') { | ||
@@ -169,4 +174,20 @@ this.numberAll = opts === null || opts === void 0 ? void 0 : opts.numbering; | ||
} | ||
// Set the offset counts if the numbering does not start at zero | ||
Object.entries((_b = opts === null || opts === void 0 ? void 0 : opts.numbering) !== null && _b !== void 0 ? _b : {}).forEach(([key, val]) => { | ||
if (typeof val === 'number') { | ||
if (key in ['heading_1', 'heading_2', 'heading_3', 'heading_4', 'heading_5', 'heading_6']) { | ||
this.targetCounts.heading[Number.parseInt(key.slice(-1), 10) - 1] = val; | ||
} | ||
else { | ||
this.targetCounts[key] = { main: val, sub: 0 }; | ||
} | ||
} | ||
}); | ||
this.identifiers = (_c = opts === null || opts === void 0 ? void 0 : opts.identifiers) !== null && _c !== void 0 ? _c : []; | ||
this.targets = {}; | ||
this.file = opts === null || opts === void 0 ? void 0 : opts.file; | ||
this.vfile = opts === null || opts === void 0 ? void 0 : opts.vfile; | ||
this.filePath = filePath; | ||
this.url = opts === null || opts === void 0 ? void 0 : opts.url; | ||
this.dataUrl = opts === null || opts === void 0 ? void 0 : opts.dataUrl; | ||
this.title = opts === null || opts === void 0 ? void 0 : opts.title; | ||
} | ||
@@ -192,8 +213,9 @@ addTarget(node) { | ||
} | ||
if (node.identifier && this.targets[node.identifier]) { | ||
if (!this.file) | ||
if (node.identifier && | ||
(this.targets[node.identifier] || this.identifiers.includes(node.identifier))) { | ||
if (!this.vfile) | ||
return; | ||
if (node.implicit) | ||
return; // Do not warn on implicit headings | ||
fileWarn(this.file, `Duplicate identifier "${node.identifier}" for node of type ${node.type}`, { | ||
fileWarn(this.vfile, `Duplicate identifier "${node.identifier}" for node of type ${node.type}`, { | ||
node, | ||
@@ -231,4 +253,2 @@ source: TRANSFORM_NAME, | ||
// heading count to do a better job initializing headers based on tree | ||
if (!this.targetCounts.heading) | ||
this.targetCounts.heading = [0, 0, 0, 0, 0, 0]; | ||
this.targetCounts.heading = incrementHeadingCounts(node.depth, this.targetCounts.heading); | ||
@@ -271,7 +291,27 @@ enumerator = formatHeadingEnumerator(this.targetCounts.heading, this.numbering.enumerator); | ||
} | ||
getFileTarget(identifier) { | ||
if (!identifier) | ||
return undefined; | ||
if (this.identifiers.includes(identifier)) | ||
return this; | ||
} | ||
resolveReferenceContent(node) { | ||
var _a, _b, _c, _d; | ||
const fileTarget = this.getFileTarget(node.identifier); | ||
if (fileTarget) { | ||
const { url, title, dataUrl } = fileTarget; | ||
if (url) { | ||
const nodeAsLink = node; | ||
nodeAsLink.type = 'link'; | ||
nodeAsLink.url = url; | ||
nodeAsLink.internal = true; | ||
if (dataUrl) | ||
nodeAsLink.dataUrl = dataUrl; | ||
updateLinkTextIfEmpty(nodeAsLink, title !== null && title !== void 0 ? title : url); | ||
} | ||
return; | ||
} | ||
const target = this.getTarget(node.identifier); | ||
if (!target) { | ||
this.warnNodeTargetNotFound(node); | ||
warnNodeTargetNotFound(node, this.vfile); | ||
return; | ||
@@ -286,6 +326,6 @@ } | ||
const headingTemplate = numberHeading ? 'Section %s' : '{name}'; | ||
fillReferenceEnumerators(this.file, node, headingTemplate, target.node.enumerator, copyNode(target.node).children); | ||
fillReferenceEnumerators(this.vfile, node, headingTemplate, target.node.enumerator, copyNode(target.node).children); | ||
} | ||
else if (target.kind === TargetKind.equation) { | ||
fillReferenceEnumerators(this.file, node, '(%s)', target.node.enumerator); | ||
fillReferenceEnumerators(this.vfile, node, '(%s)', target.node.enumerator); | ||
} | ||
@@ -308,3 +348,3 @@ else { | ||
: getDefaultNamedReferenceLabel(target.kind, !!title); | ||
fillReferenceEnumerators(this.file, node, template, `${(_d = target.node.parentEnumerator) !== null && _d !== void 0 ? _d : ''}${target.node.enumerator}`, title); | ||
fillReferenceEnumerators(this.vfile, node, template, `${(_d = target.node.parentEnumerator) !== null && _d !== void 0 ? _d : ''}${target.node.enumerator}`, title); | ||
} | ||
@@ -316,22 +356,18 @@ node.resolved = true; | ||
} | ||
warnNodeTargetNotFound(node) { | ||
if (!this.file) | ||
return; | ||
fileWarn(this.file, `Cross reference target was not found: ${node.identifier}`, { | ||
node, | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetResolves, | ||
}); | ||
} | ||
} | ||
export class MultiPageReferenceState { | ||
constructor(states, filePath) { | ||
var _a; | ||
const stateItem = states.filter((v) => v.file === filePath)[0]; | ||
function warnNodeTargetNotFound(node, vfile) { | ||
if (!vfile) | ||
return; | ||
fileWarn(vfile, `Cross reference target was not found: ${node.identifier}`, { | ||
node, | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetResolves, | ||
}); | ||
} | ||
export class MultiPageReferenceResolver { | ||
constructor(states, filePath, vfile) { | ||
this.states = states; | ||
this.fileState = stateItem === null || stateItem === void 0 ? void 0 : stateItem.state; | ||
this.file = (_a = this.fileState) === null || _a === void 0 ? void 0 : _a.file; | ||
this.url = stateItem === null || stateItem === void 0 ? void 0 : stateItem.url; | ||
this.dataUrl = stateItem === null || stateItem === void 0 ? void 0 : stateItem.dataUrl; | ||
this.filePath = filePath; | ||
this.vfile = vfile; | ||
// warn on target collision across states? | ||
} | ||
@@ -341,27 +377,26 @@ resolveStateProvider(identifier, page) { | ||
return undefined; | ||
const local = this.fileState.getTarget(identifier); | ||
if (local) { | ||
return { state: this.fileState, file: this.filePath, url: this.url, dataUrl: this.dataUrl }; | ||
} | ||
const pageXRefs = this.states.find(({ state }) => !!state.getTarget(identifier)); | ||
const pageXRefs = this.states.find((state) => { | ||
if (page && page !== state.filePath) | ||
return false; | ||
return !!state.getTarget(identifier) || !!state.getFileTarget(identifier); | ||
}); | ||
return pageXRefs; | ||
} | ||
addTarget(node) { | ||
return this.fileState.addTarget(node); | ||
} | ||
initializeNumberedHeadingDepths(tree) { | ||
return this.fileState.initializeNumberedHeadingDepths(tree); | ||
} | ||
getTarget(identifier, page) { | ||
const pageXRefs = this.resolveStateProvider(identifier, page); | ||
return pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.state.getTarget(identifier); | ||
return pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.getTarget(identifier); | ||
} | ||
getFileTarget(identifier) { | ||
if (!identifier) | ||
return undefined; | ||
return this.states.map((state) => state.getFileTarget(identifier)).find((file) => !!file); | ||
} | ||
resolveReferenceContent(node) { | ||
const pageXRefs = this.resolveStateProvider(node.identifier); | ||
if (!pageXRefs) { | ||
this.fileState.warnNodeTargetNotFound(node); | ||
warnNodeTargetNotFound(node, this.vfile); | ||
return; | ||
} | ||
pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.state.resolveReferenceContent(node); | ||
if (node.resolved && (pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.file) !== this.filePath) { | ||
pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.resolveReferenceContent(node); | ||
if (node.resolved && (pageXRefs === null || pageXRefs === void 0 ? void 0 : pageXRefs.filePath) !== this.filePath) { | ||
node.remote = true; | ||
@@ -420,3 +455,3 @@ node.url = pageXRefs.url || undefined; | ||
* By default, captionNumber is only added if caption already exists. | ||
* However, for subcontainers, captionNumber is always added. | ||
* However, for sub-containers, captionNumber is always added. | ||
*/ | ||
@@ -459,4 +494,4 @@ export function addContainerCaptionNumbersTransform(tree, file, opts) { | ||
function implicitTargetWarning(target, node, opts) { | ||
if (target.node.implicit && opts.state.file) { | ||
fileWarn(opts.state.file, `Linking "${target.node.identifier}" to an implicit ${target.kind} reference, best practice is to create an explicit reference.`, { | ||
if (target.node.implicit && opts.state.vfile) { | ||
fileWarn(opts.state.vfile, `Linking "${target.node.identifier}" to an implicit ${target.kind} reference, best practice is to create an explicit reference.`, { | ||
node, | ||
@@ -476,7 +511,8 @@ note: 'Explicit references do not break when you update the title to a section, they are preferred over using the implicit HTML ID created for headers.', | ||
const target = (_a = opts.state.getTarget(identifier)) !== null && _a !== void 0 ? _a : opts.state.getTarget(reference === null || reference === void 0 ? void 0 : reference.identifier); | ||
if (!target || !reference) { | ||
if (!opts.state.file || !link.url.startsWith('#')) | ||
const fileTarget = opts.state.getFileTarget(reference === null || reference === void 0 ? void 0 : reference.identifier); | ||
if (!(target || fileTarget) || !reference) { | ||
if (!opts.state.vfile || !link.url.startsWith('#')) | ||
return; | ||
// Only warn on explicit internal URLs | ||
fileWarn(opts.state.file, `No target for internal reference "${link.url}" was found.`, { | ||
fileWarn(opts.state.vfile, `No target for internal reference "${link.url}" was found.`, { | ||
node, | ||
@@ -488,4 +524,4 @@ source: TRANSFORM_NAME, | ||
} | ||
if (!link.url.startsWith('#') && opts.state.file) { | ||
fileWarn(opts.state.file, `Legacy syntax used for link target, please prepend a '#' to your link url: "${link.url}"`, { | ||
if (!link.url.startsWith('#') && opts.state.vfile) { | ||
fileWarn(opts.state.vfile, `Legacy syntax used for link target, please prepend a '#' to your link url: "${link.url}"`, { | ||
node, | ||
@@ -508,3 +544,4 @@ note: 'The link target should be of the form `[](#target)`, including the `#` sign.\nThis may be deprecated in the future.', | ||
delete xref.url; | ||
implicitTargetWarning(target, node, opts); | ||
if (target) | ||
implicitTargetWarning(target, node, opts); | ||
}); | ||
@@ -520,6 +557,7 @@ }; | ||
const target = (_a = opts.state.getTarget(cite.label)) !== null && _a !== void 0 ? _a : opts.state.getTarget(reference === null || reference === void 0 ? void 0 : reference.identifier); | ||
if (!target || !reference) { | ||
if (!opts.state.file) | ||
const fileTarget = opts.state.getFileTarget(reference === null || reference === void 0 ? void 0 : reference.identifier); | ||
if (!(target || fileTarget) || !reference) { | ||
if (!opts.state.vfile) | ||
return; | ||
fileWarn(opts.state.file, `Could not link citation with label "${cite.label}".`, { | ||
fileWarn(opts.state.vfile, `Could not link citation with label "${cite.label}".`, { | ||
node, | ||
@@ -537,3 +575,4 @@ source: TRANSFORM_NAME, | ||
delete cite.error; | ||
implicitTargetWarning(target, node, opts); | ||
if (target) | ||
implicitTargetWarning(target, node, opts); | ||
}); | ||
@@ -540,0 +579,0 @@ }; |
import type { GenericParent } from 'myst-common'; | ||
import type { VFile } from 'vfile'; | ||
type Options = { | ||
removeYaml?: boolean; | ||
removeHeading?: boolean; | ||
/** | ||
@@ -12,2 +10,8 @@ * In many existing JupyterBooks, the first node is a label `(heading)=` | ||
propagateTargets?: boolean; | ||
/** | ||
* `preFrontmatter` overrides frontmatter from the file. It must be taken | ||
* into account this early so tile is not removed if preFrontmatter.title | ||
* is defined. | ||
*/ | ||
preFrontmatter?: Record<string, any>; | ||
}; | ||
@@ -17,4 +21,5 @@ export declare function getFrontmatter(file: VFile, tree: GenericParent, opts?: Options): { | ||
frontmatter: Record<string, any>; | ||
identifiers: string[]; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=frontmatter.d.ts.map |
import yaml from 'js-yaml'; | ||
import { remove } from 'unist-util-remove'; | ||
import { RuleId, fileError, toText } from 'myst-common'; | ||
import { select } from 'unist-util-select'; | ||
import { RuleId, fileError, toText, fileWarn, normalizeLabel } from 'myst-common'; | ||
import { mystTargetsTransform } from './targets.js'; | ||
export function getFrontmatter(file, tree, opts = { removeYaml: true, removeHeading: true, propagateTargets: true }) { | ||
var _a, _b, _c; | ||
export function getFrontmatter(file, tree, opts = { propagateTargets: true }) { | ||
var _a, _b, _c, _d; | ||
if (opts.propagateTargets) | ||
@@ -13,2 +14,3 @@ mystTargetsTransform(tree); | ||
let frontmatter = {}; | ||
const identifiers = []; | ||
const firstIsYaml = (firstNode === null || firstNode === void 0 ? void 0 : firstNode.type) === 'code' && (firstNode === null || firstNode === void 0 ? void 0 : firstNode.lang) === 'yaml'; | ||
@@ -18,4 +20,3 @@ if (firstIsYaml) { | ||
frontmatter = yaml.load(firstNode.value) || {}; | ||
if (opts.removeYaml) | ||
firstNode.type = '__delete__'; | ||
firstNode.type = '__delete__'; | ||
} | ||
@@ -29,25 +30,45 @@ catch (err) { | ||
} | ||
if (opts.preFrontmatter) { | ||
frontmatter = { ...frontmatter, ...opts.preFrontmatter }; | ||
} | ||
if (frontmatter.content_includes_title != null) { | ||
fileWarn(file, `'frontmatter' cannot explicitly set: content_includes_title`, { | ||
ruleId: RuleId.validPageFrontmatter, | ||
}); | ||
delete frontmatter.content_includes_title; | ||
} | ||
const titleNull = frontmatter.title === null; | ||
if (titleNull) | ||
delete frontmatter.title; | ||
const firstHeadingNode = select('heading', tree); | ||
// If title is not defined, copy first header to title | ||
if (!frontmatter.title && firstHeadingNode) { | ||
const title = toText(firstHeadingNode.children); | ||
frontmatter.title = title; | ||
frontmatter.content_includes_title = true; | ||
} | ||
const nextNode = firstIsYaml ? secondNode : firstNode; | ||
const nextNodeIsHeading = (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === 'heading' && nextNode.depth === 1; | ||
// Explicitly handle the case of a H1 directly after the frontmatter | ||
if (nextNodeIsHeading) { | ||
const nextNodeIsH1 = (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type) === 'heading' && nextNode.depth === 1; | ||
// Explicitly handle the case of an H1 directly after the frontmatter | ||
if (nextNodeIsH1 && !titleNull) { | ||
const title = toText(nextNode.children); | ||
// Add the title if it doesn't already exist | ||
if (!frontmatter.title) | ||
frontmatter.title = title; | ||
// Only remove the title if it is the same | ||
if (frontmatter.title && frontmatter.title === title) { | ||
if (opts.removeHeading) | ||
nextNode.type = '__delete__'; | ||
// If this has a label what do we do? Add this label as a document reference | ||
nextNode.type = '__delete__'; | ||
frontmatter.content_includes_title = false; | ||
if (nextNode.label) { | ||
const { identifier } = (_d = normalizeLabel(nextNode.label)) !== null && _d !== void 0 ? _d : {}; | ||
if (identifier) | ||
identifiers.push(identifier); | ||
} | ||
} | ||
} | ||
if (opts.removeHeading || opts.removeYaml) { | ||
// Handles deleting the block if it is the only element in the block | ||
const possibleNull = remove(tree, '__delete__'); | ||
if (possibleNull === null) { | ||
// null is returned if tree itself didn’t pass the test or is cascaded away | ||
remove(tree, { cascade: false }, '__delete__'); | ||
} | ||
// Handles deleting the block if it is the only element in the block | ||
const possibleNull = remove(tree, '__delete__'); | ||
if (possibleNull === null) { | ||
// null is returned if tree itself didn’t pass the test or is cascaded away | ||
remove(tree, { cascade: false }, '__delete__'); | ||
} | ||
return { tree, frontmatter }; | ||
return { tree, frontmatter, identifiers }; | ||
} |
@@ -5,8 +5,4 @@ import type { Plugin } from 'unified'; | ||
import type { GenericParent } from 'myst-common'; | ||
import type { IReferenceState } from './enumerate.js'; | ||
export type Options = { | ||
state: IReferenceState; | ||
}; | ||
export declare function glossaryTransform<T extends Node | GenericParent>(mdast: T, file: VFile, opts: Options): void; | ||
export declare const glossaryPlugin: Plugin<[Options], GenericParent, GenericParent>; | ||
export declare function glossaryTransform<T extends Node | GenericParent>(mdast: T, file: VFile): void; | ||
export declare const glossaryPlugin: Plugin<[], GenericParent, GenericParent>; | ||
//# sourceMappingURL=glossary.d.ts.map |
import { selectAll } from 'unist-util-select'; | ||
import { normalizeLabel, toText, fileError, RuleId } from 'myst-common'; | ||
export function glossaryTransform(mdast, file, opts) { | ||
export function glossaryTransform(mdast, file) { | ||
const glossaries = selectAll('glossary', mdast); | ||
@@ -27,4 +27,4 @@ glossaries.forEach((glossary) => { | ||
} | ||
export const glossaryPlugin = (opts) => (tree, file) => { | ||
glossaryTransform(tree, file, opts); | ||
export const glossaryPlugin = () => (tree, file) => { | ||
glossaryTransform(tree, file); | ||
}; |
@@ -21,4 +21,5 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { containerChildrenPlugin, containerChildrenTransform } from './containers.js'; | ||
export type { IReferenceState, NumberingOptions, ReferenceKind } from './enumerate.js'; | ||
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceState, } from './enumerate.js'; | ||
export { headingDepthPlugin, headingDepthTransform } from './headings.js'; | ||
export type { IReferenceStateResolver, NumberingOptions, ReferenceKind } from './enumerate.js'; | ||
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceResolver, } from './enumerate.js'; | ||
export { basicTransformationsPlugin, basicTransformations } from './basic.js'; | ||
@@ -25,0 +26,0 @@ export { unnestTransform } from './unnest.js'; |
@@ -21,3 +21,4 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { containerChildrenPlugin, containerChildrenTransform } from './containers.js'; | ||
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceState, } from './enumerate.js'; | ||
export { headingDepthPlugin, headingDepthTransform } from './headings.js'; | ||
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceResolver, } from './enumerate.js'; | ||
// Composite plugins | ||
@@ -24,0 +25,0 @@ export { basicTransformationsPlugin, basicTransformations } from './basic.js'; |
{ | ||
"name": "myst-transforms", | ||
"version": "1.1.19", | ||
"version": "1.2.0", | ||
"sideEffects": false, | ||
@@ -29,6 +29,6 @@ "type": "module", | ||
"mdast-util-find-and-replace": "^2.1.0", | ||
"myst-common": "^1.1.21", | ||
"myst-spec": "^0.0.4", | ||
"myst-spec-ext": "^1.1.21", | ||
"myst-to-html": "1.0.21", | ||
"myst-common": "^1.1.22", | ||
"myst-spec": "^0.0.5", | ||
"myst-spec-ext": "^1.1.22", | ||
"myst-to-html": "1.0.22", | ||
"rehype-parse": "^8.0.4", | ||
@@ -35,0 +35,0 @@ "rehype-remark": "^9.1.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
170391
107
3589
+ Addedmyst-to-html@1.0.22(transitive)
- Removedmyst-spec@0.0.4(transitive)
- Removedmyst-to-html@1.0.21(transitive)
Updatedmyst-common@^1.1.22
Updatedmyst-spec@^0.0.5
Updatedmyst-spec-ext@^1.1.22
Updatedmyst-to-html@1.0.22