Skip to content

Commit

Permalink
Add two failing header-in-codeblock tests
Browse files Browse the repository at this point in the history
Both of these tests should be fixed before we can consider thlorenz#37, thlorenz#38,
and thlorenz#88 as resolved.

Credit goes to @yomed for `test/fixtures/readme-with-code.md`.
  • Loading branch information
jez committed May 30, 2016
1 parent af081fd commit 86f781a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/fixtures/readme-benign-backticks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Hello, world!

> You can make code blocks with three back ticks:
>
> ```
# Add this header
<h1>And also this one</h1>
> ```
37 changes: 37 additions & 0 deletions test/fixtures/readme-with-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
README to test doctoc with edge-case headers.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents

- [Single Backticks](#single-backticks)
- [Multiple Backticks](#multiple-backticks)
- [code tag](#code-tag)
- [pre tag](#pre-tag)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## Single Backticks
`<h2>not me single backticks</h2>`
`## nor me single backticks`

## Multiple Backticks
```
<h2>not me fenced</h2>
## nor me fenced
not even me fenced
------------------
```

## code tag
<code><h2>not me code</h2></code>
<code>## nor me code</code>

## pre tag
<pre>
<h2>not me pre</h2>
## nor me pre
not even me pre
-------
</pre>
37 changes: 37 additions & 0 deletions test/transform-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,40 @@ test('\ngiven a file that includes html with header tags using default maxHeader
)
t.end()
})

test('\ngiven a file with headers embedded in code', function (t) {
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-code.md', 'utf8');
var headers = transform(content);

t.deepEqual(
headers.toc.split('\n')
, [ '## Table of Contents',
'',
'- [Single Backticks](#single-backticks)',
'- [Multiple Backticks](#multiple-backticks)',
'- [code tag](#code-tag)',
'- [pre tag](#pre-tag)',
'' ]
, 'generates a correct toc when headers are embedded in code blocks'
)

t.end()
})

test('\ngiven a file with benign backticks', function (t) {
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-benign-backticks.md', 'utf8');
var headers = transform(content);

t.deepEqual(
headers.toc.split('\n')
, [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*',
'',
'- [Hello, world!](#hello-world)',
'- [Add this header](#add-this-header)',
'- [And also this one](#and-also-this-one)',
'' ]
, 'generates a correct toc when readme has benign backticks'
)

t.end()
})

0 comments on commit 86f781a

Please sign in to comment.