Skip to content

Commit

Permalink
debug mkdocs indent issues (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing authored Apr 6, 2023
1 parent b50e475 commit ffc4d1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 24 deletions.
16 changes: 1 addition & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
---
name: CI

on:
push:
branches: [main]
tags:
- v*
tags: [v*]
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.10'
- uses: pre-commit/action@v2.0.0

tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, '3.10']
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Installation (deps and package)
# we install with flit --pth-file,
# so that coverage will be recorded for the module
run: |
pip install flit
flit install --deps=production --extras=test --pth-file
- name: Run pytest
run: |
pytest --cov=mdformat_admon --cov-report=xml --cov-report=term-missing
Expand All @@ -54,26 +45,21 @@ jobs:
# flags: pytests
# file: ./coverage.xml
# fail_ci_if_error: false

pre-commit-hook:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Installation (deps and package)
run: |
pip install pre-commit
pip install .
- name: run pre-commit with plugin
run: |
pre-commit run --config .pre-commit-test.yaml --all-files --verbose --show-diff-on-failure
publish:
name: Publish to PyPi
needs: [pre-commit, tests, pre-commit-hook]
Expand Down
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ repos:
- id: trailing-whitespace
exclude: tests/fixtures.*\.md
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- repo: https://github.com/timothycrosley/isort
rev: 5.11.4
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
Expand All @@ -51,12 +51,11 @@ repos:
rev: 0.7.16
hooks:
- id: mdformat
additional_dependencies:
- mdformat-mkdocs[recommended]
additional_dependencies: ['mdformat-mkdocs[recommended]']
exclude: tests/.+\.md
args: [--wrap=no]
- repo: https://github.com/lyz-code/yamlfix/
rev: 1.1.1
rev: 1.9.0
hooks:
- id: yamlfix
types_or: []
Expand Down
6 changes: 3 additions & 3 deletions mdformat_mkdocs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def update_mdit(mdit: MarkdownIt) -> None:
...


_RE_INDENT = re.compile(r"(?P<indent>\s*)(?P<content>.*)")
_RE_INDENT = re.compile(r"(?P<indent>\s*)(?P<content>[^\s]?.*)")
"""Match `indent` and `content` against line`."""

_RE_LIST_ITEM = re.compile(r"(?P<bullet>[\-\*\d\.]+)\s+(?P<item>.+)")
Expand All @@ -23,7 +23,7 @@ def update_mdit(mdit: MarkdownIt) -> None:

def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) -> str:
"""Post-processor to normalize lists."""
eol = "\n" # PLANNED: Does this need to support carriage returns?
eol = "\n"
indent = " " * _MKDOCS_INDENT_COUNT

rendered = ""
Expand Down Expand Up @@ -53,7 +53,7 @@ def _normalize_list(text: str, node: RenderTreeNode, context: RenderContext) ->
raise NotImplementedError(f"Error in indentation of: `{line}`")
else:
indent_counter = 0
last_indent = match["indent"]
last_indent = this_indent
new_indent = indent * indent_counter
rendered += f"{new_indent}{new_line.strip()}{eol}"
return rendered.rstrip()
Expand Down

0 comments on commit ffc4d1f

Please sign in to comment.