Skip to main content
Version: 1.x.x

@yozora/tokenizer-thematic-break

Npm VersionNpm DownloadNpm LicenseModule formats: cjs, esmNode.js VersionTested with JestCode Style: prettier

github flavor markdown spec

A line consisting of 030-3 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.

Install

npm install --save @yozora/tokenizer-thematic-break

Usage

tip

@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.

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
parser.parse(`
***
---
___
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-thematic-break"
prioritynumberfalseTokenizerPriority.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 the match-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 { YastNode } 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 = YastNode<ThematicBreakType>

Live Examples

  • Basic.

    #13
      
      
  • Wrong characters.

      
      
  • Not enough characters.

    #16
      
      
  • One to three spaces indent are allowed.

    #17
      
      
  • Four spaces is too many

      
      
  • More than three characters may be used.

    #20
      
      
  • Spaces are allowed between the characters.

      
      
  • Spaces are allowed at the end.

    #24
      
      
  • However, no other characters may occur in the line.

    #25
      
      
  • It is required that all of the non-whitespace characters be the same. So, this is not a thematic break.

    #26
      
      
  • Thematic breaks do not need blank lines before or after.

    #27
      
      
  • 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.

    #28
      
      
  • When both a thematic break and a list item are possible interpretations of a line, the thematic break takes precedence.

    #29
      
      
  • If you want a thematic break in a list item, use a different bullet.

    #30