1
0
Fork 0
A markdown-it plugin to write inline tag. https://www.npmjs.com/package/@sup39/markdown-it-inline-tag
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
Find a file
2021-01-14 19:45:25 +09:00
test consider silent 2021-01-14 19:45:25 +09:00
.eslintignore init 2021-01-12 21:57:45 +09:00
.eslintrc.js init 2021-01-12 21:57:45 +09:00
.gitignore init 2021-01-12 21:57:45 +09:00
index.js consider silent 2021-01-14 19:45:25 +09:00
LICENSE init 2021-01-12 21:57:45 +09:00
package.json consider silent 2021-01-14 19:45:25 +09:00
README.md init 2021-01-12 21:57:45 +09:00
yarn.lock init 2021-01-12 21:57:45 +09:00

markdown-it-inline

A markdown-it plugin to write inline tag.

Syntax

%tag[inline] is parsed as <tag>inline</tag>, where inline is parsed as markdown text.

Usage

const md = require('markdown-it')();
const mia = require('@sup39/markdown-it-inline-tag');

console.log(md.use(mia).render(`
1 %div[2 %span[ab] c*d*e 3] 4
`));

Expected output:

<p>1 <div>2 <span>ab</span> c<em>d</em>e 3</div> 4</p>

Alias

You can also set alias for tag.

For example,

const md = require('markdown-it')();
const mit = require('@sup39/markdown-it-inline-tag');

console.log(md.use(mit, {
  alias: {
    's': 'span',
    '@': 'div',
  },
}).render(`
1 %@[2 %s[ab] c*d*e 3] 4
`));

Expected output:

<p>1 <div>2 <span>ab</span> c<em>d</em>e 3</div> 4</p>

Extension: attributes

You can use @sup39/markdown-it-attr plugin to add attributes to inline tags.

const md = require('markdown-it')();
const mia = require('@sup39/markdown-it-attr');
const mit = require('@sup39/markdown-it-inline-tag');

console.log(md.use(mia).use(mrt).render(`
1 %div[2 %span[ab]{.a} c*d*{.b}e 3]{.c} 4
`));

Expected output:

<p>1 <div class="c">2 <span class="a">ab</span> c<em class="b">d</em>e 3</div> 4</p>

Also, you can omit %tag if there is {attrs} right after [...]. In this case, the tag name will be alias[''] or span if not assigned.

const md = require('markdown-it')();
const mia = require('@sup39/markdown-it-attr');
const mit = require('@sup39/markdown-it-inline-tag');

console.log(md.use(mia).use(mrt, {'': 'summary'}).render(`
1 [2 %span[ab]{.a} c*d*{.b}e 3]{.c} 4
`));

Expected output:

<p>1 <summary class="c">2 <span class="a">ab</span> c<em class="b">d</em>e 3</summary> 4</p>