Socket
Book a DemoInstallSign in
Socket

@inyur/markdown-to-html

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inyur/markdown-to-html

```bash npm i -S @inyur/markdown-to-html ```

1.0.5
latest
npmnpm
Version published
Maintainers
1
Created
Source

@inyur/markdown-to-html

Install

npm i -S @inyur/markdown-to-html

Usage

import md2html from '@inyur/markdown-to-html';

// Variant 1
const someMdFileContent = require('fs').readFileSync('./some.md', 'utf8');
const html = await md2html(someMdFileContent);

// Variant 2
// Internaly md2html has promise resolver if promise found and 
// has object default getter.
const someMdFileContentPromised = import('./some.md')
  .then(module=> module.defult);
const html = await md2html(someMdFileContentPromised);
// Or This simplified works too
const someMdFileContentPromised = import('./some.md');
const html = await md2html(someMdFileContentPromised);
// Or This simplified works too
const html = await md2html(import('./some.md'));

In general cases markdown-to-html return html string, except this called with special parameter extended

Advanced usage:


const options = {
}

const html = await md2html('Md text or promise or esmodule', options);

options

this is object of some props (see next)

Can be Array of (Objects of Strings or Functions) Can be Array of Functions Can be Object of Strings or Functions Can be Function

const options = {
  links: [{
    alfaUrl: 'https://alfa.net',
    betaUrl: (url, node) => {
      if (url.host !== 'internal.site') {
        node.properties.target = '_blank'
      }
      return 'https://beta.com'
    },
  }]
}

options.variables

Can be Object

const options = {
  variables: {
    someTextVariable: 'Some Value'
  }
}
const html = await md2html('Md text ${someTextVariable}', options);

options.extended

markdown-to-html return Object of:

const {
  markdown, // initial markdown source
  title, // returns if splitTitle prop is true
  template, // Handlebars template, useful for reuse template
  html, // Compiled template as === template(variables)
  data, // Returned data from frontMatter
  headings, // Returned H1-6 structure
  toString, // Function for usage as text === toString() { return  template(variables); }
} = await md2html('Md text or promise or esmodule', options);

options.splitTitle

Boolean, default false In extended version returned object with html without title and title prop.

FAQs

Package last updated on 20 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.