Skip to content

Commit

Permalink
updated dependencies, fixed missing options for renderer.render, upda…
Browse files Browse the repository at this point in the history
…ted test, closes #30
  • Loading branch information
medfreeman committed Dec 29, 2016
1 parent 8988a7a commit 3eb39de
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
"!**/__tests__"
],
"dependencies": {
"clone": "^1.0.2",
"clone": "^2.1.0",
"uslug": "^1.0.4"
},
"devDependencies": {
"ava": "^0.14.0",
"ava": "^0.17.0",
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"babel-eslint": "^6.0.3",
"babel-eslint": "^7.1.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"coveralls": "^2.11.9",
"eslint": "^2.8.0",
"eslint-config-i-am-meticulous": "^4.2.1",
"markdown-it": "^6.0.1",
"eslint": "^3.12.2",
"eslint-config-i-am-meticulous": "^5.0.2",
"markdown-it": "^8.2.2",
"npmpub": "^3.1.0",
"nyc": "^6.4.0"
"nyc": "^10.0.0"
},
"scripts": {
"prepublish": "babel --ignore __tests__ src --out-dir dist",
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/anchor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from "ava"

import mdIt from "./utils/md-it"

test("markdown-it-toc-and-anchor anchor", (t) => {
Expand Down Expand Up @@ -55,7 +56,7 @@ test("markdown-it-toc-and-anchor anchor", (t) => {
),
`<p></p>
<h1 id="heading"><a class="anchor" href="#heading">` +
`<span class="octicon octicon-link"></span></a>Heading</h1>\n`,
"<span class=\"octicon octicon-link\"></span></a>Heading</h1>\n",
"should support GitHub style anchor link"
)
})
15 changes: 8 additions & 7 deletions src/__tests__/toc-callback.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import test from "ava"

import mdIt from "./utils/md-it"

test.cb("markdown-it-toc-and-anchor toc-callback", (t) => {
const callback = function(tocMarkdown, tocArray, tocHtml) {
t.is(
tocMarkdown,
`* [Heading](#heading)\n`,
"* [Heading](#heading)\n",
"should work with disabled toc insertion + callback, returning toc only"
)
t.deepEqual(
Expand Down Expand Up @@ -35,7 +36,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback", (t) => {
tocCallback: callback,
}
),
`<h1 id="heading">Heading</h1>\n`,
"<h1 id=\"heading\">Heading</h1>\n",
"should work with disabled toc insertion + callback, returning heading only"
)

Expand All @@ -46,7 +47,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback-toc", (t) => {
const callback = function(tocMarkdown, tocArray, tocHtml) {
t.is(
tocMarkdown,
`* [Heading](#heading)\n`,
"* [Heading](#heading)\n",
"should work with enabled toc insertion + callback, returning toc only"
)
t.deepEqual(
Expand Down Expand Up @@ -93,7 +94,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback-md", (t) => {
const callback = function(tocMarkdown, tocArray, tocHtml) {
t.is(
tocMarkdown,
`* [Heading](#heading)\n`,
"* [Heading](#heading)\n",
`should work with disabled toc insertion +
callback in md options, returning toc only`
)
Expand Down Expand Up @@ -127,7 +128,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback-md", (t) => {
tocCallback: callback,
}
),
`<h1 id="heading">Heading</h1>\n`,
"<h1 id=\"heading\">Heading</h1>\n",
`should work with disabled toc insertion +
callback in md options, returning heading only`
)
Expand All @@ -139,7 +140,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback-env", (t) => {
const callback = function(tocMarkdown, tocArray, tocHtml) {
t.is(
tocMarkdown,
`* [Heading](#heading)\n`,
"* [Heading](#heading)\n",
`should work with disabled toc insertion +
callback in md render env, returning toc only`
)
Expand Down Expand Up @@ -174,7 +175,7 @@ test.cb("markdown-it-toc-and-anchor toc-callback-env", (t) => {
tocCallback: callback,
}
),
`<h1 id="heading">Heading</h1>\n`,
"<h1 id=\"heading\">Heading</h1>\n",
`should work with disabled toc insertion +
callback in md render env, returning heading only`
)
Expand Down
22 changes: 10 additions & 12 deletions src/__tests__/toc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test from "ava"

import mdIt from "./utils/md-it"

test("markdown-it-toc-and-anchor toc", (t) => {
Expand All @@ -16,7 +17,7 @@ test("markdown-it-toc-and-anchor toc", (t) => {
mdIt(
"@[toc]"
),
`<p></p>\n`,
"<p></p>\n",
"should do nothing if not asked to"
)

Expand All @@ -25,7 +26,7 @@ test("markdown-it-toc-and-anchor toc", (t) => {
"@[toc]",
{ toc: true }
),
`<p></p>\n`,
"<p></p>\n",
"should do nothing with no heading"
)

Expand Down Expand Up @@ -274,15 +275,12 @@ and next element in the same inline token`
</ul>
</li>
<li><a href="#heading-2">Heading 2</a>
<ul>
<li>
*
<ul>
<li><a href="#deeper-heading">Deeper Heading</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</p>
<h1 id="heading-1">Heading 1</h1>
<h2 id="subheading">SubHeading</h2>
Expand All @@ -297,9 +295,9 @@ and next element in the same inline token`
{ resetIds: true }
),
[
`<h1 id="heading">Heading</h1>\n`,
`<h1 id="heading">Heading</h1>\n`,
`<h1 id="heading">Heading</h1>\n`,
"<h1 id=\"heading\">Heading</h1>\n",
"<h1 id=\"heading\">Heading</h1>\n",
"<h1 id=\"heading\">Heading</h1>\n",
],
`should return the same anchor hrefs for the same markdown headings with
same names on different renderings with the same markdownIt instance when
Expand All @@ -312,9 +310,9 @@ resetIds is true`
{ resetIds: false }
),
[
`<h1 id="heading">Heading</h1>\n`,
`<h1 id="heading-2">Heading</h1>\n`,
`<h1 id="heading-3">Heading</h1>\n`,
"<h1 id=\"heading\">Heading</h1>\n",
"<h1 id=\"heading-2\">Heading</h1>\n",
"<h1 id=\"heading-3\">Heading</h1>\n",
],
`should return different anchor hrefs for the same markdown headings with
same names on different renderings with the same markdownIt instance when
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/utils/md-it.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import markdownIt from "markdown-it"

import markdownItTocAndAnchor from "../../../src"

export default (md, options = {}, mdOptions = {}, renderEnv = {}) => {
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const treeToMarkdownBulletList = (tree, indent = 0) => tree.map(item => {
`[${ item.heading.content }](#${ item.heading.anchor })\n`
}
else {
node += `\n`
node += "\n"
}
if (item.nodes.length) {
node += treeToMarkdownBulletList(item.nodes, indent + 1)
Expand Down Expand Up @@ -202,7 +202,9 @@ export default function(md, options) {
attrs.push([ "class", options.tocClassName ])
}

tocHtml = markdownItSecondInstance.renderer.render(tocTokens)
tocHtml = markdownItSecondInstance.renderer.render(
tocTokens, markdownItSecondInstance.options
)

if (typeof state.env.tocCallback === "function") {
state.env.tocCallback.call(undefined, tocMarkdown, tocArray, tocHtml)
Expand Down

4 comments on commit 3eb39de

@popomore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you publish to npm for this change?

@medfreeman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Sorry about the wait. It'll be done in a few hours.

@medfreeman
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@popomore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, it have been fixed.

Please sign in to comment.