@yozora/tokenizer-thematic-break
A line consisting of spaces of indentation, followed by a sequence of
three or more matching -
, _
, or *
characters, each followed optionally by
any number of spaces or tabs, forms a thematic break.
- See github flavor markdown spec for details.
- See Live Examples for an intuitive impression.
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-thematic-break
yarn add @yozora/tokenizer-thematic-break
pnpm add @yozora/tokenizer-thematic-break
Usage
@yozora/tokenizer-thematic-break has been integrated into @yozora/parser / @yozora/parser-gfm-ex / @yozora/parser-gfm,
so you can use YozoraParser
/ GfmExParser
/ GfmParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-thematic-break cannot be used alone, it needs to be registered in Parser as a plugin-in before it can be used.
import { DefaultParser } from '@yozora/core-parser'
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
import TextTokenizer from '@yozora/tokenizer-text'
import ThematicBreakTokenizer from '@yozora/tokenizer-thematic-break'
const parser = new DefaultParser()
.useFallbackTokenizer(new ParagraphTokenizer())
.useFallbackTokenizer(new TextTokenizer())
.useTokenizer(new ThematicBreakTokenizer())
// parse source markdown content
parser.parse(`
***
---
___
`)
import YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
// parse source markdown content
parser.parse(`
***
---
___
`)
import GfmParser from '@yozora/parser-gfm'
const parser = new GfmParser()
// parse source markdown content
parser.parse(`
***
---
___
`)
import GfmExParser from '@yozora/parser-gfm-ex'
const parser = new GfmExParser()
// parse source markdown content
parser.parse(`
***
---
___
`)
Options
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-thematic-break" |
priority | number | false | TokenizerPriority.ATOMIC |
-
name
: The unique name of the tokenizer, used to bind the token it generates, to determine the tokenizer that should be called in each life cycle of the token in the entire matching / parsing phase. -
priority
: Priority of the tokenizer, determine the order of processing, high priority priority execution. interruptable. In addition, in thematch-block
stage, a high-priority tokenizer can interrupt the matching process of a low-priority tokenizer.
Types
@yozora/tokenizer-thematic-break produce ThematicBreak type nodes. See @yozora/ast for full base types.
import type { Node } from '@yozora/ast'
export const ThematicBreakType = 'thematicBreak'
export type ThematicBreakType = typeof ThematicBreakType
/**
* ThematicBreak represents a thematic break, such as a scene change in
* a story, a transition to another topic, or a new document.
* @see https://github.com/syntax-tree/mdast#thematicbreak
* @see https://github.github.com/gfm/#thematic-break
*/
export type ThematicBreak = Node<ThematicBreakType>
Live Examples
-
Basic.
-
Wrong characters.
-
Not enough characters.
-
One to three spaces indent are allowed.
-
Four spaces is too many
-
More than three characters may be used.
-
Spaces are allowed between the characters.
-
Spaces are allowed at the end.
-
However, no other characters may occur in the line.
-
It is required that all of the non-whitespace characters be the same. So, this is not a thematic break.
-
Thematic breaks do not need blank lines before or after.
-
If a line of dashes that meets the above conditions for being a thematic break could also be interpreted as the underline of a setext heading, the interpretation as a setext heading takes precedence. Thus, for example, this is a setext heading, not a paragraph followed by a thematic break.
-
When both a thematic break and a list item are possible interpretations of a line, the thematic break takes precedence.
-
If you want a thematic break in a list item, use a different bullet.