Skip to content

Commit 1b552e9

Browse files
Merge pull request #43 from BarryThePenguin/update-remark-10
Update remark 10
2 parents d881b54 + 96ec06d commit 1b552e9

File tree

21 files changed

+113
-4
lines changed

21 files changed

+113
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Yields:
5151
map:
5252
{ type: 'list',
5353
ordered: false,
54-
children: [ { type: 'listItem', loose: true, children: [Object] } ] } }
54+
children: [ { type: 'listItem', loose: true, children: [Array] } ] } }
5555
```
5656

5757
## API

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function toc(node, options) {
2727
var result = search(node, heading, settings.maxDepth || 6);
2828
var map = result.map;
2929

30-
result.map = map.length ? contents(map, settings.tight) : null;
30+
result.map = map.length === 0 ? null : contents(map, settings.tight);
3131

3232
/* No given heading */
3333
if (!heading) {

lib/insert.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ function insert(node, parent, tight) {
8282
* Properly style list-items with new lines.
8383
*/
8484

85+
parent.spread = !tight;
86+
87+
if (parent.type === LIST && parent.spread) {
88+
parent.spread = false;
89+
index = -1;
90+
91+
while (++index < length) {
92+
if (children[index].children.length > 1) {
93+
parent.spread = true;
94+
break;
95+
}
96+
}
97+
}
98+
99+
// To do: remove `loose` in next major release.
85100
if (parent.type === LIST_ITEM) {
86101
parent.loose = tight ? false : children.length > 1;
87102
} else {

lib/list-item.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ var LIST_ITEM = 'listItem';
2020
function listItem() {
2121
return {
2222
type: LIST_ITEM,
23+
// To do: remove `loose` in next major.
2324
loose: false,
25+
spread: false,
2426
children: []
2527
};
2628
}

lib/list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function list() {
2121
return {
2222
type: LIST,
2323
ordered: false,
24+
spread: false,
2425
children: []
2526
};
2627
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"browserify": "^16.2.1",
4343
"esmangle": "^1.0.1",
4444
"istanbul": "^0.4.4",
45-
"remark-attr": "^0.6.2",
45+
"remark-attr": "^0.7.0",
4646
"remark": "^10.0.0",
4747
"remark-cli": "^6.0.0",
4848
"remark-comment-config": "^5.0.0",
@@ -52,7 +52,7 @@
5252
"remark-usage": "^6.0.0",
5353
"remark-validate-links": "^7.0.0",
5454
"tape": "^4.6.0",
55-
"xo": "^0.21.1"
55+
"xo": "^0.23.0"
5656
},
5757
"xo": {
5858
"space": 4,

test/fixtures/custom-heading/output.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"map": {
55
"type": "list",
66
"ordered": false,
7+
"spread": true,
78
"children": [
89
{
910
"type": "listItem",
1011
"loose": true,
12+
"spread": true,
1113
"children": [
1214
{
1315
"type": "paragraph",
@@ -28,10 +30,12 @@
2830
{
2931
"type": "list",
3032
"ordered": false,
33+
"spread": false,
3134
"children": [
3235
{
3336
"type": "listItem",
3437
"loose": false,
38+
"spread": false,
3539
"children": [
3640
{
3741
"type": "paragraph",
@@ -54,6 +58,7 @@
5458
{
5559
"type": "listItem",
5660
"loose": false,
61+
"spread": false,
5762
"children": [
5863
{
5964
"type": "paragraph",
@@ -80,6 +85,7 @@
8085
{
8186
"type": "listItem",
8287
"loose": false,
88+
"spread": false,
8389
"children": [
8490
{
8591
"type": "paragraph",

test/fixtures/deep-headings/output.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"map": {
55
"type": "list",
66
"ordered": false,
7+
"spread": true,
78
"children": [
89
{
910
"type": "listItem",
1011
"loose": true,
12+
"spread": true,
1113
"children": [
1214
{
1315
"type": "paragraph",
@@ -28,10 +30,12 @@
2830
{
2931
"type": "list",
3032
"ordered": false,
33+
"spread": false,
3134
"children": [
3235
{
3336
"type": "listItem",
3437
"loose": false,
38+
"spread": false,
3539
"children": [
3640
{
3741
"type": "paragraph",
@@ -58,6 +62,7 @@
5862
{
5963
"type": "listItem",
6064
"loose": false,
65+
"spread": false,
6166
"children": [
6267
{
6368
"type": "paragraph",

test/fixtures/image-in-link-in-heading/output.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"map": {
55
"type": "list",
66
"ordered": false,
7+
"spread": true,
78
"children": [
89
{
910
"type": "listItem",
1011
"loose": true,
12+
"spread": true,
1113
"children": [
1214
{
1315
"type": "paragraph",
@@ -28,10 +30,12 @@
2830
{
2931
"type": "list",
3032
"ordered": false,
33+
"spread": false,
3134
"children": [
3235
{
3336
"type": "listItem",
3437
"loose": false,
38+
"spread": false,
3539
"children": [
3640
{
3741
"type": "paragraph",
@@ -54,6 +58,7 @@
5458
{
5559
"type": "listItem",
5660
"loose": false,
61+
"spread": false,
5762
"children": [
5863
{
5964
"type": "paragraph",
@@ -80,6 +85,7 @@
8085
{
8186
"type": "listItem",
8287
"loose": false,
88+
"spread": false,
8389
"children": [
8490
{
8591
"type": "paragraph",

test/fixtures/maximum-depth-1/output.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"map": {
55
"type": "list",
66
"ordered": false,
7+
"spread": false,
78
"children": [
89
{
910
"type": "listItem",
1011
"loose": false,
12+
"spread": false,
1113
"children": [
1214
{
1315
"type": "paragraph",

0 commit comments

Comments
 (0)