mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Improve code to determine unordered list style for MD004/ul-style (fixes #104).
This commit is contained in:
parent
c0ea22e55e
commit
056608a680
4 changed files with 61 additions and 38 deletions
17
lib/md004.js
17
lib/md004.js
|
|
@ -4,6 +4,19 @@
|
|||
|
||||
var shared = require("./shared");
|
||||
|
||||
// Returns the unordered list style for a list item token
|
||||
function unorderedListStyleFor(token) {
|
||||
switch (token.markup) {
|
||||
case "-":
|
||||
return "dash";
|
||||
case "+":
|
||||
return "plus";
|
||||
// case "*":
|
||||
default:
|
||||
return "asterisk";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD004", "ul-style" ],
|
||||
"description": "Unordered list style",
|
||||
|
|
@ -15,10 +28,10 @@ module.exports = {
|
|||
shared.flattenLists(params).forEach(function forList(list) {
|
||||
if (list.unordered) {
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = shared.unorderedListStyleFor(list.items[0]);
|
||||
expectedStyle = unorderedListStyleFor(list.items[0]);
|
||||
}
|
||||
list.items.forEach(function forItem(item) {
|
||||
var itemStyle = shared.unorderedListStyleFor(item);
|
||||
var itemStyle = unorderedListStyleFor(item);
|
||||
if (style === "sublist") {
|
||||
var nesting = list.nesting;
|
||||
if (!nestingStyles[nesting] &&
|
||||
|
|
|
|||
|
|
@ -100,19 +100,6 @@ module.exports.headingStyleFor = function headingStyleFor(token) {
|
|||
return "setext";
|
||||
};
|
||||
|
||||
// Returns the unordered list style for a list item token
|
||||
module.exports.unorderedListStyleFor = function unorderedListStyleFor(token) {
|
||||
switch (trimLeft(token.line).substr(0, 1)) {
|
||||
case "-":
|
||||
return "dash";
|
||||
case "+":
|
||||
return "plus";
|
||||
// case "*":
|
||||
default:
|
||||
return "asterisk";
|
||||
}
|
||||
};
|
||||
|
||||
// Calls the provided function for each matching token
|
||||
function filterTokens(params, type, callback) {
|
||||
(params.tokenLists[type] || []).forEach(callback);
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ Text
|
|||
|
||||
Text
|
||||
|
||||
> - Item
|
||||
> - Item
|
||||
> - Item {MD004}
|
||||
> - Item {MD004}
|
||||
|
||||
Text
|
||||
|
||||
|
|
@ -40,35 +40,35 @@ Text
|
|||
|
||||
Text
|
||||
|
||||
> * Item
|
||||
> * Item
|
||||
> * Item {MD030}
|
||||
> * Item {MD005}
|
||||
> * Item {MD005}
|
||||
> * Item {MD004}
|
||||
> * Item {MD004}
|
||||
> * Item {MD004} {MD030}
|
||||
> * Item {MD004} {MD005}
|
||||
> * Item {MD004} {MD005}
|
||||
|
||||
Text
|
||||
|
||||
> Text
|
||||
> > - Item
|
||||
> > - Item {MD027}
|
||||
> > - Item
|
||||
> > > - Item
|
||||
> > > - Item {MD027}
|
||||
> > > - Item {MD027}
|
||||
> > - Item {MD004}
|
||||
> > - Item {MD004} {MD027}
|
||||
> > - Item {MD004}
|
||||
> > > - Item {MD004}
|
||||
> > > - Item {MD004} {MD027}
|
||||
> > > - Item {MD004} {MD027}
|
||||
|
||||
Text
|
||||
|
||||
>* Item
|
||||
> * Item
|
||||
>>* Item
|
||||
>> * Item
|
||||
>+ Item
|
||||
> + Item
|
||||
>>+ Item
|
||||
>> + Item
|
||||
|
||||
Text
|
||||
|
||||
> Quoted text
|
||||
>
|
||||
> * A list
|
||||
> * of items
|
||||
> * A list {MD004}
|
||||
> * of items {MD004}
|
||||
>
|
||||
> More quoted text
|
||||
|
||||
|
|
@ -76,8 +76,8 @@ Text
|
|||
|
||||
> Quoted text
|
||||
>
|
||||
> > * A list
|
||||
> > * of items
|
||||
> > + A list
|
||||
> > + of items
|
||||
>
|
||||
> More quoted text
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ Text
|
|||
|
||||
> Quoted text
|
||||
>
|
||||
> > * A list
|
||||
> > * of items
|
||||
> > - A list {MD004}
|
||||
> > - of items {MD004}
|
||||
> >
|
||||
> > More quoted text
|
||||
|
|
|
|||
23
test/md004-list-items-in-blockquote.md
Normal file
23
test/md004-list-items-in-blockquote.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Header
|
||||
|
||||
Text
|
||||
|
||||
- Item
|
||||
- Item
|
||||
|
||||
Text
|
||||
|
||||
>- Item
|
||||
>- Item
|
||||
|
||||
Text
|
||||
|
||||
> - Item
|
||||
> - Item
|
||||
|
||||
Text
|
||||
|
||||
> > - Item
|
||||
> > - Item
|
||||
|
||||
Text
|
||||
Loading…
Add table
Add a link
Reference in a new issue