markdown-link-check icon indicating copy to clipboard operation
markdown-link-check copied to clipboard

Make replacementPatterns do global replace

Open glensc opened this issue 2 years ago • 2 comments

From readme:

replacementPatterns: An array of objects holding regular expressions which are replaced in a link with their corresponding replacement string. This behavior allows (for example) to adapt to certain platform conventions hosting the Markdown. The special replacement {{BASEURL}} can be used to dynamically link to the current working directory (for example that / points to the root of your current working directory).

I am checking gitlab wiki repository where spaces are encoded as %20 when saving, but in filenames they're -. tried such config, but it replaced only first occurrence of %20:

{
  "replacementPatterns": [
    {
      "pattern": "$",
      "replacement": ".md"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    }
  ]
}

please add /g like flag:

/%20/g

glensc avatar Aug 30 '23 12:08 glensc

workaround: add same pattern as many times until no more matches are left. in my case:

{
  "replacementPatterns": [
    {
      "pattern": "$",
      "replacement": ".md"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    },
    {
      "pattern": "%20",
      "replacement": "-"
    }
  ]
}

glensc avatar Aug 30 '23 12:08 glensc

It could be added with an optional "global": true to avoid breaking changes?

CanadaHonk avatar Oct 17 '23 18:10 CanadaHonk