executablebooks / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
439 stars 46 forks source link

inconsistent indenting of nested lists #371

Closed afeld closed 1 year ago

afeld commented 1 year ago

Describe the bug

context When I run MdFormat on this notebook through nbqa

expectation I expected to get nested lists indented a certain number of spaces.

bug But instead some are indented two spaces, while some are indented three.

diff --git hw_0.ipynb hw_0.ipynb
index 4aaa010..ef99e82 100644
--- hw_0.ipynb
+++ hw_0.ipynb
@@ -11,16 +11,16 @@
     "Kaggle, like JupyterHub and Google Colab, is built around Jupyter notebooks. They are not _exactly_ the same, but will feel similar. For this homework
:\n",
     "\n",
     "1. Do following Kaggle [Learn Python](https://www.kaggle.com/learn/python) tutorials and exercises. You do not need to turn these in.\n",
-    "    - [Hello, Python](https://www.kaggle.com/colinmorris/hello-python)\n",
-    "    - [Booleans and Conditionals](https://www.kaggle.com/colinmorris/booleans-and-conditionals)\n",
-    "    - [Strings and Dictionaries](https://www.kaggle.com/colinmorris/strings-and-dictionaries)\n",
+    "   - [Hello, Python](https://www.kaggle.com/colinmorris/hello-python)\n",
+    "   - [Booleans and Conditionals](https://www.kaggle.com/colinmorris/booleans-and-conditionals)\n",
+    "   - [Strings and Dictionaries](https://www.kaggle.com/colinmorris/strings-and-dictionaries)\n",
     "1. Read about:\n",
-    "    - [Tuples, lists, and dictionaries](http://sthurlow.com/python/lesson06/)\n",
-    "    - [Errors and exceptions](https://swcarpentry.github.io/python-novice-inflammation/09-errors/index.html)\n",
+    "   - [Tuples, lists, and dictionaries](http://sthurlow.com/python/lesson06/)\n",
+    "   - [Errors and exceptions](https://swcarpentry.github.io/python-novice-inflammation/09-errors/index.html)\n",
     "1. Do the coding challenges below.\n",
     "1. Do the following Kaggle tutorials and exercises. You do not need to turn these in.\n",
-    "    - [Python Lists](https://www.kaggle.com/colinmorris/lists)\n",
-    "    - [Creating, Reading, and Writing with Pandas](https://www.kaggle.com/residentmario/creating-reading-and-writing)\n",
+    "   - [Python Lists](https://www.kaggle.com/colinmorris/lists)\n",
+    "   - [Creating, Reading, and Writing with Pandas](https://www.kaggle.com/residentmario/creating-reading-and-writing)\n",
     "1. Post a question, per the instructions at the bottom.\n",
     "1. [Turn in this notebook.](https://python-public-policy.afeld.me/en/latest/README.html#turning-in-assignments)\n",
     "\n",
@@ -163,8 +163,8 @@
     "We will now make an interactive tool to assess people for unemployment benefits. We will use a simplified version of [the rules from the New York Stat
e Department of Labor](https://www.labor.ny.gov/formsdocs/ui/TC318.3e.pdf#page=18), as follows. To be elegible, one must:\n",
     "\n",
     "- Have lost employment\n",
-    "- Have made at least $10,000 in the past year\n",
-    "    - Ask for their salary rather than as a yes-or-no question\n",
+    "- Have made at least \\$10,000 in the past year\n",
+    "  - Ask for their salary rather than as a yes-or-no question\n",
     "- Be ready, willing and able to work immediately\n",
     "- Be actively seeking work\n",
     "\n",

problem This is a problem because I'm publishing that notebook via JupyterBook, and it's Markdown parser only seems to support nested lists indented 3+ spaces.

cc https://github.com/executablebooks/mdformat/issues/331#issuecomment-1224279288 for the option to make that configurable for more fragile Markdown parsers

Reproduce the bug

  1. Download this notebook
  2. Run Mdformat through nbqa:

    nbqa mdformat hw_0.ipynb --nbqa-md

List your environment

$ jupyter-book --version
Jupyter Book      : 0.13.1
External ToC      : 0.2.4
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.3.3
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.13
$ nbqa --version
nbqa 1.5.3
$ mdformat --version
mdformat 0.7.16 (mdformat_myst: 0.1.5, mdformat_tables: 0.4.1, mdformat_frontmatter: 0.4.1)
welcome[bot] commented 1 year ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
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! :tada:

hukkin commented 1 year ago

But instead some are indented two spaces, while some are indented three.

The logic here is as follows:

This is a problem because I'm publishing that notebook via JupyterBook, and it's Markdown parser only seems to support nested lists indented 3+ spaces.

Hmm, are you 100% sure about this? I'm doubtful, because JupyterBook uses myst-nb which uses myst-parser which uses markdown-it-py to parse Markdown, and that is a CommonMark compliant parser which happens to be the same exact parser used by mdformat.

KyleKing commented 1 year ago

I published mdformat-mkdocs to format list indents to 4-spaces, which might be helpful for your use case

hukkin commented 1 year ago

This is a problem because I'm publishing that notebook via JupyterBook, and it's Markdown parser only seems to support nested lists indented 3+ spaces.

Closing, as this issue should be fixed now by installing KyleKing's mdformat-mkdocs plugin.