Skip to main content
Version: 2.x.x

@yozora/tokenizer-break

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

github flavor markdown spec

Hard line breaks

A line break (not in a code span or HTML tag) that is preceded by two or more spaces and does not occur at the end of a block is parsed as a hard line break (rendered in HTML as a <br /> tag).

Soft line breaks

A regular line break (not in a code span or HTML tag) that is not preceded by two or more spaces or a backslash is parsed as a [softbreak]gfm-softbreak. (A softbreak may be rendered in HTML either as a line ending or as a space. The result will be the same in browsers. In the examples here, a line ending will be used.)

Install

npm install --save @yozora/tokenizer-break

Usage

tip

@yozora/tokenizer-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(`
foo
baz

foo\
baz

foo
baz
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-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.

    Exception: Delimiters of type full are always processed before other type delimiters.

Types

@yozora/tokenizer-break produce Break type nodes. See @yozora/ast for full base types.

import type { Node } from '@yozora/ast'

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 = Node<BreakType>

Live Examples

Hard line breaks

  • Basic.

    #654
      
      
  • For a more visible alternative, a backslash before the line ending may be used instead of two spaces.

    #655
      
      
  • More than two spaces can be used.

    #656
      
      
  • Leading spaces at the beginning of the next line are ignored.

      
      
  • Line breaks can occur inside emphasis, links, and other constructs that allow inline content.

      
      
  • Line breaks do not occur inside code spans or or HTML tags.

      
      
  • Hard line breaks are for separating inline content within a block. Neither syntax for hard line breaks works at the end of a paragraph or other block element.

      
      

Soft line breaks

  • Basic.

    #669
      
      
  • Spaces at the end of the line and beginning of the next line are removed.

    #670