mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update MD034/no-bare-urls to re-scan documents with potential violations using proper reference definition handling to avoid false positives (fixes #787).
This commit is contained in:
parent
054f208e9a
commit
488813f7f7
7 changed files with 136 additions and 102 deletions
|
|
@ -26,9 +26,10 @@ const {
|
|||
*
|
||||
* @param {string} markdown Markdown document.
|
||||
* @param {Object} [options] Options for micromark.
|
||||
* @param {boolean} [refsDefined] Whether to treat references as defined.
|
||||
* @returns {Object[]} Micromark events.
|
||||
*/
|
||||
function getMicromarkEvents(markdown, options = {}) {
|
||||
function getMicromarkEvents(markdown, options = {}, refsDefined = true) {
|
||||
|
||||
// Customize options object to add useful extensions
|
||||
options.extensions = options.extensions || [];
|
||||
|
|
@ -38,8 +39,10 @@ function getMicromarkEvents(markdown, options = {}) {
|
|||
const encoding = undefined;
|
||||
const eol = true;
|
||||
const parseContext = parse(options);
|
||||
// Customize ParseContext to treat all references as defined
|
||||
parseContext.defined.includes = (searchElement) => searchElement.length > 0;
|
||||
if (refsDefined) {
|
||||
// Customize ParseContext to treat all references as defined
|
||||
parseContext.defined.includes = (searchElement) => searchElement.length > 0;
|
||||
}
|
||||
const chunks = preprocess()(markdown, encoding, eol);
|
||||
const events = postprocess(parseContext.document().write(chunks));
|
||||
return events;
|
||||
|
|
@ -50,12 +53,14 @@ function getMicromarkEvents(markdown, options = {}) {
|
|||
*
|
||||
* @param {string} markdown Markdown document.
|
||||
* @param {Object} [options] Options for micromark.
|
||||
* @param {boolean} [refsDefined] Whether to treat references as defined.
|
||||
* @returns {Token[]} Micromark tokens (frozen).
|
||||
*/
|
||||
function micromarkParse(markdown, options = {}) {
|
||||
function micromarkParse(markdown, options = {}, refsDefined = true) {
|
||||
|
||||
// Use micromark to parse document into Events
|
||||
const events = getMicromarkEvents(markdown, options);
|
||||
const events =
|
||||
getMicromarkEvents(markdown, options, refsDefined);
|
||||
|
||||
// Create Token objects
|
||||
const document = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue