Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .bumpversion.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

93 changes: 63 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ on:

jobs:

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

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

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

steps:
- uses: actions/checkout@v2
Expand All @@ -25,40 +36,62 @@ jobs:
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 "poetry==1.1.5"
poetry config virtualenvs.create false
poetry install --no-interaction --no-ansi
pip install flit
flit install --deps=production --extras=test --pth-file

- name: Linters
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.7'
- name: Run pytest
run: |
pre-commit run -a
mypy .
pytest --cov=mdformat_myst --cov-report=xml --cov-report=term-missing

- name: Test with pytest
- name: Upload to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.8
uses: codecov/codecov-action@v1
with:
name: pytests
flags: pytests
file: ./coverage.xml
fail_ci_if_error: true

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.8

- name: Installation (deps and package)
run: |
pytest
pip install pre-commit
pip install .

pypi-publish:
# Only publish if all other jobs succeed
needs:
- build
- 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]
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install Poetry
run: |
pip install "poetry==1.1.5"
- name: Build and publish
run: |
# TODO: Remove the first command as soon as this Poetry bug is fixed: https://github.com/python-poetry/poetry/issues/2210
poetry config http-basic.pypi "__token__" "${POETRY_PYPI_TOKEN_PYPI}"
poetry build
poetry publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: install flit
run: |
pip install flit~=3.0
- name: Build and publish
run: |
flit publish
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_KEY }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ dmypy.json

# IntelliJ
.idea/

# VS Code
.vscode/
9 changes: 9 additions & 0 deletions .pre-commit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: local
hooks:
- id: mdformat
name: mdformat
entry: mdformat
files: "tests/pre-commit-test.md"
types: [markdown]
language: system
4 changes: 3 additions & 1 deletion mdformat_myst/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.1.3" # DO NOT EDIT THIS LINE MANUALLY. LET bump2version UTILITY DO IT
"""Mdformat plugin for MyST compatibility."""

__version__ = "0.1.3"
23 changes: 14 additions & 9 deletions mdformat_myst/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import re
from textwrap import indent

from markdown_it import MarkdownIt
import mdformat.plugins
Expand Down Expand Up @@ -90,16 +91,20 @@ def _footnote_ref_renderer(node: RenderTreeNode, context: RenderContext) -> str:


def _footnote_renderer(node: RenderTreeNode, context: RenderContext) -> str:
text = f"[^{node.meta['label']}]: "
child_iterator = iter(node.children)
first_child = next(child_iterator)
if first_child.type == "footnote_anchor":
return text
first_line = f"[^{node.meta['label']}]:"
elements = []
for child in node.children:
if child.type == "footnote_anchor":
continue
elements.append(child.render(context))
body = indent("\n\n".join(elements), " " * 4)
# if the first body element is a paragraph, we can start on the first line,
# otherwise we start on the second line
if body and node.children and node.children[0].type != "paragraph":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the body condition makes me think, what happens if not body. If that is valid syntax, I think it needs separate handling where no trailing space is added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is valid syntax, but yeh I can remove the trailing space. In fact it was removing it, but then I refactored the code slightly and forgot to "rehandle" it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it only works currently if there is a space, otherwise it is not recognized as a footnote.

I note though, that this is recognized as a footnote in VS Code previews (which uses markdown-it), so perhaps this is a bug in the plugin (albeit a quite unlikely scenario, that you would want a footnote with no text)

body = "\n" + body
else:
text += first_child.render(context)
for child in child_iterator:
text += "\n\n " + child.render(context)
return text
body = " " + body.lstrip()
return first_line + body


def _render_children(node: RenderTreeNode, context: RenderContext) -> str:
Expand Down
Loading