Suggestions for source formatting before syntax highlighting #3748
-
I'm not sure what the best way would be to approach this so asking for suggestions or opinions. I have a large number of markdown files that I have migrated to 11ty from earlier build systems (like Jekyll). Somehow some embedded example code sections have transferred correctly with original formatting/indenting and some have not. In some cases, the indentation has been partially or wholly stripped out at some point. There are enough of the files that spotting where the problems occur by hand/eye is a big task. Usually, each page has several code blocks embedded in the markdown using backticks e.g : #python example
while True:
if something:
print('this should be indented correctly') The language for each example chunk varies but my idea was to run prettier over each sample section using the appropriate language settings for each chunk so it would be corrected to: #python example
while True:
if something:
print('this should be indented correctly') Running prettier against the whole markdown file obviously won't take into account the varying requirements - markdown, html, python, javascript - for each portion of the file. I feel I could brute-force this by writing a program to go through all of the files, extract the code sample, run prettier against a temporary file, then copy back the result but I wonder if there's a more elegant and "11ty-ish" way to do it? I think prettier needs to run before the markdown processing and syntax highlighting run so that the indentation is fixed before converting to html. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Assuming this is a one off process, I'd probably go down the route you suggested: write a script to process all your markdown files.
If you're no good with regex, ask one other LLM's they are pretty good at writing them for you. Or ask it to just write the whole script for you. Alternatively, this is the sort of task that cursor could probably do for you. You could do this in a more 11ty style way by writing your code in |
Beta Was this translation helpful? Give feedback.
Assuming this is a one off process, I'd probably go down the route you suggested: write a script to process all your markdown files.
If you're no good with regex, ask one other LLM's they are pretty good at writing them for you. Or ask it to just write the whole script for you.
Alternatively, this is the sort of task that cursor could probably do for you.
You could do this in a more 11ty style way by writing your code in
[eleventy.before](https://www.11ty.dev/docs/events/#eleventy-before)
function. But then you…