What is @types/marked?
@types/marked provides TypeScript type definitions for the 'marked' library, which is a fast, lightweight markdown parser and compiler. It allows developers to use 'marked' with TypeScript, ensuring type safety and better development experience.
What are @types/marked's main functionalities?
Basic Markdown Parsing
This feature allows you to convert a markdown string into HTML. The code sample demonstrates how to use 'marked' to parse a simple markdown string and convert it to HTML.
const marked = require('marked');
const markdownString = '# Hello World';
const htmlString = marked(markdownString);
console.log(htmlString);
Custom Renderer
This feature allows you to customize the rendering of markdown elements. The code sample shows how to create a custom renderer that changes the color of headings to red.
const marked = require('marked');
const renderer = new marked.Renderer();
renderer.heading = function (text, level) {
return `<h${level} style="color: red;">${text}</h${level}>`;
};
const markdownString = '# Hello World';
const htmlString = marked(markdownString, { renderer: renderer });
console.log(htmlString);
Synchronous and Asynchronous Parsing
This feature allows you to parse markdown both synchronously and asynchronously. The code sample demonstrates both methods of parsing a markdown string.
const marked = require('marked');
const markdownString = '# Hello World';
// Synchronous
const htmlStringSync = marked(markdownString);
console.log(htmlStringSync);
// Asynchronous
marked(markdownString, (err, htmlStringAsync) => {
if (err) throw err;
console.log(htmlStringAsync);
});
Other packages similar to @types/marked
showdown
Showdown is another markdown to HTML converter. It is similar to 'marked' in terms of functionality but offers additional features like extensions and more customization options. Showdown also has a TypeScript definition file available.
markdown-it
Markdown-it is a markdown parser that is designed to be pluggable and offers high performance. It provides more extensibility compared to 'marked' and has a rich plugin ecosystem. It also supports TypeScript through a separate type definition package.
remark
Remark is a markdown processor powered by plugins. It is highly extensible and can be used to parse, transform, and compile markdown. Remark offers more flexibility and control over the markdown processing pipeline compared to 'marked'.
Installation
npm install --save @types/marked
Summary
This package contains type definitions for Marked (https://github.com/markedjs/marked).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/marked.
Additional Details
- Last updated: Thu, 21 Oct 2021 06:31:24 GMT
- Dependencies: none
- Global values:
marked
Credits
These definitions were written by William Orr, BendingBender, CrossR, Mike Wickett, Hitomi Hatsukaze, Ezra Celli, Romain LE BARO, Sarun Intaralawan, Tony Brix, and Anatolii Titov.