@yozora/ast
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/ast
yarn add @yozora/ast
pnpm add @yozora/ast
Core Types
YastNode
/**
* Syntactic units of the yozora AST.
* @see https://github.com/syntax-tree/unist#node
*/
export interface YastNode<T extends YastNodeType = YastNodeType> {
/**
* The variant of a node.
*/
readonly type: T
/**
* Location of a node in a source document.
* Must not be present if a node is generated.
*/
position?: YastNodePosition
}
YastParent
/**
* Nodes containing other nodes.
* @see https://github.com/syntax-tree/mdast#parent
*/
export interface YastParent<T extends YastNodeType = YastNodeType>
extends YastNode<T> {
/**
* List representing the children of a node.
*/
children: YastNode[]
}
YastLiteral
/**
* Nodes containing a value.
*/
export interface YastLiteral<T extends YastNodeType = YastNodeType>
extends YastNode<T> {
/**
* Literal value.
*/
value: string
}
YastResource
/**
* A reference to resource.
* @see https://github.com/syntax-tree/mdast#resource
*/
export interface YastResource {
/**
* A URL to the referenced resource.
*/
url: string
/**
* Advisory information for the resource, such as would be
* appropriate for a tooltip.
*/
title?: string
}
YastAssociation
/**
* An internal relation from one node to another.
* @see https://github.com/syntax-tree/mdast#association
*/
export interface YastAssociation {
/**
* It can match an identifier field on another node.
*/
identifier: string
/**
* The original value of the normalized identifier field.
*/
label: string
}
YastReference
/**
* A marker that is associated to another node.
* @see https://github.com/syntax-tree/mdast#reference
*/
export interface YastReference {
/**
* The explicitness of a reference:
* - shortcut: the reference is implicit, its identifier inferred from its content
* - collapsed: the reference is explicit, its identifier inferred from its content
* - full: the reference is explicit, its identifier explicitly set
* @see https://github.com/syntax-tree/mdast#referencetype
*/
referenceType: 'full' | 'collapsed' | 'shortcut'
}
YastAlternative
/**
* Alternative represents a node with a fallback.
* @see https://github.com/syntax-tree/mdast#alternative
*/
export interface YastAlternative {
/**
* Equivalent content for environments that cannot represent the
* node as intended.
*/
alt: string
}
YastNodePoint
/**
* One place in the source file.
* @see https://github.com/syntax-tree/unist#point
*/
export interface YastNodePoint {
/**
* Line in a source file.
* @minimum 1
*/
readonly line: number
/**
* Column column in a source file.
* @minimum 1
*/
readonly column: number
/**
* Character in a source file.
* @minimum 0
*/
readonly offset?: number
}
YastNodePosition
/**
* Location of a node in a source file.
* @see https://github.com/syntax-tree/unist#position
*/
export interface YastNodePosition {
/**
* Place of the first character of the parsed source region.
*/
start: YastNodePoint
/**
* Place of the first character after the parsed source region.
*/
end: YastNodePoint
/**
* start column at each index (plus start line) in the source region,
* for elements that span multiple lines
*/
indent?: number[]
}
YastNodeType
/**
* Variant of a node of yozora AST.
*/
export type YastNodeType = string
YastAlignType
/**
* AlignType represents how phrasing content is aligned
* @see https://github.com/syntax-tree/mdast#aligntype
*/
export type YastAlignType = 'left' | 'right' | 'center' | null
Yast nodes
Admonition
export const AdmonitionType = 'admonition'
export type AdmonitionType = typeof AdmonitionType
/**
* Admonitions are block elements. The titles can include inline markdown and
* the body can include any block markdown except another admonition.
* @see https://github.com/elviswolcott/remark-admonitions
*/
export interface Admonition extends YastParent<AdmonitionType> {
/**
* Keyword of an admonition.
*/
keyword: 'note' | 'important' | 'tip' | 'caution' | 'warning' | string
/**
* Admonition title.
*/
title: YastNode[]
}
Blockquote
export const BlockquoteType = 'blockquote'
export type BlockquoteType = typeof BlockquoteType
/**
* Blockquote represents a section quoted from somewhere else.
* @see https://github.com/syntax-tree/mdast#blockquote
* @see https://github.github.com/gfm/#block-quotes
*/
export type Blockquote = YastParent<BlockquoteType>
Break
export const BreakType = 'break'
export type BreakType = typeof BreakType
/**
* Break represents a line break, such as in poems or addresses.
* @see https://github.com/syntax-tree/mdast#break
* @see https://github.github.com/gfm/#hard-line-breaks
* @see https://github.github.com/gfm/#soft-line-breaks
*/
export type Break = YastNode<BreakType>
Code
export const CodeType = 'code'
export type CodeType = typeof CodeType
/**
* Code represents a block of preformatted text, such as ASCII art or computer
* code.
* @see https://github.com/syntax-tree/mdast#code
* @see https://github.github.com/gfm/#code-fence
*/
export interface Code extends YastLiteral<CodeType> {
/**
* Language of the codes
*/
lang?: string
/**
* Meta info string
*/
meta?: string
}
Definition
export const DefinitionType = 'definition'
export type DefinitionType = typeof DefinitionType
/**
* Definition represents a resource.
* @see https://github.com/syntax-tree/mdast#definition
* @see https://github.github.com/gfm/#link-reference-definitions
*/
export interface Definition
extends YastNode<DefinitionType>,
YastAssociation,
YastResource {}
Delete
export const DeleteType = 'delete'
export type DeleteType = typeof DeleteType
/**
* Delete represents contents that are no longer accurate or no longer relevant.
* @see https://github.com/syntax-tree/mdast#delete
* @see https://github.github.com/gfm/#strikethrough-extension-
*/
export type Delete = YastParent<DeleteType>
EcmaImport
export const EcmaImportType = 'ecmaImport'
export type EcmaImportType = typeof EcmaImportType
export interface EcmaImport extends Node<EcmaImportType> {
/**
* import Parser from '@yozora/parser'
* ==> { moduleName: '@yozora/parser' }
*/
moduleName: string
/**
* import Parser, { YozoraParserProps } from '@yozora/parser'
* ==> { defaultImport: 'Parser' }
*/
defaultImport: string | null
/**
* import { YozoraParserProps, YozoraParser as Parser } from '@yozora/parser'
* ==> {
* namedImports: [
* { src: 'YozoraParserProps', alias: null },
* { src: 'YozoraParser', alias: 'Parser' },
* ]
* }
*/
namedImports: IEcmaImportNamedImport[]
}
/**
*
* import { YozoraParserProps, YozoraParser as Parser } from '@yozora/parser'
* ==> [
* { src: 'YozoraParserProps', alias: null },
* { src: 'YozoraParser', alias: 'Parser' },
* ]
*/
export interface IEcmaImportNamedImport {
/**
*
*/
src: string
/**
*
*/
alias: string | null
}
Emphasis
export const EmphasisType = 'emphasis'
export type EmphasisType = typeof EmphasisType
/**
* Emphasis represents stress emphasis of its contents.
* @see https://github.com/syntax-tree/mdast#emphasis
* @see https://github.github.com/gfm/#emphasis-and-strong-emphasis
*/
export type Emphasis = YastParent<EmphasisType>
FootnoteDefinition
export const FootnoteDefinitionType = 'footnoteDefinition'
export type FootnoteDefinitionType = typeof FootnoteDefinitionType
/**
* FootnoteDefinition represents content relating to the document that is
* outside its flow.
* @see https://github.com/syntax-tree/mdast#footnotedefinition
*/
export interface FootnoteDefinition
extends YastParent<FootnoteDefinitionType>, YastAssociation {}