New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mdast

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

129

lib/stringify.js

@@ -18,6 +18,8 @@ 'use strict';

var EXPRESSION_ESCAPE,
EXPRESSION_DIGIT;
EXPRESSION_DIGIT,
EXPRESSION_TRAILING_NEW_LINES;
EXPRESSION_ESCAPE = /[\\`*{}\[\]()#+\-._>]/g;
EXPRESSION_DIGIT = /\d/;
EXPRESSION_TRAILING_NEW_LINES = /\n+$/g;

@@ -184,7 +186,7 @@ /*

currentCount++;
} else {
if (currentCount > highestCount) {
highestCount = currentCount;
}
} else {
currentCount = 0;

@@ -245,9 +247,9 @@ }

bullet,
horizontalRule,
horizontalRuleSpaces,
horizontalRuleRepetition,
preferSetextHeadings,
preferReferenceLinks,
preferReferenceFootnotes,
preferFences,
rule,
ruleSpaces,
ruleRepetition,
setext,
referenceLinks,
referenceFootnotes,
fences,
emphasis,

@@ -269,9 +271,9 @@ strong;

bullet = options.bullet;
horizontalRule = options.horizontalRule;
horizontalRuleSpaces = options.horizontalRuleSpaces;
horizontalRuleRepetition = options.horizontalRuleRepetition;
preferSetextHeadings = options.preferSetextHeadings;
preferReferenceLinks = options.preferReferenceLinks;
preferReferenceFootnotes = options.preferReferenceFootnotes;
preferFences = options.preferFences;
rule = options.rule;
ruleSpaces = options.ruleSpaces;
ruleRepetition = options.ruleRepetition;
setext = options.setext;
referenceLinks = options.referenceLinks;
referenceFootnotes = options.referenceFootnotes;
fences = options.fences;
emphasis = options.emphasis;

@@ -286,12 +288,12 @@ strong = options.strong;

if (!horizontalRule) {
options.horizontalRule = ASTERISK;
} else if (!(horizontalRule in HORIZONTAL_RULE_BULLETS)) {
raise(horizontalRule, 'options.horizontalRule');
if (!rule) {
options.rule = ASTERISK;
} else if (!(rule in HORIZONTAL_RULE_BULLETS)) {
raise(rule, 'options.rule');
}
if (horizontalRuleSpaces === null || horizontalRuleSpaces === undefined) {
options.horizontalRuleSpaces = true;
} else if (typeof horizontalRuleSpaces !== 'boolean') {
raise(horizontalRuleSpaces, 'options.horizontalRuleSpaces');
if (ruleSpaces === null || ruleSpaces === undefined) {
options.ruleSpaces = true;
} else if (typeof ruleSpaces !== 'boolean') {
raise(ruleSpaces, 'options.ruleSpaces');
}

@@ -311,40 +313,37 @@

if (preferSetextHeadings === null || preferSetextHeadings === undefined) {
options.preferSetextHeadings = false;
} else if (typeof preferSetextHeadings !== 'boolean') {
raise(preferSetextHeadings, 'options.preferSetextHeadings');
if (setext === null || setext === undefined) {
options.setext = false;
} else if (typeof setext !== 'boolean') {
raise(setext, 'options.setext');
}
if (preferReferenceLinks === null || preferReferenceLinks === undefined) {
options.preferReferenceLinks = false;
} else if (typeof preferReferenceLinks !== 'boolean') {
raise(preferReferenceLinks, 'options.preferReferenceLinks');
if (referenceLinks === null || referenceLinks === undefined) {
options.referenceLinks = false;
} else if (typeof referenceLinks !== 'boolean') {
raise(referenceLinks, 'options.referenceLinks');
}
if (
preferReferenceFootnotes === null ||
preferReferenceFootnotes === undefined
) {
options.preferReferenceFootnotes = true;
} else if (typeof preferReferenceFootnotes !== 'boolean') {
raise(preferReferenceFootnotes, 'options.preferReferenceFootnotes');
if (referenceFootnotes === null || referenceFootnotes === undefined) {
options.referenceFootnotes = true;
} else if (typeof referenceFootnotes !== 'boolean') {
raise(referenceFootnotes, 'options.referenceFootnotes');
}
if (preferFences === null || preferFences === undefined) {
options.preferFences = false;
} else if (typeof preferFences !== 'boolean') {
raise(preferFences, 'options.preferFences');
if (fences === null || fences === undefined) {
options.fences = false;
} else if (typeof fences !== 'boolean') {
raise(fences, 'options.fences');
}
if (
horizontalRuleRepetition === null ||
horizontalRuleRepetition === undefined
ruleRepetition === null ||
ruleRepetition === undefined
) {
options.horizontalRuleRepetition = 3;
options.ruleRepetition = 3;
} else if (
typeof horizontalRuleRepetition !== 'number' ||
horizontalRuleRepetition < 3 ||
horizontalRuleRepetition !== horizontalRuleRepetition
typeof ruleRepetition !== 'number' ||
ruleRepetition < 3 ||
ruleRepetition !== ruleRepetition
) {
raise(horizontalRuleRepetition, 'options.horizontalRuleRepetition');
raise(ruleRepetition, 'options.ruleRepetition');
}

@@ -540,7 +539,7 @@

compilerPrototype.heading = function (token, parent, level) {
var preferSetextHeadings,
var setext,
depth,
content;
preferSetextHeadings = this.options.preferSetextHeadings;
setext = this.options.setext;

@@ -551,9 +550,3 @@ depth = token.depth;

if (
preferSetextHeadings &&
(
depth === 1 ||
depth === 2
)
) {
if (setext && (depth === 1 || depth === 2)) {
return content + LINE +

@@ -636,3 +629,3 @@ repeat(content.length, depth === 1 ? EQUALS : DASH);

if (self.options.preferReferenceLinks) {
if (self.options.referenceLinks) {
value += SQUARE_BRACKET_OPEN + (++self.linkCounter) +

@@ -723,3 +716,3 @@ SQUARE_BRACKET_CLOSE;

ticks = repeat(getLongestRepetition(value, TICK) + 2, TICK);
ticks = repeat(getLongestRepetition(value, TICK) + 1, TICK);

@@ -756,3 +749,3 @@ start = ticks;

if (!token.lang && !this.options.preferFences) {
if (!token.lang && !this.options.fences) {
return pad(value, 1);

@@ -788,5 +781,5 @@ }

rule = repeat(options.horizontalRuleRepetition, options.horizontalRule);
rule = repeat(options.ruleRepetition, options.rule);
if (options.horizontalRuleSpaces) {
if (options.ruleSpaces) {
rule = rule.split(EMPTY).join(SPACE);

@@ -892,3 +885,3 @@ }

/*
* Check if the user prefers inline footnotes.
* Check if the user s inline footnotes.
* But, only expose footnotes inline when the

@@ -899,3 +892,3 @@ * footnote contains just one paragraph.

if (
this.options.preferReferenceFootnotes ||
this.options.referenceFootnotes ||
footnote.length !== 1 ||

@@ -1056,5 +1049,5 @@ footnote[0].type !== 'paragraph'

return value;
return value.replace(EXPRESSION_TRAILING_NEW_LINES, LINE);
}
module.exports = stringify;
{
"name": "mdast",
"version": "0.1.3",
"description": "Speedy Markdown parser/stringified for multipurpose analysis",
"version": "0.1.4",
"description": "Speedy Markdown parser/stringifier for multipurpose analysis",
"license": "MIT",

@@ -15,3 +15,5 @@ "keywords": [

"parse",
"stringify"
"stringify",
"bin",
"cli"
],

@@ -30,2 +32,5 @@ "dependencies": {

],
"bin": {
"mdast": "cli.js"
},
"devDependencies": {

@@ -43,9 +48,12 @@ "chalk": "^0.5.0",

"test": "_mocha --check-leaks test/index.js",
"test-travis": "istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js",
"test-cli": "bash test/cli.sh",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js",
"test-travis": "npm run test-cli && npm run test-coveralls",
"coverage": "istanbul cover _mocha -- -- test/index.js",
"lint-api": "eslint index.js lib/parse.js lib/stringify.js lib/utilities.js",
"lint-cli": "eslint --rule no-process-exit:false cli.js",
"lint-test": "eslint --env mocha test/index.js test/fixtures.js",
"lint-benchmark": "eslint --global suite,set,bench benchmark.js",
"lint-style": "jscs --reporter inline index.js lib/parse.js lib/stringify.js lib/utilities.js test/index.js test/fixtures.js benchmark.js",
"lint": "npm run lint-api && npm run lint-test && npm run lint-benchmark && npm run lint-style",
"lint-style": "jscs --reporter inline index.js benchmark.js cli.js lib/parse.js lib/stringify.js lib/utilities.js test/index.js test/fixtures.js",
"lint": "npm run lint-api && npm run lint-benchmark && npm run lint-cli && npm run lint-test && npm run lint-style",
"make": "npm run lint && npm run coverage",

@@ -52,0 +60,0 @@ "benchmark": "matcha benchmark.js"

@@ -94,7 +94,5 @@ # ![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg)

```md
Some *emphasis*, **strongness**, and `code`\.
Some _emphasis_, **strongness**, and `code`.
```
Yeah, the escaped period is nasty, but it works! :smile:
### [mdast](#mdast).parse(value, options?)

@@ -120,10 +118,10 @@

- `options` (`Object`) — Optional options:
- `options.preferSetextHeadings` (`boolean`, default: `false`). See [Setext Headings](#setext-headings);
- `options.preferReferenceLinks` (`boolean`, default: `false`). See [Reference Links](#reference-links);
- `options.preferReferenceFootnotes` (`boolean`, default: `true`). See [Inline Footnotes](#inline-footnotes);
- `options.preferFences` (`boolean`, default: `false`). See [Fences](#fences);
- `options.setext` (`boolean`, default: `false`). See [Setext Headings](#setext-headings);
- `options.referenceLinks` (`boolean`, default: `false`). See [Reference Links](#reference-links);
- `options.referenceFootnotes` (`boolean`, default: `true`). See [Inline Footnotes](#inline-footnotes);
- `options.fences` (`boolean`, default: `false`). See [Fences](#fences);
- `options.bullet` (`"-"`, `"*"`, or `"+"`, default: `"-"`). See [List Item Bullets](#list-item-bullets);
- `options.horizontalRule` (`"-"`, `"*"`, or `"_"`, default: `"*"`). See [Horizontal Rules](#horizontal-rules);
- `options.horizontalRuleRepetition` (`number`, default: 3). See [Horizontal Rules](#horizontal-rules);
- `options.horizontalRuleSpaces` (`boolean`, default `true`). See [Horizontal Rules](#horizontal-rules);
- `options.rule` (`"-"`, `"*"`, or `"_"`, default: `"*"`). See [Horizontal Rules](#horizontal-rules);
- `options.ruleRepetition` (`number`, default: 3). See [Horizontal Rules](#horizontal-rules);
- `options.ruleSpaces` (`boolean`, default `true`). See [Horizontal Rules](#horizontal-rules);
- `options.strong` (`"_"`, or `"*"`, default `"*"`). See [Emphasis Markers](#emphasis-markers);

@@ -136,2 +134,36 @@ - `options.emphasis` (`"_"`, or `"*"`, default `"_"`). See [Emphasis Markers](#emphasis-markers).

## CLI
Install:
```bash
$ npm install --global mdast
```
Use:
```text
Usage: mdast [options] file
Speedy Markdown parser/stringifier for multipurpose analysis
Options:
-h, --help output usage information
-v, --version output version number
-a, --ast output AST information
--options output available settings
-o, --option <option> specify settings
Usage:
# Pass `Readme.md` through mdast
$ mdast Readme.md > Readme.md
# Pass stdin through mdast, with options
$ cat Readme.md | mdast -o "setex-headings, bullet: *" > Readme.md
```
## Options
### Github Flavoured Markdown

@@ -467,3 +499,3 @@

mdast.stringify(ast, {
'preferSetextHeadings': true
'setextHeadings': true
});

@@ -528,5 +560,5 @@ ```

mdast.stringify(ast, {
'horizontalRule': '*',
'horizontalRuleRepetition': 80 / 2,
'horizontalRuleSpaces': true
'rule': '*',
'ruleRepetition': 80 / 2,
'ruleSpaces': true
});

@@ -582,3 +614,3 @@ ```

mdast.stringify(ast, {
'preferReferenceLinks': true
'referenceLinks': true
});

@@ -599,3 +631,3 @@ ```

By default, footnotes are stringified after the document. By setting `preferReferenceFootnotes: false` footnotes containing a single paragraph can be stringified inline.
By default, footnotes are stringified after the document. By setting `referenceFootnotes: false` footnotes containing a single paragraph can be stringified inline.

@@ -611,3 +643,3 @@ ```js

mdast.stringify(ast, {
'preferReferenceFootnotes': false
'referenceFootnotes': false
});

@@ -634,3 +666,3 @@ ```

mdast.stringify(ast, {
'preferFences': true
'fences': true
});

@@ -641,3 +673,3 @@ ```

``````md
````md
A code block:

@@ -648,3 +680,3 @@

\```
``````
````

@@ -925,9 +957,9 @@ The above example contains two slahes to make sure GitHub renders the markdown (in markdown) properly.

On a MacBook Air, it parser about 3 megabytes of markdown per second, depending on how much markup v.s. plain text the document contains, and which language the document is in, that’s more than the [entire works of Shakespeare](http://vintagezen.com/zen/2013/4/1/plain-text), in two seconds.
On a MacBook Air, it parser more than 3 megabytes of markdown per second, depending on how much markup v.s. plain text the document contains, and which language the document is in, that’s more than the [entire works of Shakespeare](http://www.gutenberg.org/ebooks/100), in under two seconds.
```text
benchmarks * 76 fixtures (total: 50Kb markdown)
63 op/s » mdast.parse
145 op/s » mdast.stringify
```
benchmarks * 56 fixtures (total: 47Kb markdown)
64 op/s » mdast.parse
179 op/s » mdast.stringify
```

@@ -934,0 +966,0 @@ ## License

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