tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
361 stars 14 forks source link

Support for formatting SQL code blocks in Markdown #593

Open michael-the1 opened 1 month ago

michael-the1 commented 1 month ago

It would be really nice if sqlfmt would support formatting SQL code blocks in Markdown files. In the context of dbt, this would also be very beneficial. We put a lot of example queries in our documentation and it would be amazing if they followed the same style.

Before

# Some title

Some text

```sql
SELECT * FROM some.table

## After

``````markdown
# Some title

Some text

```sql
select * from some.table


In terms of requirements, I think limiting to `sql` blocks within `.md` files would be enough.
tconbeer commented 1 month ago

I like this idea.

I think we'd support this by installing a markdown parser as an extra (e.g., mistletoe or marko), iterating through the code blocks in the AST, and replacing their contents.

Right now we ignore .md files, but that can be changed via config.

PRs very welcome!

michael-the1 commented 1 month ago

Looks doable! I'm able to spend some time on this so I'll try to get a PR up sometime in the next two weeks.