Skip to content

Collapse consecutive blank lines if there's no title #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Running doctoc will insert the toc at that location.

Use the `--title` option to specify a (Markdown-formatted) custom TOC title; e.g., `doctoc --title '**Contents**' .` From then on, you can simply run `doctoc <file>` and doctoc will will keep the title you specified.

Alternatively, to blank out the title with a newline, use the `--notitle` option. This will simply remove the title from the TOC.
Alternatively, to blank out the title, use the `--notitle` option. This will simply remove the title from the TOC.

### Specifying a maximum heading level for TOC entries

Expand Down
4 changes: 3 additions & 1 deletion lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ exports = module.exports = function transform(content, mode, maxHeaderLevel, tit

var inferredTitle = determineTitle(title, notitle, lines, info);

var titleSeparator = inferredTitle ? '\n\n' : '\n';

var currentToc = info.hasStart && lines.slice(info.startIdx, info.endIdx + 1).join('\n')
, linesToToc = getLinesToToc(lines, currentToc, info);

Expand All @@ -139,7 +141,7 @@ exports = module.exports = function transform(content, mode, maxHeaderLevel, tit

var toc =
inferredTitle
+ '\n\n'
+ titleSeparator
+ linkedHeaders
.map(function (x) {
var indent = _(_.range(x.rank - lowestRank))
Expand Down
1 change: 0 additions & 1 deletion test/transform-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ test('\nclobber existing title', function (t) {
t.deepEqual(
headers.toc.split('\n')
, [ '',
'',
'- [Installation](#installation)',
'- [API](#api)',
'- [License](#license)',
Expand Down