forked from thlorenz/doctoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves thlorenz#64. The `title` variable in `lib/transform.js` is now populated according to this logic: - If the new `--notitle` option is specified: - `title = ''` - If a title was explicitly passed with `--title`: - `title` is the user-specified title - If a TOC exists )as evidencedy by `info.hasStart`: - `title = lines[info.startIdx + 2]` - This line is assumed to always be the TOC title - Otherwise: - `title` is the standard "**Table of Contents**" title
- Loading branch information
Showing
7 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Hello, world! | ||
|
||
README to test doctoc with user-specified titles. | ||
|
||
<!-- 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 | ||
|
||
- [Installation](#installation) | ||
- [API](#api) | ||
- [License](#license) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
|
||
## Installation | ||
## API | ||
## License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
/*jshint asi: true */ | ||
|
||
var test = require('tap').test | ||
, transform = require('../lib/transform'); | ||
|
||
test('\noverwrite existing title', function (t) { | ||
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-custom-title.md', 'utf8'); | ||
var headers = transform(content, null, null, '## Table of Contents', false); | ||
|
||
t.deepEqual( | ||
headers.toc.split('\n') | ||
, [ '## Table of Contents', | ||
'', | ||
'- [Installation](#installation)', | ||
'- [API](#api)', | ||
'- [License](#license)', | ||
'' ] | ||
, 'generates correct toc for when custom --title was passed' | ||
) | ||
t.end() | ||
}); | ||
|
||
test('\ndo not overwrite existing title', function (t) { | ||
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-custom-title.md', 'utf8'); | ||
var headers = transform(content, null, null, null, false); | ||
|
||
t.deepEqual( | ||
headers.toc.split('\n') | ||
, [ '## Table of Contents', | ||
'', | ||
'- [Installation](#installation)', | ||
'- [API](#api)', | ||
'- [License](#license)', | ||
'' ] | ||
, 'generates correct toc for when custom title exists in README already' | ||
) | ||
t.end() | ||
}); | ||
|
||
test('\nclobber existing title', function (t) { | ||
var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-custom-title.md', 'utf8'); | ||
var headers = transform(content, null, null, null, true); | ||
|
||
t.deepEqual( | ||
headers.toc.split('\n') | ||
, [ '', | ||
'', | ||
'- [Installation](#installation)', | ||
'- [API](#api)', | ||
'- [License](#license)', | ||
'' ] | ||
, 'generates correct toc for when --notitle was passed' | ||
) | ||
t.end() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters