Comments (3)
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! 🎉
from mdformat.
Frontmatter is not a CommonMark rule so there is not support for it in mdformat without plugins. Does installing mdformat-frontmatter
plugin solve your problem?
from mdformat.
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 ---
with a long line of ---------------------------
. But there are other rules I wanted to disable, that was just an example. In fact, I only wanted one rule. I ended up hacking together a Python script with ChatGPT to do it instead and checking its output by hand
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()
adambard/learnxinyminutes-docs@01bbd08
from mdformat.
Related Issues (20)
- Escape "\|" not working in table cell HOT 3
- Support XGG base directory specification for user configuration resolution
- Checkboxes are escaped HOT 3
- mdformat breaks Hugo shortcodes by escaping `<` HOT 5
- markdown-it-py 3 support
- Not Working In Python 3.11? HOT 5
- Error: Could not format HOT 2
- Alt text wrapped in grave marks is deleted HOT 2
- Formatted md renders different html than original md HOT 2
- image path is falsely patched with `<>` if URL includes `()`, breaks render HOT 5
- Double slash in math formular HOT 3
- Incorrecly reformats python code HOT 1
- convert inline links to references? HOT 2
- Support json schema
- Word-wrap on sentence (punctuation) and width. HOT 1
- Inline elements in image descriptions are flattened and stripped HOT 2
- Numbers in ordererd lists are ignored when using MDRenderer/MDFormat HOT 3
- Feature request: Respect .gitignore'd files HOT 1
- Checkbox convert HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdformat.