Skip to content

Commit 13b37e9

Browse files
committed
Links to sindresorhus#199 Also see sancarn/awesome-vba#12 for reference
1 parent d83d036 commit 13b37e9

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

rules/list-item.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,18 @@ function validateList(list, file) {
106106
continue;
107107
}
108108

109-
let [link, ...description] = paragraph.children;
110-
111-
// Might have children like: '{image} {text} {link} { - description}'
112-
// Keep discarding prefix elements until we find something link-like.
113-
while (link.type !== 'linkReference' && link.type !== 'link' && description.length > 1) {
114-
link = description[0];
115-
description = description.slice(1);
109+
// Might also have children like '{image} {text} {link} {image} { - description}'
110+
// Specifically {any}* {link} [^{link}]* { - description}?
111+
// To properly find link and description we search first for { - description} node, then search backwards from the index to find the first link.
112+
let link;
113+
let description;
114+
const descriptionIndex = paragraph.children.findIndex(node => node?.type === 'text' && /^[\s\u00A0]-[\s\u00A0]/.test(node.value));
115+
if (descriptionIndex === -1) {
116+
// Possibly link with no description, but try to find description anyway.
117+
[link, ...description] = paragraph.children;
118+
} else {
119+
link = paragraph.children.slice(0, descriptionIndex).reverse().find(node => ['link', 'linkReference'].includes(node?.type));
120+
description = paragraph.children.slice(descriptionIndex);
116121
}
117122

118123
if (!validateListItemLink(link, file)) {

test/fixtures/list-item/0.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ These are valid list items that don't need a description.
5454
- [foo](https://foo.com) - The so-called `awesome-lint` project.
5555

5656
Test description's ending punctuation.
57+
5758
- [foo](https://foo.com) - Ending with a period.
5859
- [foo](https://foo.com) - Ending with an exclamation mark!
5960
- [foo](https://foo.com) - Ending with a question mark?
@@ -80,7 +81,7 @@ Test description's ending punctuation.
8081
- [foo](https://foo.com) - “Article's quote full of edge cases with non-balanced quote marks . But too long to be in full (…) so here is the best part — making an important point — with a twist.”
8182

8283
- [foo](https://foo.com) - Ending with a parenthetical. (Japanese)
83-
- [foo](https://foo.com) - Ending with an emphasis parenthetical. *(Japanese)*
84+
- [foo](https://foo.com) - Ending with an emphasis parenthetical. _(Japanese)_
8485
- [foo](https://foo.com) - Ending with a strong parenthetical. **(Japanese)**
8586

8687
- [foo](https://foo.com) - Ending with an emoji case 1. 📷
@@ -89,63 +90,70 @@ Test description's ending punctuation.
8990
- [foo](https://foo.com) - Ending with an emoji case 3. ⌚
9091

9192
These list items are special-cases which replace punctuation with emoji.
93+
9294
- [foo](https://foo.com) 💲
9395
- [foo](https://foo.com) - [Preview](https://read.amazon.com/kp/embed?asin=B01G7TTKSK&asin=B01G7TTKSK&preview=newtab&linkCode=kpe&ref_=cm_sw_r_kb_dp_DLhOxb0XZ3MEC) 💲
9496

9597
These list items are special-cases which have simple descripitions and no dash separator.
98+
9699
- [foo](https://foo.com) (parenthetical)
97-
- [foo](https://foo.com) *(emphasis parenthetical)*
100+
- [foo](https://foo.com) _(emphasis parenthetical)_
98101
- [foo](https://foo.com) **(strong parenthetical)**
99102
- [foo](https://foo.com) (parenthetical with emoji) 📷
100-
- [foo](https://foo.com) *(emphasis parenthetica with emojil)* 📷
103+
- [foo](https://foo.com) _(emphasis parenthetica with emojil)_ 📷
101104
- [foo](https://foo.com) **(strong parenthetica with emojil)** 📷
102105

103106
These list items use inline code in the link text.
107+
104108
- [`@electronjs` on Twitter](https://twitter.com/electronjs)
105109
- [`#node.js` on Freenode](https://webchat.freenode.net/?channels=node.js)
106-
- [`@electron_ru` on Telegram](https://telegram.me/electron_ru) *(Russian)*
110+
- [`@electron_ru` on Telegram](https://telegram.me/electron_ru) _(Russian)_
107111

108112
These list items start with common lower-case acronyms.
113+
109114
- [foo](https://foo.com) - npm is awesome.
110115
- [foo](https://foo.com) - iOS is awesome.
111116
- [foo](https://foo.com) - macOS is awesome.
112117

113118
- [macOS](https://github.com/iCHAIT/awesome-macOS#readme)
119+
114120
- [Command-Line](https://github.com/herrbischoff/awesome-macos-command-line#readme)
115121

116122
- Promises
117-
- [bar](https://bar.com)
118-
- [bar](https://bar.com)
123+
- [bar](https://bar.com)
124+
- [bar](https://bar.com)
119125
- Observables
120-
- [bar](https://bar.com)
126+
- [bar](https://bar.com)
121127

122128
These sub-lists are indented with tabs instead of spaces.
129+
123130
- [foo](https://foo.com)
124-
- [bar](https://bar.com)
125-
- [bar2](https://bar2.com)
126-
- [baz](https://baz.com)
127-
- [baz2](https://baz2.com)
131+
- [bar](https://bar.com)
132+
- [bar2](https://bar2.com)
133+
- [baz](https://baz.com)
134+
- [baz2](https://baz2.com)
128135

129136
These sub-lists use mixed indentation (spaces and tabs).
137+
130138
- [Python](https://github.com/vinta/awesome-python#readme)
131-
- [Asyncio](https://github.com/timofurrer/awesome-asyncio#readme) - Asynchronous I/O in Python 3.
132-
- [Scientific Audio](https://github.com/faroit/awesome-python-scientific-audio#readme) - Scientific research in audio/music.
133-
- [CircuitPython](https://github.com/adafruit/awesome-circuitpython#readme) - A version of Python for microcontrollers.
134139

140+
- [Asyncio](https://github.com/timofurrer/awesome-asyncio#readme) - Asynchronous I/O in Python 3.
141+
- [Scientific Audio](https://github.com/faroit/awesome-python-scientific-audio#readme) - Scientific research in audio/music.
142+
- [CircuitPython](https://github.com/adafruit/awesome-circuitpython#readme) - A version of Python for microcontrollers.
135143

136144
- [why-is-node-running](https://github.com/mafintosh/why-is-node-running) - Node.js is running but you don't know why?
137145

138-
139146
- [gtkada] - Ada graphical toolkit based on Gtk3 components (issue #161 link reference below but checked by `remark-lint-no-undefined-references` not `rules/list-item.js`).
140-
- [*example* `code`][exampleref] - Another linkref but with children.
147+
- [_example_ `code`][exampleref] - Another linkref but with children.
141148
- [foo](https://foo.com) ![stars](https://img.shields.io/github/stars/foo/foo.svg) - Valid description.
142149
- ![v3](img/vapor-3.png) [API Error Middleware](https://github.com/skelpo/APIErrorMiddleware) - Vapor middleware for converting thrown errors to JSON responses.
143150
- ![v2](img/vapor-2.png) ![v3](img/vapor-3.png) [Bugsnag](https://github.com/nodes-vapor/bugsnag) - Report errors with Bugsnag.
151+
- [![v2](img/vapor-2.png)](#-) [![v3](img/vapor-3.png)](#- "Tooltip") [Bugsnag](https://github.com/nodes-vapor/bugsnag) - Report errors with Bugsnag.
144152
- [ArcGIS location services - Postman Workspace](https://www.postman.com/arcgis-developer/workspace/arcgis-location-services) - Official Postman collections to work with the Geocoding & Search API, Routing & Directions API, Demographics & GeoEnrichment API, Data hosting and more (issue #146).
145153
- [rmw](https://github.com/ros2/rmw/tree/master/rmw) - Contains the ROS middleware API ![rmw](https://img.shields.io/github/stars/ros2/rmw.svg) (issue #49).
146154
<!-- TODO
147-
- [__Compiling machine learning programs via high-level tracing__. Roy Frostig, Matthew James Johnson, Chris Leary. _MLSys 2018_.](https://mlsys.org/Conferences/doc/2018/146.pdf) - This white paper describes an early version of JAX, detailing how computation is traced and compiled (issue #136)
148-
-->
155+
- [**Compiling machine learning programs via high-level tracing**. Roy Frostig, Matthew James Johnson, Chris Leary. _MLSys 2018_.](https://mlsys.org/Conferences/doc/2018/146.pdf) - This white paper describes an early version of JAX, detailing how computation is traced and compiled (issue #136)
156+
-->
149157

150158
[gtkada]: https://github.com/AdaCore/gtkada
151159
[exampleref]: https://example.com

0 commit comments

Comments
 (0)