🚀 Socket Launch Week 🚀 Day 3: Socket Acquires Coana.Learn More →

react-markdown-github

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-markdown-github - npm Package Compare versions

Comparing version

to
3.1.0

# `react-markdown-github`
### 3.1.0
- [#10] Bump `react-markdown` to `^4.0.6`
- [#9] Reset slug counts before rendering to prevent inconsistent anchors
### 3.0.1

@@ -38,1 +43,2 @@

[#8]: https://github.com/godaddy/react-markdown-github/pull/8
[#9]: https://github.com/godaddy/react-markdown-github/pull/9

@@ -160,14 +160,4 @@ 'use strict';

value: function renderHeading(props) {
var title = '';
var uniqueSlug = this.slugify.slugNode(props.children);
props.children.forEach(function (child) {
if (child.props && child.props.children) {
title += child.props.children;
} else {
title += child;
}
});
var uniqueSlug = this.slugify.slug(title);
// eslint-disable-next-line react/no-children-prop

@@ -196,3 +186,3 @@ return _react2.default.createElement('h' + props.level, {

}, this.props.renderers);
this.slugify.reset();
return _react2.default.createElement(_reactMarkdown2.default, _extends({}, this.props, {

@@ -199,0 +189,0 @@ renderers: renderers,

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

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -65,2 +67,29 @@

/**
* Helper function to extract text from a node.
* @api public
* @param {React.ReactElement} node - the react element to extract text from.
* @returns {String} the node text extracted from the node.
*/
}, {
key: 'extractString',
value: function extractString(node) {
var _this = this;
var title = '';
if (node.props && node.props.children) {
if (_typeof(node.props.children) === 'object') {
node.props.children.forEach(function (child) {
title += _this.extractString(child);
});
} else {
title += node.props.children;
}
} else {
title += node;
}
return title;
}
/**
* Generates a GH style slug from the passed text.

@@ -77,3 +106,2 @@ * @api public

var uniqueSlug = slug;
this.slugs[slug] = this.slugs[slug] || 0;

@@ -88,2 +116,21 @@ if (this.slugs[slug]) {

/**
* Generates a GH style slug from the passed node.
* @api public
* @param {Array} nodes - the react elements to be used to create a slug.
* @returns {String} the node text converted to a slug.
*/
}, {
key: 'slugNode',
value: function slugNode(nodes) {
var _this2 = this;
var title = '';
nodes.forEach(function (node) {
title += _this2.extractString(node);
});
return this.slug(title);
}
/**
* Resets the state of this object including

@@ -90,0 +137,0 @@ * the tracking of duplicate slugs.

{
"name": "react-markdown-github",
"description": "React component that renders Markdown similarly to Github's formatting",
"version": "3.0.1",
"version": "3.1.0",
"main": "./lib/index.js",

@@ -20,3 +20,3 @@ "browser": "./lib/index.js",

"prepublishOnly": "rimraf lib && mkdir -p lib && babel -d lib src",
"pretest": "npm run lint",
"posttest": "npm run lint",
"test": "nyc --reporter=text --reporter=json-summary npm run test:mocha",

@@ -64,5 +64,5 @@ "test:mocha": "mocha --require test/setup ./test/*.test.js"

"dependencies": {
"react-markdown": "^3.3.0",
"react-markdown": "^4.0.6",
"url-parse": "^1.4.0"
}
}

@@ -138,14 +138,4 @@ import React, { Component } from 'react';

renderHeading(props) {
let title = '';
const uniqueSlug = this.slugify.slugNode(props.children);
props.children.forEach((child) => {
if (child.props && child.props.children) {
title += child.props.children;
} else {
title += child;
}
});
const uniqueSlug = this.slugify.slug(title);
// eslint-disable-next-line react/no-children-prop

@@ -170,3 +160,3 @@ return React.createElement(`h${props.level}`, {

};
this.slugify.reset();
return (

@@ -173,0 +163,0 @@ <ReactMarkdown

@@ -50,2 +50,24 @@ /**

/**
* Helper function to extract text from a node.
* @api public
* @param {React.ReactElement} node - the react element to extract text from.
* @returns {String} the node text extracted from the node.
*/
extractString(node) {
let title = '';
if (node.props && node.props.children) {
if (typeof node.props.children === 'object') {
node.props.children.forEach((child) => {
title += this.extractString(child);
});
} else {
title += node.props.children;
}
} else {
title += node;
}
return title;
}
/**
* Generates a GH style slug from the passed text.

@@ -59,3 +81,2 @@ * @api public

let uniqueSlug = slug;
this.slugs[slug] = this.slugs[slug] || 0;

@@ -70,2 +91,16 @@ if (this.slugs[slug]) {

/**
* Generates a GH style slug from the passed node.
* @api public
* @param {Array} nodes - the react elements to be used to create a slug.
* @returns {String} the node text converted to a slug.
*/
slugNode(nodes) {
let title = '';
nodes.forEach((node) => {
title += this.extractString(node);
});
return this.slug(title);
}
/**
* Resets the state of this object including

@@ -72,0 +107,0 @@ * the tracking of duplicate slugs.

@@ -159,2 +159,19 @@ import React from 'react';

it('Does not increment anchors on re-render', () => {
const input = `
# Header
# Header
`;
renderFullDom({ source: input });
assume(tree.find('#header')).to.have.length(1);
assume(tree.find('#header-1')).to.have.length(1);
assume(tree.find('#header-2')).to.have.length(0);
tree.setProps(input);
assume(tree.find('#header-2')).to.have.length(0);
assume(tree.find('#header-1')).to.have.length(1);
assume(tree.find('#header')).to.have.length(1);
});
it('A header with code elements', () => {

@@ -174,3 +191,2 @@ const input = '### a `codething` in the header `moreCode` txt';

renderFullDom({ source: input });
assume(tree.find('#bold-in-the-bold-header')).to.have.length(1);

@@ -177,0 +193,0 @@ assume(tree.find('#bold-in-the-bold-header')

@@ -0,1 +1,2 @@

import React from 'react';
import assume from 'assume';

@@ -51,3 +52,9 @@ import { GithubSlugify } from '../src';

it('nested children', () => {
const slug = new GithubSlugify();
const nodes = <div><div><div>this </div><div>is </div>a test </div>string</div>;
assume(slug.slugNode(nodes.props.children)).equals('this-is-a-test-string');
});
it('can reset unique counts', () => {

@@ -54,0 +61,0 @@ const slug = new GithubSlugify();

Sorry, the diff of this file is not supported yet