Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
@atlaskit/adf-schema-generator
Advanced tools
This package provides a simple DSL (Domain Specific Language) for defining the schema, that can be transformed into multiple output formats that are required to work with ADF (Atlassian Document Format):
The package exports several functions that can be used to define the schema:
adfNode
– defines a new ADF nodeadfMark
– defines a new ADF markadfNodeGroup
– defines a new ADF node groupadfMarkGroup
– defines a new ADF mark group$or
- Create a content expression that allows any of the specified content items$onePlus
- Create a content expression that allows one or more of the specified content items$zeroPlus
- Create a content expression that allows zero or more of the specified content items$range
– Create a content expression that allows to limit number of childrenThere is quite often a need to define a slightly different version of the node. E.g.:
Variants enable this use case.
Each variant shallowly overrides the base node spec.
And then can be used via node.use('variant_name')
method.
const paragraph = adfNode('paragraph')
.define({
group: blockGroup,
content: [$zeroPlus($or(text))],
})
// Defines a variant of the node called 'with-attrs'
.variant('with-attrs', {
attrs: {
alignment: {
type: 'enum',
values: ['start', 'end', 'center', 'justify'],
default: 'start',
},
},
});
// paragraphWithAttrs now references a new instance of the ADFNode with the 'with-attrs' variant applied.
const paragraphWithAttrs = paragraph.use('with-attrs');
const name = paragraphWithAttrs.getName(); // paragraph_with-attrs_node (name includes node type and variant name)
// Both base and a variant can be used in the schema definition, even as children of the same node:
const doc = adfNode('doc').define({
root: true,
content: [$onePlus($or(paragraph, paragraphWithAttrs))],
});
// This is similar to a union type in TypeScript, where you can have a type that is either one type or another.
import {
adfNode,
adfMark,
adfNodeGroup,
$or,
$onePlus,
$zeroPlus,
} from '@atlaskit/adf-schema-generator';
const codeMark = adfMark('code').define();
const text = adfNode('text').define({
marks: [codeMark],
});
const paragraph = adfNode('paragraph')
.define({
content: [$zeroPlus($or(text))],
})
.variant('with-attrs', {
attrs: {
alignment: {
type: 'enum',
values: ['start', 'end', 'center', 'justify'],
default: 'start',
},
},
});
const blockGroup = adfNodeGroup('block', [paragraph]);
const doc = adfNode('doc').define({
root: true,
content: [$onePlus($or(blockGroup))],
});
The schema can be traversed to generate the output formats:
Traverse accepts a root node of the ADF DSL tree and a visitor object. Visitor is a pattern that is commonly used in tree traversal algorithms. It allows to separate the traversal logic from the actual processing logic.
import { traverse } from '@atlaskit/adf-schema-generator';
traverse(doc, {
node: (node, variant, children) => {
return node.type;
},
group: (group, children) => {
return group.name;
},
$or: (children) => {
return children.join(' | ');
},
});
[] TODO
[] TODO
[] TODO
@DSLCompatibilityException
: This annotation marks special cases made by transformers during DSL conversion that address temporary compatibility issues with specific target schemas. It serves as a tracking mechanism to identify, prioritize, and eliminate these exceptions as the DSL evolves to encompass these special cases.FAQs
Generates ADF and PM schemas
The npm package @atlaskit/adf-schema-generator receives a total of 204 weekly downloads. As such, @atlaskit/adf-schema-generator popularity was classified as not popular.
We found that @atlaskit/adf-schema-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.