New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options to disable/enable rules #431
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
Frontmatter is not a CommonMark rule so there is not support for it in mdformat without plugins. Does installing |
I have it installed, that's why it's formatting the frontmatter. Without it installed the mdformat treats it as markdown and completely destroys it, starting by replacing import sys
import glob
def process_files(filenames):
for filename in filenames:
with open(filename, "r") as file:
lines = file.readlines()
code_fence_count = [0] * len(lines)
for i, line in enumerate(lines):
if i > 0:
code_fence_count[i] = code_fence_count[i-1]
if line.strip().startswith("```"):
code_fence_count[i] += 1
save = False
modified_lines = []
for i, line in enumerate(lines):
if line.strip().startswith("```"):
if "groovy" in filename and 'ca-es' in filename:
pass
is_starting_fence = code_fence_count[i] % 2 == 1
if is_starting_fence:
if i > 0 and lines[i-1].strip():
save = True
modified_lines.append("\n")
# Remove any empty lines immediately after the opening fence
while i + 1 < len(lines) and not lines[i+1].strip():
i += 1
else:
# Remove any empty lines immediately before the closing fence
while modified_lines and not modified_lines[-1].strip():
modified_lines.pop()
if i < len(lines) - 1 and lines[i+1].strip():
line += "\n"
modified_lines.append(line)
if save and not "markdown" in filename.removesuffix(".markdown") and "vim" not in filename and "livescript" not in filename:
with open(filename, "w") as file:
file.writelines(modified_lines)
def main():
if len(sys.argv) > 1:
filenames = sys.argv[1:]
else:
# Process all .md and .markdown files in the current directory
filenames = glob.glob("**/*.md") + glob.glob("**/*.markdown")
process_files(filenames)
if __name__ == "__main__":
main() |
Context
I want to format a bunch of markdown files, but I don't want to apply all the rules, just one important rule.
For example, I have this in my frontmatter
which is changing the indentation and removing the quotes around the name. I don't want this.
Proposal
A syntax like https://github.com/markdownlint/markdownlint has for enabling/disabling rules
Tasks and updates
No response
The text was updated successfully, but these errors were encountered: