-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
add more flexibility to hyphen separated check; explicit em-dash check #185
Changes from 2 commits
dc58049
ae91733
a5509df
1affb9d
3ad6572
9c6ff83
e7ccfbe
ea4a4a8
bfa29a3
a526a1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -102,12 +102,24 @@ function validateList(list, file) { | |||||||
continue; | ||||||||
} | ||||||||
|
||||||||
const [link, ...description] = paragraph.children; | ||||||||
|
||||||||
if (link.type === 'text') { | ||||||||
if (paragraph.children[0].type === 'text') { | ||||||||
continue; | ||||||||
} | ||||||||
|
||||||||
let [link, ...description] = paragraph.children; | ||||||||
|
||||||||
// Might have children like {image} {text} {link} - {descrition} | ||||||||
// Keep discarding elements until we find a link | ||||||||
// or linkReference | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if (!/link/.test(link.type)) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compare explicitly. Doesn't make sense to use regex here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. besides linkReference and link, I'm not sure if there are other link items in markdown -- figured any type matching "link" should get to pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use
Look at the docs for the Markdown parser. |
||||||||
for (let i = 0; i < description.length - 1; i++) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. worse, I don't think I need to test link's type twice. while loop is probably better? (in recent commit) |
||||||||
if (/link/.test(description[i].type)) { | ||||||||
link = description[i]; | ||||||||
description = description.slice(i + 1); | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if (!validateListItemLink(link, file)) { | ||||||||
continue; | ||||||||
} | ||||||||
|
@@ -117,6 +129,13 @@ function validateList(list, file) { | |||||||
} | ||||||||
|
||||||||
function validateListItemLink(link, file) { | ||||||||
// NB. need remark-lint-no-undefined-references separately | ||||||||
// to catch if this is a valid reference. here we only care that it exists | ||||||||
WillForan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
if (link.type === 'linkReference') { | ||||||||
// TODO: need to test link children against listItemLinkNodeAllowList? | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be resolved. |
||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
if (link.type !== 'link') { | ||||||||
file.message('Invalid list item link', link); | ||||||||
return false; | ||||||||
|
@@ -168,11 +187,17 @@ function validateListItemDescription(description, file) { | |||||||
return false; | ||||||||
} | ||||||||
|
||||||||
if (/^\s*—/.test(prefixText)) { | ||||||||
file.message('List item link and description separated by invalid en-dash', prefix); | ||||||||
if (/^\s*[—–]/.test(prefixText)) { | ||||||||
WillForan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
file.message('List item link and description separated by invalid en-dash or em-dash', prefix); | ||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
// Might have image and link on left side before desciption. | ||||||||
// Assume a hyphen with spaces in the description is good enough | ||||||||
if (/ - +[A-Z]/.test(descriptionText)) { | ||||||||
WillForan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
file.message('List item link and description must be separated with a dash', prefix); | ||||||||
return false; | ||||||||
} | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo