-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: Support parsing of SQL code blocks in Markdown files #598
Open
michael-the1
wants to merge
18
commits into
tconbeer:main
Choose a base branch
from
michael-the1:markdown-parsing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4644492
Format SQL code blocks in .md files
michael-the1 855760c
Update CHANGELOG
michael-the1 68d51ba
Only parse Markdown files if mistletoe is installed
michael-the1 814b668
Use importlib.util.find_spec to check for mistletoe
michael-the1 cb7d218
Return tuple from included_file_extensions
michael-the1 9ed1fcf
Add missing test files
michael-the1 b622a65
Guard against formatting markdown files while mistletoe is not installed
michael-the1 d764a03
Merge branch 'main' into markdown-parsing
tconbeer fe766b9
Fix typo in CHANGELOG.md
tconbeer 02a4aae
Add mistletoe to dev dependencies
michael-the1 3de685f
Remove mistletoe from dev dependencies, fix workflows
michael-the1 6b6f1f2
Make flake8 and mypy happy
michael-the1 58bc61e
Fix edge case where BlockToken has no children
michael-the1 35ace60
Fix mypy by ignoring missing imports for mistletoe
michael-the1 8789c73
sqlfmt_primer: Fix expected values
michael-the1 bd6b9f1
Merge remote-tracking branch 'origin/main' into markdown-parsing
michael-the1 1c85282
Make the new linters happy
michael-the1 b366e56
Merge branch 'main' into markdown-parsing
michael-the1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Hello | ||
|
||
```sql | ||
select 1 | ||
``` |
9 changes: 9 additions & 0 deletions
9
tests/data/fast/preformatted/008_markdown_file_without_sql_blocks.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Hello again | ||
|
||
```python | ||
import antigravity | ||
``` | ||
|
||
``` | ||
SELECT 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Hello | ||
|
||
```sql | ||
SELECT 1 | ||
``` | ||
)))))__SQLFMT_OUTPUT__((((( | ||
# Hello | ||
|
||
```sql | ||
select 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Hello | ||
|
||
This is some SQL code in a `sql` code block: | ||
|
||
```sql | ||
select 1 | ||
``` | ||
|
||
SQL code, but it's not a `sql` code block so it shouldn't get formatted: | ||
|
||
``` | ||
SELECT 2 | ||
``` | ||
|
||
And finally, some bash code | ||
|
||
```bash | ||
echo "Hello, world!" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Hello | ||
|
||
```sql | ||
-- fmt: off | ||
SELECT 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Hello | ||
|
||
```sql | ||
SELECT 1 | ||
``` | ||
)))))__SQLFMT_OUTPUT__((((( | ||
# Hello | ||
|
||
```sql | ||
select 1 | ||
``` |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wrap this in
try ... except ImportError
and either return the source or re-raise aSqlfmtError
to create a nicer error message for users who don't have the extra installed. I know right now we shouldn't hit that codepath due to the Mode property, but would be good to safeguard against that changing in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the
try ... except
guard. I went ahead and subclassedSqlfmtError
since I didn't see any bareraise SqlfmtError
anywhere.