Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
markdownlint-rule-search-replace
Advanced tools
A custom markdownlint rule to search and replace patterns.
In markdown files, sometimes we want to replace certain characters or patterns. For example,
“
to straight quotes "
--
to m-dash —
...
to ellipsis …
Or specific cases like replace three backticks with one. [ref] Or ban certain words.
In such scenarios the markdownlint-rule-search-replace
rule can be used to flag or fix such occurrences.
Use following command to install
npm install markdownlint-rule-search-replace --save-dev
There are various ways markdownlint can be configured using objects, config files etc. For more information on markdownlint configuration refer options.config.
You'll have to add a configuration entry in the .markdownlint.json file. For example,
"search-replace": [
{
"name": "ellipsis",
"message": "Do not use three dots '...' for ellipsis.",
"search": "...",
"replace": "…"
},
{
"name": "curly-double-quotes",
"message": "Do not use curly double quotes.",
"search_pattern": "/“|”/g",
"replace": "\""
}
]
Here,
search-replace
: An array of search-replace definitions.name
: name of the definitionmessage
: corresponding messagesearch
: plain text to searchsearch_pattern
: regex pattern to search. Include flags as well, as if you are defining a regex literal in JavaScript, e.g. /http/g
.replace
: The replacement text, e.g. https
. Regex properties like $1
can be used if search_pattern
is being used.Note, search
and search_pattern
are interchangeable. The property search
is used if both are supplied.
The rule can be disabled for specific section or file. For example, if you want to disable the rule for a particular section:
...
### Markdown rules to follow
The rules are:
<!-- markdownlint-disable search-replace -->
- Do not use three dots '...' for ellipsis. Use '…' instead.
- Do not use two hyphens '--' use m-dash '—'.
<!-- markdownlint-enable search-replace -->
...
Here, the markdownlint will not apply the search-replace rule on the list. For more options refer Configuration section on markdownlint repo page.
There are various ways to run markdownlint.
Use following command for markdownlint-cli:
markdownlint test.md -r markdownlint-rule-search-replace
# or
markdonwlint test.md -r markdownlint-rule-search-replace --fix
Add the rule object to the customRules
array:
const searchReplace = require("markdownlint-rule-search-replace");
const options = {
...
"customRules": [searchReplace]
};
markdownlint(options, function callback(err, result) {
if (!err) {
console.log(result.toString());
}
});
FAQs
A custom markdownlint rule for search and replaces
The npm package markdownlint-rule-search-replace receives a total of 5,164 weekly downloads. As such, markdownlint-rule-search-replace popularity was classified as popular.
We found that markdownlint-rule-search-replace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.