Skip to main content
Version: 1.x.x

@yozora/tokenizer-paragraph

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

github flavor markdown spec

A sequence of non-blank lines that cannot be interpreted as other kinds of blocks forms a paragraph. The contents of the paragraph are the result of parsing the paragraph’s raw content as inlines. The paragraph’s raw content is formed by concatenating the lines and removing initial and final whitespace.

Install

npm install --save @yozora/tokenizer-paragraph

Usage

tip

@yozora/tokenizer-paragraph 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(`
aaa

bbb
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-paragraph"
prioritynumberfalseTokenizerPriority.FALLBACK
  • 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-paragraph produce Paragraph type nodes. See @yozora/ast for full base types.

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

export const ParagraphType = 'paragraph'
export type ParagraphType = typeof ParagraphType

/**
* Paragraph represents a unit of discourse dealing with a particular
* point or idea.
* @see https://github.com/syntax-tree/mdast#paragraph
* @see https://github.github.com/gfm/#paragraphs
*/
export type Paragraph = YastParent<ParagraphType>

Live Examples

  • Basic.

    #189
      
      
  • Paragraphs can contain multiple lines, but no blank lines.

    #190
      
      
  • Multiple blank lines between paragraph have no effect.

    #191
      
      
  • Leading spaces are skipped.

    #192
      
      
  • Lines after the first may be indented any amount, since indented code blocks cannot interrupt paragraphs.

    #193
      
      
  • However, the first line may be indented at most three spaces, or an indented code block will be triggered.

      
      
  • Final spaces are stripped before inline parsing, so a paragraph that ends with two or more spaces will not end with a hard line break.

    #196