Skip to content
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

inconsistent indenting of nested lists #371

Closed
afeld opened this issue Dec 8, 2022 · 4 comments
Closed

inconsistent indenting of nested lists #371

afeld opened this issue Dec 8, 2022 · 4 comments
Labels
question Further information is requested

Comments

@afeld
Copy link

afeld commented Dec 8, 2022

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 #331 (comment) 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)
@afeld afeld added the bug Something isn't working label Dec 8, 2022
@welcome
Copy link

welcome bot commented Dec 8, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

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! 🎉

@hukkin
Copy link
Member

hukkin commented Dec 15, 2022

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

The logic here is as follows:

  • mdformat always indents unordered lists with two spaces
  • indent width of ordered lists depends on the width of the initial number of the ordered list
    1. Here indent width is
       three.
    
    123. Here indent width is
         five. It needs to be so, because
    
         Otherwise this next paragraph doesn't belong in the same list item.

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.

@hukkin hukkin added question Further information is requested and removed bug Something isn't working labels Dec 15, 2022
@KyleKing
Copy link
Contributor

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

@hukkin
Copy link
Member

hukkin commented Jan 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants