mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add full-width punctuation characters to MD026/no-trailing-punctuation and MD036/no-emphasis-as-heading (fixes #192).
This commit is contained in:
parent
fa40084994
commit
1d8b9e7e62
8 changed files with 45 additions and 25 deletions
18
doc/Rules.md
18
doc/Rules.md
|
@ -788,10 +788,10 @@ Tags: headings, headers
|
|||
|
||||
Aliases: no-trailing-punctuation
|
||||
|
||||
Parameters: punctuation (string; default ".,;:!?")
|
||||
Parameters: punctuation (string; default ".,;:!?。,;:!?")
|
||||
|
||||
This rule is triggered on any heading that has a punctuation character as the
|
||||
last character in the line:
|
||||
This rule is triggered on any heading that has a normal or full-width punctuation
|
||||
character as the last character in the line:
|
||||
|
||||
```markdown
|
||||
# This is a heading.
|
||||
|
@ -1207,7 +1207,7 @@ Tags: headings, headers, emphasis
|
|||
|
||||
Aliases: no-emphasis-as-heading, no-emphasis-as-header
|
||||
|
||||
Parameters: punctuation (string; default ".,;:!?")
|
||||
Parameters: punctuation (string; default ".,;:!?。,;:!?")
|
||||
|
||||
This check looks for instances where emphasized (i.e. bold or italic) text is
|
||||
used to separate sections, where a heading should be used instead:
|
||||
|
@ -1235,11 +1235,11 @@ Lorem ipsum dolor sit amet...
|
|||
Consectetur adipiscing elit, sed do eiusmod.
|
||||
```
|
||||
|
||||
Note: this rule looks for single line paragraphs that consist entirely of
|
||||
emphasized text. It won't fire on emphasis used within regular text,
|
||||
multi-line emphasized paragraphs, and paragraphs ending in punctuation.
|
||||
Similarly to rule MD026, you can configure what characters are recognized as
|
||||
punctuation.
|
||||
Note: This rule looks for single line paragraphs that consist entirely
|
||||
of emphasized text. It won't fire on emphasis used within regular text,
|
||||
multi-line emphasized paragraphs, or paragraphs ending in punctuation
|
||||
(normal or full-width). Similarly to rule MD026, you can configure what
|
||||
characters are recognized as punctuation.
|
||||
|
||||
<a name="md037"></a>
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@ module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
|
|||
// readFile options for reading with the UTF-8 encoding
|
||||
module.exports.utf8Encoding = { "encoding": "utf8" };
|
||||
|
||||
// All punctuation characters (normal and full-width)
|
||||
module.exports.allPunctuation = ".,;:!?。,;:!?";
|
||||
|
||||
// Returns true iff the input is a number
|
||||
module.exports.isNumber = function isNumber(obj) {
|
||||
return typeof obj === "number";
|
||||
|
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, forEachHeading, rangeFromRegExp } = require("../helpers");
|
||||
const { addError, allPunctuation, forEachHeading, rangeFromRegExp } =
|
||||
require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
"description": "Trailing punctuation in heading",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD026(params, onError) {
|
||||
const punctuation = params.config.punctuation || ".,;:!?";
|
||||
const punctuation = params.config.punctuation || allPunctuation;
|
||||
const trailingPunctuationRe = new RegExp("[" + punctuation + "]$");
|
||||
forEachHeading(params, function forHeading(heading, content) {
|
||||
const match = trailingPunctuationRe.exec(content);
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { addErrorContext, allPunctuation } = require("../helpers");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD036", "no-emphasis-as-heading", "no-emphasis-as-header" ],
|
||||
"description": "Emphasis used instead of a heading",
|
||||
"tags": [ "headings", "headers", "emphasis" ],
|
||||
"function": function MD036(params, onError) {
|
||||
const punctuation = params.config.punctuation || ".,;:!?";
|
||||
const punctuation = params.config.punctuation || allPunctuation;
|
||||
const re = new RegExp("[" + punctuation + "]$");
|
||||
function base(token) {
|
||||
if (token.type === "paragraph_open") {
|
||||
|
|
|
@ -190,7 +190,7 @@ rules.forEach(function forRule(rule) {
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
};
|
||||
break;
|
||||
|
|
|
@ -708,7 +708,7 @@
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -724,7 +724,7 @@
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -966,7 +966,7 @@
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -982,7 +982,7 @@
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -998,7 +998,7 @@
|
|||
"punctuation": {
|
||||
"description": "Punctuation characters",
|
||||
"type": "string",
|
||||
"default": ".,;:!?"
|
||||
"default": ".,;:!?。,;:!?"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
|
|
@ -39,4 +39,6 @@ detected as a heading because it's on multiple lines**
|
|||
|
||||
**This also shouldn't be detected as a heading as it ends in punctuation.**
|
||||
|
||||
**This shouldn't be detected as a heading as it ends in full-width punctuation。**
|
||||
|
||||
**[This as well since it is a link](https://example.com)**
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
# Heading 1 {MD026}.
|
||||
# Heading Trailing Punctuation
|
||||
|
||||
## Heading 2 {MD026},
|
||||
## Heading {MD026} .
|
||||
|
||||
## Heading 3 {MD026}!
|
||||
## Heading {MD026} ,
|
||||
|
||||
## Heading 4 {MD026}:
|
||||
## Heading {MD026} ;
|
||||
|
||||
## Heading 5 {MD026};
|
||||
## Heading {MD026} :
|
||||
|
||||
## Heading 6 {MD026}?
|
||||
## Heading {MD026} !
|
||||
|
||||
## Heading {MD026} ?
|
||||
|
||||
## Heading/Full-Width {MD026} 。
|
||||
|
||||
## Heading/Full-Width {MD026} ,
|
||||
|
||||
## Heading/Full-Width {MD026} ;
|
||||
|
||||
## Heading/Full-Width {MD026} :
|
||||
|
||||
## Heading/Full-Width {MD026} !
|
||||
|
||||
## Heading/Full-Width {MD026} ?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue