Top Related Projects
Markdown lint tool
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
textlint is the pluggable linter for natural language text.
Quick Overview
Markdownlint is a tool for checking markdown files and flagging style issues. It's designed to be flexible and customizable, allowing users to enforce consistent markdown styling across their projects. The tool can be integrated into various workflows and CI/CD pipelines.
Pros
- Highly customizable with numerous built-in rules and the ability to create custom rules
- Can be used as a command-line tool, Ruby library, or integrated into various text editors and IDEs
- Supports multiple markdown flavors and can be configured to match specific style guides
- Active development and community support
Cons
- Requires Ruby runtime, which may not be available in all environments
- Some users may find the default rule set too strict or opinionated
- Configuration can be complex for advanced use cases
- May produce false positives in certain edge cases
Code Examples
Here are a few examples of how to use Markdownlint in Ruby:
- Basic usage:
require 'mdl'
rules = MarkdownLint::RuleSet.new(MarkdownLint::AllRules)
doc = MarkdownLint::Doc.new("# My Markdown File\n\nSome content here.")
results = rules.check(doc)
puts results.map(&:to_s)
- Customizing rules:
require 'mdl'
rules = MarkdownLint::RuleSet.new
rules.load_rule(:MD001) # Only load the "Header levels should only increment by one level at a time" rule
rules.load_rule(:MD009) # Also load the "Trailing spaces" rule
doc = MarkdownLint::Doc.new(File.read('README.md'))
results = rules.check(doc)
- Creating a custom rule:
require 'mdl'
class MyCustomRule < MarkdownLint::Rule
def check(doc)
doc.lines.each_with_index do |line, linenum|
if line.include?('TODO')
add_issue(linenum + 1, "TODO found in document")
end
end
end
end
rules = MarkdownLint::RuleSet.new
rules.add_rule(MyCustomRule.new)
doc = MarkdownLint::Doc.new(File.read('document.md'))
results = rules.check(doc)
Getting Started
To use Markdownlint in your Ruby project:
-
Install the gem:
gem install mdl
-
Create a configuration file (
.mdlrc
) in your project root:style 'path/to/your/style.rb' rules 'MD001', 'MD009'
-
Run Markdownlint on your markdown files:
mdl your_markdown_file.md
For more advanced usage and integration with other tools, refer to the project's documentation on GitHub.
Competitor Comparisons
Markdown lint tool
Pros of markdownlint
- Written in Ruby, making it easily extensible for Ruby developers
- Provides a command-line interface for easy integration into build processes
- Offers a wide range of customizable rules for Markdown linting
Cons of markdownlint
- May have slower performance compared to JavaScript-based alternatives
- Requires Ruby runtime, which might not be available in all environments
- Less frequent updates and maintenance compared to some other linters
Code Comparison
markdownlint:
rule "MD001", "Header levels should only increment by one level at a time" do
tags :headers
check do |doc|
headers = doc.headers
headers.each_cons(2).map do |first, second|
second.level - first.level
end.reject { |i| i <= 1 }
end
end
markdownlint:
module.exports = {
"default": true,
"MD001": true,
"MD003": { "style": "atx" },
"MD007": { "indent": 4 },
"no-hard-tabs": false
};
Note: The code comparison shows different approaches to rule definition and configuration between the Ruby-based markdownlint and the JavaScript-based markdownlint. The Ruby version defines rules programmatically, while the JavaScript version uses a configuration object.
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
Pros of Vale
- More versatile, supporting multiple markup languages beyond Markdown
- Highly customizable with user-defined style guides and vocabularies
- Integrates with various text editors and CI/CD pipelines
Cons of Vale
- Steeper learning curve due to its extensive configuration options
- Requires more setup time compared to Markdownlint's out-of-the-box functionality
- May be overkill for simple Markdown-only projects
Code Comparison
Vale configuration example:
StylesPath = styles
MinAlertLevel = suggestion
[*.md]
BasedOnStyles = Vale, write-good
Markdownlint configuration example:
{
"default": true,
"MD013": { "line_length": 120 },
"MD033": false
}
Both tools offer configuration options, but Vale's approach is more complex and flexible, allowing for custom styles and vocabularies. Markdownlint's configuration is simpler and focused specifically on Markdown rules.
Vale is better suited for larger projects with diverse content types and custom style requirements, while Markdownlint excels in straightforward Markdown linting tasks with minimal setup.
textlint is the pluggable linter for natural language text.
Pros of textlint
- More versatile, supporting multiple file formats beyond Markdown
- Highly extensible with a large ecosystem of plugins
- Provides a powerful API for custom rule creation
Cons of textlint
- Steeper learning curve due to its broader scope
- May require more configuration for Markdown-specific linting
- Potentially slower performance when processing large files
Code Comparison
textlint:
import { TextLintEngine } from "textlint";
const engine = new TextLintEngine();
const results = await engine.executeOnFiles(["README.md"]);
if (engine.isErrorResults(results)) {
console.log(engine.formatResults(results));
}
markdownlint:
const markdownlint = require("markdownlint");
const options = {
files: ["README.md"],
config: {
"default": true,
"MD013": false
}
};
markdownlint(options, function callback(err, result) {
console.log(result.toString());
});
Both tools offer powerful linting capabilities, but textlint provides more flexibility for various text formats, while markdownlint focuses specifically on Markdown. The code examples demonstrate the different approaches to file processing and rule configuration in each tool.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Markdown lint tool
A tool to check markdown files and flag style issues.
Installation
Markdownlint is packaged in some distributions as well as distributed via RubyGems. Check the list below to see if it's packaged for your distribution, and if so, feel free to use your distros package manager to install it.
To install from rubygems, run:
gem install mdl
Alternatively you can build it from source:
git clone https://github.com/markdownlint/markdownlint
cd markdownlint
rake install
Note that you will need rake
(gem install rake
) and bundler
(gem install bundler
) in order to build from source.
Usage
To have markdownlint check your markdown files, simply run mdl
with the
filenames as a parameter:
mdl README.md
Markdownlint can also take a directory, and it will scan all markdown files within the directory (and nested directories):
mdl docs/
If you don't specify a filename, markdownlint will use stdin:
cat foo.md | mdl
Markdownlint will output a list of issues it finds, and the line number where the issue is. See RULES.md for information on each issue, as well as how to correct it:
README.md:1: MD013 Line length
README.md:70: MD029 Ordered list item prefix
README.md:71: MD029 Ordered list item prefix
README.md:72: MD029 Ordered list item prefix
README.md:73: MD029 Ordered list item prefix
Markdownlint has many more options you can pass on the command line, run
mdl --help
to see what they are, or see the documentation on
configuring markdownlint.
Styles
Not everyone writes markdown in the same way, and there are multiple flavors and styles, each of which are valid. While markdownlint's default settings will result in markdown files that reflect the author's preferred markdown authoring preferences, your project may have different guidelines.
It's not markdownlint's intention to dictate any one specific style, and in order to support these differing styles and/or preferences, markdownlint supports what are called 'style files'. A style file is a file describing which rules markdownlint should enable, and also what settings to apply to individual rules. For example, rule MD013 checks for long lines, and by default will report an issue for any line longer than 80 characters. If your project has a different maximum line length limit, or if you don't want to enforce a line limit at all, then this can be configured in a style file.
For more information on creating style files, see the creating styles document.
Custom rules and rulesets
It may be that the rules provided in this project don't cover your stylistic needs. To account for this, markdownlint supports the creation and use of custom rules.
For more information, see the creating rules document.
Related projects
- markdownlint - A similar project, but limited in Node.js
- markdownlint-cli - A CLI for the above Node.js project
- markdownlint-cli2 - An alternative CLI for the Node.js project
Contributing
See CONTRIBUTING.md for more information.
Top Related Projects
Markdown lint tool
:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
textlint is the pluggable linter for natural language text.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot