Socket
Socket
Sign inDemoInstall

markdown-it-attrs

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-attrs - npm Package Compare versions

Comparing version 0.1.9 to 0.2.0

34

index.js

@@ -61,4 +61,2 @@ 'use strict';

var attrs = utils.getAttrs(content, curlyStart + 1, content.length - 1);
// some blocks are hidden, example li > paragraph_open
utils.addAttrs(attrs, firstTokenNotHidden(tokens, i - 1));
if (content[curlyStart - 1] === ' ') {

@@ -68,3 +66,17 @@ // trim space before {}

}
last(inlineTokens).content = content.slice(0, curlyStart);
// if list and `\n{#c}` -> apply to bullet list open
// `- iii \n{#c}` -> `<ul id="c"><li>iii</li></ul>`
var nextLastInline = nextLast(inlineTokens);
var possibleBulletListOpen = secondTokenNotHidden(tokens, i - 1);
if (nextLastInline && possibleBulletListOpen &&
nextLastInline.type === 'softbreak' &&
possibleBulletListOpen.type === 'bullet_list_open') {
utils.addAttrs(attrs, secondTokenNotHidden(tokens, i - 1));
// remove softbreak and {} inline tokens
tokens[i].children = inlineTokens.slice(0, -2);
} else {
// some blocks are hidden, example li > paragraph_open
utils.addAttrs(attrs, firstTokenNotHidden(tokens, i - 1));
last(inlineTokens).content = content.slice(0, curlyStart);
}
}

@@ -112,3 +124,3 @@

function firstTokenNotHidden(tokens, i) {
if (tokens[i].hidden) {
if (tokens[i] && tokens[i].hidden) {
return firstTokenNotHidden(tokens, i - 1);

@@ -120,2 +132,12 @@ }

/**
* same as firstTokenNotHidden, but sTNH([ tok1, tok2, hidden ], 2) gives tok1
*/
function secondTokenNotHidden(tokens, i) {
if (tokens[i] && tokens[i].hidden) {
return secondTokenNotHidden(tokens, i - 1);
}
return firstTokenNotHidden(tokens, i - 1);
}
/**
* find corresponding opening block

@@ -142,1 +164,5 @@ */

}
function nextLast(arr) {
return arr.slice(-2, -1)[0];
}

2

package.json
{
"name": "markdown-it-attrs",
"version": "0.1.9",
"version": "0.2.0",
"description": "Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -43,4 +43,16 @@ # 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)

If you need the class to apply to the list item instead:
If you need the class to apply to the list item instead, use a space:
```md
- list item **bold** {.red}
```
Output:
```html
<ul>
<li class="red">list item <strong>bold</strong></li>
</ul>
```
If you need the class to apply to the ul element, use a new line:
```md
- list item **bold**

@@ -52,5 +64,4 @@ {.red}

```html
<ul>
<li class="red">list item <strong>bold</strong>
</li>
<ul class="red">
<li>list item <strong>bold</strong></li>
</ul>

@@ -57,0 +68,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc