Coder Social home page Coder Social logo

markdown-it-custom-block's Introduction

markdown-it-custom-block

Handle custom blocks transformations

Usage

const customBlock = require('markdown-it-custom-block')

markdownit()
  .use(customBlock, {
    example (arg) {
      return `<example-${arg}/>`
    },
    video (url) {
      return `<video controls>
        <source src="${url}" type="video/mp4">
      </video>`
    }
  })
@[example](hello)

@[video](video.mp4)

becomes

<example-hello/>
<video controls>
  <source src="video.mp4" type="video/mp4">
</video>

License

MIT

markdown-it-custom-block's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

markdown-it-custom-block's Issues

Cannot handle multiple occurrences

The lib cannot handle multiple occurrences of the same custom block.

Error case 1

Using the same custom block twice without separation. The lib cannot transform the blocks at all.

Used custom block

const md = markdownit().use(customBlock, {
  example (arg) {
    return `<example-${arg}/>`
  }
})

Test fixture

---
desc: Element
---

Two occurrences no separation
.
@[example](button1)
@[example](button2)
.
<example-button1/>
<example-button2/>
.

Output

  Custom Blocks
    Element
      1) Two occurrences no separation


  0 passing (42ms)
  1 failing

  1) Custom Blocks Element Two occurrences no separation:

      AssertionError: expected '<p>@<a href="button1">example</a>\n@<a href="button2">example</a></p>\n' to equal '<example-button1/>\n<example-button2/>\n'
      + expected - actual

      -<p>@<a href="button1">example</a>
      -@<a href="button2">example</a></p>
      +<example-button1/>
      +<example-button2/>

      at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:169:32)
      at Context.<anonymous> (node_modules/markdown-it-testgen/index.js:188:26)

Error case 2

Using the same custom block twice with an empty line between them. The first transform will be repeated twice.

Used custom block

const md = markdownit().use(customBlock, {
  example (arg) {
    return `<example-${arg}/>`
  }
})

Test fixture

---
desc: Element
---

Two occurrences with separation
.
@[example](button1)

@[example](button2)
.
<example-button1/>
<example-button2/>
.

Output

   Custom Blocks
    Element
      1) Two occurrences with separation


  0 passing (38ms)
  1 failing

  1) Custom Blocks Element Two occurrences with separation:

      AssertionError: expected '<example-button1/>\n<example-button1/>\n' to equal '<example-button1/>\n<example-button2/>\n'
      + expected - actual

       <example-button1/>
      -<example-button1/>
      +<example-button2/>

      at Function.assert.strictEqual (node_modules/chai/lib/chai/interface/assert.js:169:32)
      at Context.<anonymous> (node_modules/markdown-it-testgen/index.js:188:26)

Multiple template literals

Is it possible to use more than one template literal?

const customBlock = require('markdown-it-custom-block')

markdownit()
  .use(customBlock, {
    test (one, two) {
      return `<div class="one">${one}</div><div class="two">${two}</div>`
    }
  })
@[test](One),(Two)

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency mocha to ^9.1.2

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

Invalid repository url

Repo url is invalid in the package.json file -> npm repo link is wrong.

 "repository": {
    "type": "git",
    "url": "git+https://github.com/posva/vue-mdc.git"
  },

Handle adjacent blocks (no blank line)

At the moment it's necessary to add a blank line between blocks:

@[example](button1)

@[example](button2)

I'm open to contributions to make this work:

@[example](button1)
@[example](button2)

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.