@diplodoc/transform
TypeScript icon, indicating that this package has built-in type declarations

4.14.2 • Public • Published

english | русский


NPM version

@diplodoc/transform is a package for converting Yandex Flavored Markdown to HTML.

Use it in your code to work with text during program execution. For example, to display user-generated content.

Installation {#install}

  1. Install a package:

    npm i @diplodoc/transform
  2. Add the package in your code using the require() or import() function:

    const transform = require('@diplodoc/transform');
  3. To ensure text is displayed properly, add CSS styles and client scripts to the project:

    @import '~@diplodoc/transform/dist/css/yfm.css';
    import '@diplodoc/transform/dist/js/yfm';

Usage {#use}

The package provides the transform() function:

  • Input data: Settings and a string with YFM.
  • Returned value: An object with the result and logs fields.

Result field

result: Resulting object, contains the fields:

  • html: A line with HTML.
  • meta: Metadata from the transmitted content.
  • title: The document title. Returned if extractTitle = true or needTitle = true.
  • headings: A list of document headers.

Logs field

logs: Information about the transformation process, includes arrays:

  • error: Errors.
  • warn: Warnings.
  • info: Additional information.

Example of a function invocation

const fs = require('fs');
const transform = require('@diplodoc/transform');

const content = fs.readFileSync(filePath, 'utf');
const vars = { user: { name: 'Alice' } };

const {
    result: {html, meta, title, headings},
    logs,
    } = transform(content, {vars});

License

MIT

Package Sidebar

Install

npm i @diplodoc/transform

Weekly Downloads

963

Version

4.14.2

License

MIT

Unpacked Size

907 kB

Total Files

365

Last publish

Collaborators

  • yndx-birman111
  • martyanov-av
  • vsesh
  • rndnm
  • v8tenko
  • moki
  • 3y3
  • alexey_w100
  • robot-dataui-npm