Coder Social home page Coder Social logo

remark-ruby's Introduction

remark-ruby

This remark plugin parses custom Markdown syntax to produce (HTML) ruby.

It introduces a new MDAST node type: "ruby".

interface ruby <: Node {
  type: "ruby";
  base: string;
  text: string;
  data: {
    hName: "ruby";
    hChildren: [
      {
        type: 'text',
        value: string,
      },
      {
        type: 'element',
        children: [
          { type: 'text', value: string }
        ],
        tagName: 'rp',
      },
      {
        type: 'element',
        children: [
          { type: 'text', value: string }
        ],
        tagName: 'rt',
      },
      {
        type: 'element',
        children: [
          { type: 'text', value: string },
        ],
        tagName: 'rp',
      }
    ],
  },
}

Syntax

Ruby is defined in the following way:

This plugin works on {Markdown AST}^(MDAST).

This would compile to the following HTML:

<p>This plugin works on <ruby>Markdown AST<rp>(</rp><rt>MDAST</rt><rp>)</rp></p>

Text Delimitation

You could also use [] to delimit text:

{[][]}^([へん][たい])

This would compile to the following HTML:

<p><ruby><rb></rb><rb></rb><rp>(</rp><rt>へん</rt><rt>たい</rt><rp>)</rp></ruby></p>

Notice that this requires the usage of rb tag, which is not supported by most of the browsers except Firefox. Check caniuse for details.

Installation

npm:

npm install remark-ruby

Usage

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const remarkRuby = require('remark-ruby')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

Usage:

unified()
  .use(remarkParse)
  .use(remarkRuby)
  .use(remark2rehype)
  .use(stringify)

Options

options.parenthesis

Ruby fallback parenthesis which will be used in rp tag. It should be a string with at most two characters. The first will be used as left parenthesis, the last will be used as right parenthesis.

By default, it's value is ().

example

.use(remarkAbbr, { parenthesis: '「」' })

given

This plugin works on {Markdown AST}^(MDAST).

produces

<p>This plugin works on <ruby>Markdown AST<rp></rp><rt>MDAST</rt><rp></rp></p>

License

MIT © LaySent

remark-ruby's People

Contributors

dependabot[bot] avatar laysent avatar odnamrataizem avatar tburleigh avatar tombyrer avatar

Watchers

 avatar

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.