markdown-it-attrs-dsl
v0.1.0
Published
Markdown-it plugin that extends markdown-it-attrs with a shorthand style DSL.
Downloads
8
Maintainers
Readme
markdown-it-attrs-dsl
Adds a concise style-attribute DSL on top of markdown-it-attrs, e.g. {w:50} or {mt:8}.
These DSL attributes are converted into style and removed from the final HTML attributes.
Install
npm i markdown-it markdown-it-attrs markdown-it-attrs-dslUsage
import attrs from 'markdown-it-attrs-dsl'
const md = new MarkdownIt()
.use(attrs)
const html = md.render('{ w:300 h:200 f:right scale:0.5 }')DSL Rules
w/h: width/height. Addspxby default, e.g.w:50=>width: 50px. If a percentage is used, setsmax-width/max-heightand makeswidth/heightauto.trbl: maps totop/right/bottom/left.mtmrmbml: maps tomargin-*.ptprpbpl: maps topadding-*.float:r/right=>right,l/left=>left, otherwisenone.pos: maps toposition.fit: maps toobject-fit.z: maps toz-index.op: maps toopacity.scale: appendstransform: scale(x)and setstransform-origin: top left.rot: appendstransform: rotate(xdeg).
Examples
{w:50 h:40}
{w:50% h:50%}
{float:r mt:8 ml:12}Notes
- The shorthand form
w:50is equivalent tow="50". - Currently, the DSL is only applied to image (
img) elements.
