myst-transforms
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -10,3 +10,3 @@ import { liftMystDirectivesAndRolesTransform } from './liftMystDirectivesAndRoles.js'; | ||
import { blockquoteTransform } from './blockquote.js'; | ||
import { codeBlockToDirectiveTransform } from './code.js'; | ||
import { codeBlockToDirectiveTransform, inlineCodeFlattenTransform } from './code.js'; | ||
import { removeUnicodeTransform } from './removeUnicode.js'; | ||
@@ -41,2 +41,3 @@ import { containerChildrenTransform } from './containers.js'; | ||
headingDepthTransform(tree, file, opts); | ||
inlineCodeFlattenTransform(tree, file); | ||
} | ||
@@ -43,0 +44,0 @@ export const basicTransformationsPlugin = (opts) => (tree, file) => { |
@@ -8,2 +8,6 @@ import type { Plugin } from 'unified'; | ||
}; | ||
/** | ||
* Flatten any inline code that only has text in it to a single value. | ||
*/ | ||
export declare function inlineCodeFlattenTransform(mdast: GenericParent, file: VFile): void; | ||
export declare function codeTransform(mdast: GenericParent, file: VFile, opts?: Options): void; | ||
@@ -21,3 +25,4 @@ export declare const codePlugin: Plugin<[Options?], GenericParent, GenericParent>; | ||
], GenericParent, GenericParent>; | ||
export declare const inlineCodeFlattenPlugin: Plugin<[], GenericParent, GenericParent>; | ||
export {}; | ||
//# sourceMappingURL=code.d.ts.map |
import { selectAll } from 'unist-util-select'; | ||
import { RuleId, fileWarn } from 'myst-common'; | ||
/** | ||
* Flatten any inline code that only has text in it to a single value. | ||
*/ | ||
export function inlineCodeFlattenTransform(mdast, file) { | ||
const code = selectAll('inlineCode', mdast); | ||
code.forEach((node) => { | ||
if (!(node === null || node === void 0 ? void 0 : node.children)) | ||
return; | ||
if (node.value) { | ||
fileWarn(file, 'Both children and value defined for inline code.', { | ||
node, | ||
ruleId: RuleId.inlineCodeMalformed, | ||
}); | ||
// This is a warning, but can be ignored. | ||
return; | ||
} | ||
if (!node.children.reduce((b, c) => b && c.type === 'text', true)) | ||
return; | ||
// All the children are now text nodes | ||
node.value = node.children.reduce((t, c) => t + c.value, ''); | ||
delete node.children; | ||
}); | ||
} | ||
export function codeTransform(mdast, file, opts) { | ||
@@ -44,1 +67,4 @@ const code = selectAll('code', mdast); | ||
}; | ||
export const inlineCodeFlattenPlugin = () => (tree, file) => { | ||
inlineCodeFlattenTransform(tree, file); | ||
}; |
@@ -10,3 +10,3 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { blockNestingPlugin, blockNestingTransform, blockMetadataPlugin, blockMetadataTransform, } from './blocks.js'; | ||
export { codePlugin, codeTransform } from './code.js'; | ||
export { codePlugin, codeTransform, inlineCodeFlattenPlugin, inlineCodeFlattenTransform, } from './code.js'; | ||
export { blockquotePlugin, blockquoteTransform } from './blockquote.js'; | ||
@@ -13,0 +13,0 @@ export { imageAltTextPlugin, imageAltTextTransform } from './images.js'; |
@@ -10,3 +10,3 @@ export { admonitionHeadersPlugin, admonitionHeadersTransform, admonitionBlockquotePlugin, admonitionBlockquoteTransform, } from './admonitions.js'; | ||
export { blockNestingPlugin, blockNestingTransform, blockMetadataPlugin, blockMetadataTransform, } from './blocks.js'; | ||
export { codePlugin, codeTransform } from './code.js'; | ||
export { codePlugin, codeTransform, inlineCodeFlattenPlugin, inlineCodeFlattenTransform, } from './code.js'; | ||
export { blockquotePlugin, blockquoteTransform } from './blockquote.js'; | ||
@@ -13,0 +13,0 @@ export { imageAltTextPlugin, imageAltTextTransform } from './images.js'; |
{ | ||
"name": "myst-transforms", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"sideEffects": false, | ||
@@ -29,5 +29,5 @@ "type": "module", | ||
"mdast-util-find-and-replace": "^2.1.0", | ||
"myst-common": "^1.1.25", | ||
"myst-common": "^1.1.26", | ||
"myst-spec": "^0.0.5", | ||
"myst-spec-ext": "^1.1.25", | ||
"myst-spec-ext": "^1.1.26", | ||
"myst-to-html": "1.0.22", | ||
@@ -34,0 +34,0 @@ "rehype-parse": "^8.0.4", |
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
172855
3643
Updatedmyst-common@^1.1.26
Updatedmyst-spec-ext@^1.1.26