context
When I pass in a code block such as below. (notice the indented inner class)
click to expand
```
1. Add a serializer class
```python
class RecurringEventSerializer(serializers.ModelSerializer): # (1)!
"""Used to retrieve recurring_event info"""
class Meta:
model = RecurringEvent # (2)!
fields = (
"uuid",
"name",
"start_time",
"duration_in_min",
"video_conference_url",
"additional_info",
"project",
)
read_only_fields = (
"uuid", # (3)!
"created_at",
"updated_at",
)
```
```
expectation
I expected mdformat to either:
ignore the block
leave it alone because it knows that python inner classes are indented from the outer class
bug
But instead it re-indents the inner class to the same level as the outer class.
Here's the output... (where the error is the un-indented inner class code)
click to expand
```
1. Add a serializer class
```python
class RecurringEventSerializer(serializers.ModelSerializer): # (1)!
"""Used to retrieve recurring_event info"""
class Meta:
model = RecurringEvent # (2)!
fields = (
"uuid",
"name",
"start_time",
"duration_in_min",
"video_conference_url",
"additional_info",
"project",
)
read_only_fields = (
"uuid", # (3)!
"created_at",
"updated_at",
)
```
```
problem
This is a problem for people creating programming guides because readers can't run the code they copy/pasted from the documentation.
Reproduce the bug
I uninstalled mdformat from my system to to eliminate possiblities.
I have the original text in a file called test.md
click to expand
```
1. Add a serializer class
```python
class RecurringEventSerializer(serializers.ModelSerializer): # (1)!
"""Used to retrieve recurring_event info"""
class Meta:
model = RecurringEvent # (2)!
fields = (
"uuid",
"name",
"start_time",
"duration_in_min",
"video_conference_url",
"additional_info",
"project",
)
read_only_fields = (
"uuid", # (3)!
"created_at",
"updated_at",
)
```
```
Describe the bug
context When I pass in a code block such as below. (notice the indented inner class)
click to expand
``` 1. Add a serializer class ```python class RecurringEventSerializer(serializers.ModelSerializer): # (1)! """Used to retrieve recurring_event info""" class Meta: model = RecurringEvent # (2)! fields = ( "uuid", "name", "start_time", "duration_in_min", "video_conference_url", "additional_info", "project", ) read_only_fields = ( "uuid", # (3)! "created_at", "updated_at", ) ``` ```expectation I expected mdformat to either:
bug But instead it re-indents the inner class to the same level as the outer class. Here's the output... (where the error is the un-indented inner class code)
click to expand
``` 1. Add a serializer class ```python class RecurringEventSerializer(serializers.ModelSerializer): # (1)! """Used to retrieve recurring_event info""" class Meta: model = RecurringEvent # (2)! fields = ( "uuid", "name", "start_time", "duration_in_min", "video_conference_url", "additional_info", "project", ) read_only_fields = ( "uuid", # (3)! "created_at", "updated_at", ) ``` ```problem This is a problem for people creating programming guides because readers can't run the code they copy/pasted from the documentation.
Reproduce the bug
I uninstalled mdformat from my system to to eliminate possiblities.
I have the original text in a file called
test.md
click to expand
``` 1. Add a serializer class ```python class RecurringEventSerializer(serializers.ModelSerializer): # (1)! """Used to retrieve recurring_event info""" class Meta: model = RecurringEvent # (2)! fields = ( "uuid", "name", "start_time", "duration_in_min", "video_conference_url", "additional_info", "project", ) read_only_fields = ( "uuid", # (3)! "created_at", "updated_at", ) ``` ```My pre-commit config for mdformat:
click to expand
``` - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: - id: mdformat ```There's no plugin being used.
I call the mdformat pre-commit hook on this file
List your environment
mdformat revision (from pre-commit config) 0.7.17
❯ python --version Python 3.11.4
❯ pre-commit --version pre-commit 3.0.4
OS: Linux Mint 21.1 Vera. Based on Ubuntu Xenial I think.