myst-transforms
Advanced tools
Comparing version 1.1.1 to 1.1.2
import { select, selectAll } from 'unist-util-select'; | ||
import { fileError, normalizeLabel } from 'myst-common'; | ||
import { RuleId, fileError, normalizeLabel } from 'myst-common'; | ||
export function blockNestingTransform(mdast) { | ||
@@ -36,2 +36,3 @@ if (!select('block', mdast)) { | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.blockMetadataLoads, | ||
}); | ||
@@ -38,0 +39,0 @@ } |
import { selectAll } from 'unist-util-select'; | ||
import { fileWarn } from 'myst-common'; | ||
import { RuleId, fileWarn } from 'myst-common'; | ||
export function codeTransform(mdast, file, opts) { | ||
@@ -8,3 +8,6 @@ const code = selectAll('code', mdast); | ||
if (!(opts === null || opts === void 0 ? void 0 : opts.lang)) { | ||
fileWarn(file, 'Language is not defined for code block', { node }); | ||
fileWarn(file, 'Language is not defined for code block', { | ||
node, | ||
ruleId: RuleId.codeLangDefined, | ||
}); | ||
return; | ||
@@ -11,0 +14,0 @@ } |
@@ -119,2 +119,3 @@ import type { Plugin } from 'unified'; | ||
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; | ||
@@ -121,0 +122,0 @@ export declare const resolveReferencesTransform: (tree: GenericParent, file: VFile, opts: StateOptions) => void; |
import { visit } from 'unist-util-visit'; | ||
import { select, selectAll } from 'unist-util-select'; | ||
import { findAndReplace } from 'mdast-util-find-and-replace'; | ||
import { createHtmlId, fileWarn, normalizeLabel, setTextAsChild, copyNode, liftChildren, TargetKind, } from 'myst-common'; | ||
import { createHtmlId, fileWarn, normalizeLabel, setTextAsChild, copyNode, liftChildren, TargetKind, RuleId, } from 'myst-common'; | ||
const TRANSFORM_NAME = 'myst-transforms:enumerate'; | ||
@@ -85,2 +85,3 @@ function getDefaultNumberedReferenceLabel(kind) { | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTemplateFills, | ||
}); | ||
@@ -191,2 +192,3 @@ } | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.identifierIsUnique, | ||
}); | ||
@@ -280,2 +282,3 @@ return; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetResolves, | ||
}); | ||
@@ -390,2 +393,3 @@ } | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetResolves, | ||
}); | ||
@@ -399,2 +403,3 @@ return; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceSyntaxValid, | ||
}); | ||
@@ -419,2 +424,3 @@ const source = link.urlSource; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetExplicit, | ||
}); | ||
@@ -424,2 +430,28 @@ } | ||
}; | ||
export const resolveUnlinkedCitations = (tree, opts) => { | ||
selectAll('cite', tree).forEach((node) => { | ||
var _a; | ||
const cite = node; | ||
if (!cite.error) | ||
return; | ||
const reference = normalizeLabel(cite.label); | ||
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) | ||
return; | ||
fileWarn(opts.state.file, `Could not link citation with label "${cite.label}".`, { | ||
node, | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.referenceTargetResolves, | ||
}); | ||
return; | ||
} | ||
// Change the cite into a cross-reference! | ||
const xref = cite; | ||
xref.type = 'crossReference'; | ||
xref.identifier = reference.identifier; | ||
xref.label = reference.label; | ||
delete cite.error; | ||
}); | ||
}; | ||
/** Cross references cannot contain links, but should retain their content */ | ||
@@ -449,2 +481,3 @@ function unnestCrossReferencesTransform(tree) { | ||
resolveReferenceLinksTransform(tree, opts); | ||
resolveUnlinkedCitations(tree, opts); | ||
resolveCrossReferencesTransform(tree, opts); | ||
@@ -451,0 +484,0 @@ addContainerCaptionNumbersTransform(tree, file, opts); |
import { selectAll } from 'unist-util-select'; | ||
import { fileWarn } from 'myst-common'; | ||
import { RuleId, fileWarn } from 'myst-common'; | ||
function nextNumber(current, reserved) { | ||
@@ -25,2 +25,3 @@ do { | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.footnoteReferencesDefinition, | ||
}); | ||
@@ -34,2 +35,3 @@ return; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.footnoteReferencesDefinition, | ||
}); | ||
@@ -36,0 +38,0 @@ return; |
import yaml from 'js-yaml'; | ||
import { remove } from 'unist-util-remove'; | ||
import { fileError, toText } from 'myst-common'; | ||
import { RuleId, fileError, toText } from 'myst-common'; | ||
import { mystTargetsTransform } from './targets.js'; | ||
@@ -21,3 +21,6 @@ export function getFrontmatter(file, tree, opts = { removeYaml: true, removeHeading: true, propagateTargets: true }) { | ||
catch (err) { | ||
fileError(file, 'Invalid YAML frontmatter', { note: err.message }); | ||
fileError(file, 'Invalid YAML frontmatter', { | ||
note: err.message, | ||
ruleId: RuleId.frontmatterIsYaml, | ||
}); | ||
} | ||
@@ -24,0 +27,0 @@ } |
import { selectAll } from 'unist-util-select'; | ||
import { normalizeLabel, toText, fileError } from 'myst-common'; | ||
import { normalizeLabel, toText, fileError, RuleId } from 'myst-common'; | ||
export function glossaryTransform(mdast, file, opts) { | ||
@@ -11,2 +11,3 @@ const glossaries = selectAll('glossary', mdast); | ||
node: list, | ||
ruleId: RuleId.glossaryUsesDefinitionList, | ||
}); | ||
@@ -13,0 +14,0 @@ return; |
@@ -18,2 +18,3 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { abbreviationPlugin, abbreviationTransform } from './abbreviations.js'; | ||
export { includeDirectivePlugin, includeDirectiveTransform } from './include.js'; | ||
export type { IReferenceState, NumberingOptions, ReferenceKind } from './enumerate.js'; | ||
@@ -20,0 +21,0 @@ export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceState, } from './enumerate.js'; |
@@ -18,2 +18,3 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { abbreviationPlugin, abbreviationTransform } from './abbreviations.js'; | ||
export { includeDirectivePlugin, includeDirectiveTransform } from './include.js'; | ||
export { enumerateTargetsTransform, enumerateTargetsPlugin, resolveReferencesTransform, resolveReferencesPlugin, ReferenceState, MultiPageReferenceState, } from './enumerate.js'; | ||
@@ -20,0 +21,0 @@ // Composite plugins |
@@ -1,2 +0,2 @@ | ||
import { fileWarn, fileError } from 'myst-common'; | ||
import { fileWarn, fileError, RuleId } from 'myst-common'; | ||
import { map } from 'unist-util-map'; | ||
@@ -18,3 +18,3 @@ export function joinGatesTransform(tree, file) { | ||
if (child.type !== last.type) { | ||
fileWarn(file, `Gate close ("${child.type}") does not match opening gate (${child.gate}).`, { node }); | ||
fileWarn(file, `Gate close ("${child.type}") does not match opening gate (${child.gate}).`, { node, ruleId: RuleId.gatedNodesJoin }); | ||
} | ||
@@ -38,2 +38,3 @@ // Clean up the gate logic | ||
node, | ||
ruleId: RuleId.gatedNodesJoin, | ||
}); | ||
@@ -40,0 +41,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { fileError } from 'myst-common'; | ||
import { RuleId, fileError } from 'myst-common'; | ||
import { doi } from 'doi-utils'; | ||
@@ -26,2 +26,3 @@ import { updateLinkTextIfEmpty } from './utils.js'; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.doiLinkValid, | ||
}); | ||
@@ -28,0 +29,0 @@ return false; |
@@ -1,2 +0,2 @@ | ||
import { fileWarn, fileError } from 'myst-common'; | ||
import { fileWarn, fileError, RuleId } from 'myst-common'; | ||
import { updateLinkTextIfEmpty } from './utils.js'; | ||
@@ -23,2 +23,3 @@ const TRANSFORM_SOURCE = 'LinkTransform:MystTransformer'; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.mystLinkValid, | ||
}); | ||
@@ -40,2 +41,3 @@ return false; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.mystLinkValid, | ||
}); | ||
@@ -56,2 +58,3 @@ return false; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.mystLinkValid, | ||
}); | ||
@@ -58,0 +61,0 @@ return false; |
@@ -1,2 +0,2 @@ | ||
import { fileWarn } from 'myst-common'; | ||
import { RuleId, fileWarn } from 'myst-common'; | ||
import { updateLinkTextIfEmpty, withoutHttp } from './utils.js'; | ||
@@ -36,2 +36,3 @@ const RESOLVER = 'https://scicrunch.org/resolver/'; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.rridLinkValid, | ||
}); | ||
@@ -38,0 +39,0 @@ return false; |
@@ -1,2 +0,2 @@ | ||
import { fileError, fileWarn } from 'myst-common'; | ||
import { RuleId, fileError, fileWarn } from 'myst-common'; | ||
import { updateLinkTextIfEmpty, withoutHttp } from './utils.js'; | ||
@@ -50,2 +50,3 @@ const DEFAULT_LANGUAGE = 'en'; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.wikipediaLinkValid, | ||
}); | ||
@@ -60,2 +61,3 @@ return false; | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.wikipediaLinkValid, | ||
}); | ||
@@ -68,2 +70,3 @@ } | ||
source: TRANSFORM_SOURCE, | ||
ruleId: RuleId.wikipediaLinkValid, | ||
}); | ||
@@ -70,0 +73,0 @@ return false; |
import katex from 'katex'; | ||
import { selectAll } from 'unist-util-select'; | ||
import { copyNode, fileError, fileWarn, normalizeLabel } from 'myst-common'; | ||
import { RuleId, copyNode, fileError, fileWarn, normalizeLabel } from 'myst-common'; | ||
import { unnestTransform } from './unnest.js'; | ||
@@ -37,2 +37,3 @@ const TRANSFORM_NAME = 'myst-transforms:math'; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathLabelLifted, | ||
}); | ||
@@ -48,2 +49,3 @@ } | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathLabelLifted, | ||
}); | ||
@@ -68,2 +70,3 @@ } | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathEquationEnvRemoved, | ||
}); | ||
@@ -80,2 +83,3 @@ return; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathEquationEnvRemoved, | ||
}); | ||
@@ -95,2 +99,3 @@ return; | ||
url: 'http://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/latex/required/amsmath/amsldoc.pdf', | ||
ruleId: RuleId.mathEqnarrayReplaced, | ||
}); | ||
@@ -136,2 +141,3 @@ return value | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathAlignmentAdjusted, | ||
}); | ||
@@ -148,2 +154,3 @@ const next = `\\begin{align*}\n${value}\n\\end{align*}`; | ||
source: TRANSFORM_NAME, | ||
ruleId: RuleId.mathAlignmentAdjusted, | ||
}); | ||
@@ -173,2 +180,3 @@ const arrayCentering = /\\begin{array}{((?:\*\{[0-9]+\})c)}/g; | ||
fatal: true, | ||
ruleId: RuleId.mathRenders, | ||
}); | ||
@@ -187,3 +195,8 @@ node.error = true; | ||
result.warnings.forEach((message) => { | ||
fileWarn(file, message, { node, note: node.value, source: 'KaTeX' }); | ||
fileWarn(file, message, { | ||
node, | ||
note: node.value, | ||
source: 'KaTeX', | ||
ruleId: RuleId.mathRenders, | ||
}); | ||
}); | ||
@@ -206,3 +219,8 @@ } | ||
} | ||
fileError(file, result.error, { node: nodeError, note: node.value, source: 'KaTeX' }); | ||
fileError(file, result.error, { | ||
node: nodeError, | ||
note: node.value, | ||
source: 'KaTeX', | ||
ruleId: RuleId.mathRenders, | ||
}); | ||
node.error = true; | ||
@@ -209,0 +227,0 @@ node.message = result.error; |
{ | ||
"name": "myst-transforms", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"sideEffects": false, | ||
@@ -28,6 +28,6 @@ "type": "module", | ||
"mdast-util-find-and-replace": "^2.1.0", | ||
"myst-common": "^1.1.5", | ||
"myst-common": "^1.1.7", | ||
"myst-spec": "^0.0.4", | ||
"myst-spec-ext": "^1.1.5", | ||
"myst-to-html": "1.0.7", | ||
"myst-spec-ext": "^1.1.7", | ||
"myst-to-html": "1.0.8", | ||
"rehype-parse": "^8.0.4", | ||
@@ -34,0 +34,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
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
Sorry, the diff of this file is not supported yet
132701
95
2708
+ Addedmyst-to-html@1.0.8(transitive)
- Removedmyst-to-html@1.0.7(transitive)
Updatedmyst-common@^1.1.7
Updatedmyst-spec-ext@^1.1.7
Updatedmyst-to-html@1.0.8