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
65 changes: 65 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
code-quality:
runs-on: ubuntu-latest

name: "Linting"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: setup python
uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install dependencies
run: make install

- name: Linting
run: make lint

test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: "Python ${{ matrix.python-version }}"

steps:
- name: Check out code
uses: actions/checkout@v4

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

- name: Install dependencies
run: make install

- name: Run tests
run: make coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
flags: unittests-${{ matrix.python-version }}
fail_ci_if_error: true # default = false
verbose: true # default = false
33 changes: 33 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish to PyPI

on:
release:
types: [released]

jobs:
release:
name: Release
environment:
name: pypi
url: https://pypi.org/project/django-markwhat
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Build
run: |
python -m pip install build
python -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
print-hash: true
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IDE specific
.idea/
.ropeproject/
.vscode/
# file
manage.py
dump.json
Expand Down Expand Up @@ -37,6 +38,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
django_markwhat/_version.py

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -70,6 +72,3 @@ docs/_build/

# PyBuilder
target/

# virtualenv
ve/
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2025.5.31
=========
----

* Upgrade all the dependecies to latest version.
* Modernize the build and development tooling process.


1.6.2 2019-08-30
================
----
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: install test build release clean

install:
pip install '.[dev]'

test:
python run_tests.py

coverage:
coverage run run_tests.py
coverage report
coverage xml

build:
python -m build

clean:
rm -rf dist *.egg-info coverage.xml build

lint:
ruff format
ruff check . --fix
mypy . --install-types --non-interactive --exclude build
1 change: 0 additions & 1 deletion django_markwhat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
"""Django Markwhat."""
__version__ = (1, 6, 2)
70 changes: 25 additions & 45 deletions django_markwhat/templatetags/markup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Set of "markup" template filters for Django.

These filters transform plain text
markup syntaxes to HTML; currently there is support for:

Expand All @@ -16,29 +17,31 @@

from django import template
from django.conf import settings
from django.utils.encoding import force_str
from django.utils.encoding import force_str, smart_str
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter(is_safe=True)
def textile(value):
def textile(value: str) -> str:
"""
:type value: str
Runs textile over a given value.

Syntax::

:rtype: str
{{ value|textile }}
"""
import textile
import textile # type: ignore[import-untyped]

return mark_safe(force_str(
textile.textile(smart_str(value)))
)
return mark_safe(force_str(textile.textile(smart_str(value))))


@register.filter(is_safe=True)
def markdown(value, args=''):
def markdown(value: str, args: str = "") -> str:
"""
Markdown Template tag.

Runs Markdown over a given value, optionally using various
extensions python-markdown supports.

Expand All @@ -52,68 +55,45 @@ def markdown(value, args=''):

If the version of Markdown in use does not support extensions,
they will be silently ignored.

:type value: str
:type args: str

:rtype: str
"""
import markdown

extensions = [e for e in args.split(',') if e]
extensions = [e for e in args.split(",") if e]
if len(extensions) > 0 and extensions[0] == "safe":
extensions = extensions[1:]
safe_mode = True
else:
safe_mode = False

return mark_safe(markdown.markdown(
force_str(value),
extensions=extensions,
safe_mode=safe_mode,
enable_attributes=(not safe_mode)
))
return mark_safe(markdown.markdown(force_str(value), extensions=extensions))


@register.filter(is_safe=True)
def commonmark(value):
def commonmark(value: str) -> str:
"""
Runs commonmark over a given value.

Syntax::

{{ value|commonmark }}

:type value: str

:rtype: str
"""
import commonmark

parser = commonmark.Parser()
renderer = commonmark.HtmlRenderer()
ast = parser.parse(force_str(value))
return mark_safe(
force_str(renderer.render(ast))
)
return mark_safe(force_str(renderer.render(ast)))


@register.filter(is_safe=True)
def restructuredtext(value):
def restructuredtext(value: str) -> str:
"""
:type value: str
:rtype: str
Runs restructured text over a given value.

Syntax::

{{ value|restructuredtext }}
"""
""""""
from docutils.core import publish_parts

docutils_settings = getattr(
settings,
"RESTRUCTUREDTEXT_FILTER_SETTINGS",
{}
)
parts = publish_parts(
source=smart_str(value),
writer_name="html4css1",
settings_overrides=docutils_settings
)
docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
return mark_safe(force_str(parts["fragment"]))
Loading