Options
All
  • Public
  • Public/Protected
  • All
Menu

@stoplight/markdown

Maintainability Test Coverage

Useful functions when working with Markdown. Leverages the Unified / Remark ecosystem under the hood.

Installation

Supported in modern browsers and node.

# latest stable
yarn add @stoplight/markdown

Usage

Example parseWithPointers

Note: Unlike most of the other functions, parseWithPointers is not exported from root. You must import by name.

import { parseWithPointers } from "@stoplight/markdown/parseWithPointers";

const result = parseWithPointers("**markdown**");

console.log(result.data); // => the MDAST compliant tree

Contributing

  1. Clone repo.
  2. Create / checkout feature/{name}, chore/{name}, or fix/{name} branch.
  3. Install deps: yarn.
  4. Make your changes.
  5. Run tests: yarn test.prod.
  6. Stage relevant files to git.
  7. Commit: yarn commit. NOTE: Commits that don't follow the conventional format will be rejected. yarn commit creates this format for you, or you can put it together manually and then do a regular git commit.
  8. Push: git push.
  9. Open PR targeting the develop branch.

Index

Type aliases

AlignType

AlignType: "left" | "right" | "center" | null

AnnotationType

AnnotationType: "tab" | "tab-end"

ElementTagNameType

ElementTagNameType: "div" | "span"

MarkdownParserResult

MarkdownParserResult: IParserResult<Parent, Parent>

PropertyPath

PropertyPath: PropertyKey | PropertyKey[]

ReferenceType

ReferenceType: "shortcut" | "collapsed" | "full"

ThemeType

ThemeType: "info" | "warning" | "danger" | "success"

Functions

default

  • default(this: Processor): void

Const fromSpec

Const getJsonPathForNode

  • getJsonPathForNode(root: Parent, node: Node): JsonPath | void

Const getJsonPathForPosition

  • getJsonPathForPosition(__namedParameters: object, position: IPosition): (string | number)[]

Const getLocationForJsonPath

  • getLocationForJsonPath(__namedParameters: object, path: JsonPath): undefined | object

Const getProperty

  • getProperty(propName: string, element: undefined | string, data: Unist.Node): undefined | string | void
  • Parameters

    • propName: string
    • Optional element: undefined | string
    • Optional data: Unist.Node

    Returns undefined | string | void

Const getSummary

  • getSummary(data: Unist.Node, opts?: IGetSummaryOpts): undefined | string | void

Const getTags

  • getTags(data: Unist.Node): string[]

Const getTitle

  • getTitle(data: Unist.Node): undefined | string | void

Const parse

  • parse(input: string, opts?: Partial<RemarkParseOptions>, processor?: Processor): Node
  • Parameters

    • input: string
    • Default value opts: Partial<RemarkParseOptions> = defaultOpts
    • Default value processor: Processor = defaultProcessor

    Returns Node

Const parseWithPointers

  • parseWithPointers(value: string, opts: Partial<RemarkParseOptions>, processor: unified.Processor): MarkdownParserResult

Const stringify

  • stringify(tree: Node, opts?: Partial<RemarkStringifyOptions>, processor?: Processor): string
  • Parameters

    • tree: Node
    • Default value opts: Partial<RemarkStringifyOptions> = defaultOpts
    • Default value processor: Processor = defaultProcessor

    Returns string

Const toSpec