Socket
Socket
Sign inDemoInstall

markdown-it-attrs

Package Overview
Dependencies
0
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

25

index.js

@@ -11,2 +11,11 @@ 'use strict';

for (var i = 0; i < l; ++i) {
// fenced code blocks
if (tokens[i].type === 'fence' && hasCurly(tokens[i].info)) {
var codeCurlyStart = tokens[i].info.indexOf('{');
var codeCurlyEnd = tokens[i].info.indexOf('}');
var codeAttrs = utils.getAttrs(tokens[i].info, codeCurlyStart + 1, codeCurlyEnd);
utils.addAttrs(codeAttrs, tokens[i]);
tokens[i].info = tokens[i].info.substring(0, codeCurlyStart);
continue;
}
// block tokens contain markup

@@ -58,3 +67,3 @@ // inline tokens contain the text

// attributes for blocks
if (hasCurlyEnd(tokens[i])) {
if (hasCurly(tokens[i].content)) {
var content = last(inlineTokens).content;

@@ -98,7 +107,7 @@ var curlyStart = content.lastIndexOf('{');

/**
* test if inline token has proper formated curly end
* test if string has proper formated curly
*/
function hasCurlyEnd(token) {
function hasCurly(str) {
// we need minimum four chars, example {.b}
if (!token.content || token.content.length < 4) {
if (!str || !str.length || str.length < 4) {
return false;

@@ -108,4 +117,3 @@ }

// should end in }
var content = token.content;
if (content.charAt(content.length - 1) !== '}') {
if (str.charAt(str.length - 1) !== '}') {
return false;

@@ -115,4 +123,3 @@ }

// should start with {
var curlyStart = content.indexOf('{');
if (curlyStart === -1) {
if (str.indexOf('{') === -1) {
return false;

@@ -168,2 +175,2 @@ }

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

@@ -12,2 +12,11 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.markdownItAttrs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

for (var i = 0; i < l; ++i) {
// fenced code blocks
if (tokens[i].type === 'fence' && hasCurly(tokens[i].info)) {
var codeCurlyStart = tokens[i].info.indexOf('{');
var codeCurlyEnd = tokens[i].info.indexOf('}');
var codeAttrs = utils.getAttrs(tokens[i].info, codeCurlyStart + 1, codeCurlyEnd);
utils.addAttrs(codeAttrs, tokens[i]);
tokens[i].info = tokens[i].info.substring(0, codeCurlyStart);
continue;
}
// block tokens contain markup

@@ -59,3 +68,3 @@ // inline tokens contain the text

// attributes for blocks
if (hasCurlyEnd(tokens[i])) {
if (hasCurly(tokens[i].content)) {
var content = last(inlineTokens).content;

@@ -99,7 +108,7 @@ var curlyStart = content.lastIndexOf('{');

/**
* test if inline token has proper formated curly end
* test if string has proper formated curly
*/
function hasCurlyEnd(token) {
function hasCurly(str) {
// we need minimum four chars, example {.b}
if (!token.content || token.content.length < 4) {
if (!str || !str.length || str.length < 4) {
return false;

@@ -109,4 +118,3 @@ }

// should end in }
var content = token.content;
if (content.charAt(content.length - 1) !== '}') {
if (str.charAt(str.length - 1) !== '}') {
return false;

@@ -116,4 +124,3 @@ }

// should start with {
var curlyStart = content.indexOf('{');
if (curlyStart === -1) {
if (str.indexOf('{') === -1) {
return false;

@@ -170,2 +177,3 @@ }

}
},{"./utils.js":2}],2:[function(require,module,exports){

@@ -172,0 +180,0 @@ /**

{
"name": "markdown-it-attrs",
"version": "0.3.0",
"version": "0.4.0",
"description": "Add classes, identifiers and attributes to your markdown with {} curly brackets, similar to pandoc's header attributes",

@@ -36,3 +36,3 @@ "license": "MIT",

"browserify": "^13.0.0",
"markdown-it": "^4.4.0",
"markdown-it": "^6.0.2",
"mocha": "*"

@@ -39,0 +39,0 @@ },

@@ -27,2 +27,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)

And fenced code blocks:
<pre><code>
```python {data=asdf}
nums = [x for x in range(10)]
```
</code></pre>
Output:
```html
<pre><code data="asdf" class="language-python">
nums = [x for x in range(10)]
</code></pre>
```
**Note:** Plugin does not validate any input, so you should validate the attributes in your html output if security is a concern.

@@ -29,0 +43,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc