GithubHelp home page GithubHelp logo

mdbox's Introduction

⬇ mdbox

npm version npm downloads bundle size

Just simple markdown utils!

Important

This project is under development.

💡 Why?

Markdown is intended to be as easy-to-read and easy-to-write as is. Readability is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text [^1]. Any sequence of characters is a valid Markdown document [^2].

While Markdown is designed to be simple, I often find myself in situations where there is simply no tool to allow programmatically working with Markdown syntax without dealing with complex and strict AST objects and choosing between dozens of available tools and extensions. Often, not even worth pursuing ideas around Markdown.

The idea is to make good-enough tools to read and write Markdown programmatically, as easy as Markdown itself is, without dealing with an AST.

Usage

Install package:

# npm
npm install mdbox

# yarn
yarn add mdbox

# pnpm
pnpm install mdbox

# bun
bun install mdbox

Import:

// ESM
import { md } from "mdbox";

// CommonJS
const { md } = require("mdbox");

Render Utils

blockquote(text)

Render a markdown blockquote text with > in front of a paragraph

Example:

md.blockquote("Hello, World!");
// => "> Hello, World!"

bold(text)

Render a markdown bold text.

Example:

md.bold("Hello, World!");
// => "**Hello, World!**"

boldAndItalic(text)

Render a markdown bold and italic text.

Example:

md.boldAndItalic("Hello, World!");
// => "***Hello, World!***"

codeBlock(code, lang?, opts?: { ext? })

Format a string as a code block.

Example:

md.codeBlock('console.log("Hello, World!");', "js");
// => "```js\nconsole.log("Hello, World!");\n```"

heading(text, level)

Render a markdown heading.

Example:

md.heading("Hello, World!", 1);
// => "\n# Hello, World!\n"

hr(length)

Render a markdown horizontal rule.

Example:

md.hr();
// => "---"

image(url, text?, opts?: { title? })

Render a markdown image.

Example:

md.image("https://cataas.com/cat", "Cute Cat");
// => "![Cute Cat](https://cataas.com/cat)"

italic(text)

Render a markdown italic text.

Example:

md.italic("Hello, World!");
// => "_Hello, World!_"

link(url, text?, opts?: { title?, external? })

Render a markdown link.

Example:

md.link("https://www.google.com", "Google");
// => "[Google](https://www.google.com)"
md.link("https://www.google.com", "Google", { external: true });
// => "<a href="https://www.google.com" title="Google" target="_blank">Google</a>"

list(items, opts: { ordered?, char? })

Render a markdown ordered or unordered list.

Example:

md.list(["Item 1", "Item 2", "Item 3"]);
// => "- Item 1\n- Item 2\n- Item 3"
md.list(["Item 1", "Item 2", "Item 3"], { ordered: true });
// => "1. Item 1\n2. Item 2\n3. Item 3"

strikethrough(text)

Render a markdown strikethrough text.

Example:

md.strikethrough("Hello, World!");
// => "~~Hello, World!~~"

table(table: { rows[][], columns[] })

Render a markdown table.

Example:

md.table({
 columns: ["Breed", "Origin", "Size", "Temperament"],
 rows: [
   ["Abyssinian", "Egypt", "Medium", "Active"],
   ["Aegean", "Greece", "Medium", "Active"],
   ["American Bobtail", "United States", "Medium", "Active"],
   ["Applehead Siamese", "Thailand", "Medium", "Active"],
  ],
});

Parsing Utils

initMarkdownItParser(options)

Create parser with markdown-it.

WARNING: The returned tree structure is unstable.

Example:

import { initMarkdownItParser } from "mdbox/parser";
const parser = await initMarkdownItParser();
const { tree } = parser.parse("# Hello, *world*!");

initMd4wParser(opts)

Create parser with md4w.

WARNING: The returned tree structure is unstable.

Example:

import { initMd4wParser } from "mdbox/parser";
const parser = await initMd4wParser();
const { tree } = parser.parse("# Hello, *world*!");

initMdAstParser(opts)

Create parser with mdast-util-from-markdown.

WARNING: The returned tree structure is unstable.

Example:

import { initMdAstParser } from "mdbox/parser";
const parser = await initMdAstParser();
const { tree } = parser.parse("# Hello, *world*!");

Contribution

Local development
  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run tests using pnpm dev or pnpm test

License

Published under the MIT license. Made by @pi0 and community 💛


🤖 auto updated with automd

mdbox's People

Contributors

pi0 avatar renovate[bot] avatar mahdikhashan avatar uncenter avatar chilfish avatar cpreston321 avatar autofix-ci[bot] avatar docxml avatar

Stargazers

Yuki Ito avatar Pato avatar Sean LeCheminant avatar John Owen Nixon avatar Nazar Kornienko avatar Jeanne Mas avatar Viki avatar Yann-Thomas LE MOIGNE avatar Askar Yusupov avatar Robert McGuinness avatar George Kontridze avatar Sam Carlton avatar Riccardo avatar Nikhil Reddy avatar Lucas Schuster avatar Lucas Schuster avatar Henrik Wenz avatar Adama KO avatar Whipstickgostop avatar ntnyq avatar Nirmalya Ghosh avatar HG avatar Anton Ödman avatar Dmitriy Brolnickij avatar gangan avatar Dee Cheung avatar Simone Gosetto avatar Tyler Davis Mitchell avatar Sam Mason de Caires avatar Shashi Kumar Nagulakonda avatar Yoones Khoshghadam avatar Lawrence Onah avatar  avatar Sandro Circi avatar  avatar Eva1ent avatar Alban avatar Jan Fröhlich avatar akshay kadam (a2k) avatar  avatar Samuel Burkhard avatar Pionxzh avatar Alex Duval avatar JD Solanki avatar Okiki Ojo avatar Takuya Fukuju avatar Bian Pratama avatar  avatar Emmanuel Salomon avatar Otis Sutton avatar Divine avatar  avatar taaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassssssssssssssssssssssssssssssssssssssssssssssssssssky avatar Meyti avatar  avatar Michael Demarais avatar horlar avatar Florian Lefebvre avatar Jero Soler avatar Robert Soriano avatar  avatar João Palmeiro avatar Steven John avatar zernonia avatar Maxime avatar Hung Hoang avatar Marr-cloud avatar  avatar Georges KABBOUCHI avatar Sylvain avatar henrycunh avatar kernoeb avatar  avatar Estéban avatar Sigve Hansen avatar Sébastien Chopin avatar Marcos Viana avatar Teena avatar Corentin THOMASSET avatar

Watchers

X. avatar  avatar  avatar

mdbox's Issues

Fix JSDoc comments to match params

Describe the change

Some jsdoc comments do not match or missing params so I will create a PR to fix this.

URLs

No response

Additional information

  • Would you be willing to help?

Support MyST Markdown parser

Describe the feature

MyST Markdown is a flavor of markdown meant for scientific and technical documentation. Extending mdbox to support MyST Markdown would allow to create easier themes for MyST Markdown and help facilitate scientific communcations

Additional information

  • Would you be willing to help implement this feature?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/autofix.yml
  • actions/checkout v4
  • actions/setup-node v4
  • autofix-ci/action ea32e3a12414e6d3183163c3424a7d7a8631ad84
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v4
npm
package.json
  • md4w ^0.2.4
  • @types/markdown-it ^13.0.7
  • @types/mdast ^4.0.3
  • @types/node ^20.11.24
  • @vitest/coverage-v8 ^1.3.1
  • automd ^0.3.6
  • changelogen ^0.5.5
  • esbuild ^0.20.1
  • eslint ^8.57.0
  • eslint-config-unjs ^0.2.1
  • jiti ^1.21.0
  • markdown-it ^14.0.0
  • mdast-util-from-markdown ^2.0.0
  • mdast-util-gfm ^3.0.0
  • micromark-extension-gfm ^3.0.0
  • mitata ^0.1.11
  • ohash ^1.1.3
  • prettier ^3.2.5
  • punycode.js ^2.3.1
  • typescript ^5.3.3
  • unbuild ^2.0.0
  • vite-tsconfig-paths ^4.3.1
  • vitest ^1.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.