diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 193ec92..3703405 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -18,7 +18,7 @@ jobs: tox_env: ${{ matrix.tox_env }} strategy: matrix: - tox_env: [py38, py39, py310, py311, py312] + tox_env: [py311, py312, py313, py314] # Use GitHub's Linux Docker host runs-on: ubuntu-latest diff --git a/README.md b/README.md index e4ac771..0f7cd85 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,13 @@ licensed under the same license. ## Changelog +### naucse_render 2.1 + +* Update to mistune 3.3. This changes parsing & formatting for Markdown again. + In most cases the differences should be superficial. + +* Tested with Python 3.11-3.15 + ### naucse_render 2.0 * Update to mistune 3.x & nbconvert 7.x. This changes parsing & formatting diff --git a/naucse_render/markdown.py b/naucse_render/markdown.py index 0abb534..b5dc026 100644 --- a/naucse_render/markdown.py +++ b/naucse_render/markdown.py @@ -25,12 +25,13 @@ def naucse_admonition_plugin(md): # out how to write a plugin") ADMONITION_NAME_PATTERN = re.compile(r' *\[(\S+)\]([^\n]*)\n') - def parse_naucse_admonition(block, m, state): + text, end_pos, lazy_line_starts = block.extract_block_quote(m, state) - text, end_pos = block.extract_block_quote(m, state) name_match = ADMONITION_NAME_PATTERN.match(text) - if name_match: + + depth = state.depth() + if not depth and name_match: # It's an admonition token = { 'type': 'naucse_admonition', @@ -45,8 +46,14 @@ def parse_naucse_admonition(block, m, state): 'type': 'block_quote', } - child = state.child_state(text) - rules = block.block_quote_rules + # scan children state + child = state.child_state(text, lazy_line_starts=lazy_line_starts) + if state.depth() >= block.max_nested_level - 1: + rules = list(block.block_quote_rules) + rules.remove("block_quote") + else: + rules = block.block_quote_rules + block.parse(child, rules) token['children'] = child.tokens if end_pos: @@ -132,9 +139,20 @@ def text_to_id(text): class NaucseRenderer(mistune.HTMLRenderer): code_tmpl = '
{}
' - def __init__(self, convert_url, *args, escape=False, **kwargs): + def __init__( + self, + convert_url, + *args, + **kwargs, + ): self._convert_url = convert_url - super().__init__(*args, **kwargs, escape=False) + super().__init__( + *args, **kwargs, + # We check the resulting HTML, so we don't sanitization + # in the Markdown->HTML translation + escape=False, + allow_harmful_protocols=True, + ) def naucse_admonition(self, text, title, name): if title: diff --git a/pyproject.toml b/pyproject.toml index 53dfcca..631e480 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,14 +7,14 @@ name = "naucse_render" version = '2.0' description = 'Converts course material to naucse.python.cz API' readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.11" classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", ] dependencies = [ 'ansi2html', - 'mistune>=2.0.3,<4', + 'mistune>=3.3.0,<4', 'nbconvert>=7.0,<8.0', 'traitlets', 'click', diff --git a/test_naucse_render/fixtures/expected-compiled/default/install-editor/index.html b/test_naucse_render/fixtures/expected-compiled/default/install-editor/index.html index eb28f9a..6351001 100644 --- a/test_naucse_render/fixtures/expected-compiled/default/install-editor/index.html +++ b/test_naucse_render/fixtures/expected-compiled/default/install-editor/index.html @@ -14,7 +14,7 @@

Co programátorský editor umí

...

Pro ilustraci, takhle může v editoru vypadat kousek kódu:

    1  @app.route('/courses/<course:course>/')
-    2  def course_page(course):
+    2  def course_page(course):
     3      ...
 

Volba a nastavení editoru # diff --git a/test_naucse_render/fixtures/expected-compiled/lessons/install-editor/index.html b/test_naucse_render/fixtures/expected-compiled/lessons/install-editor/index.html index eb28f9a..6351001 100644 --- a/test_naucse_render/fixtures/expected-compiled/lessons/install-editor/index.html +++ b/test_naucse_render/fixtures/expected-compiled/lessons/install-editor/index.html @@ -14,7 +14,7 @@

Co programátorský editor umí

...

Pro ilustraci, takhle může v editoru vypadat kousek kódu:

    1  @app.route('/courses/<course:course>/')
-    2  def course_page(course):
+    2  def course_page(course):
     3      ...
 

Volba a nastavení editoru # diff --git a/test_naucse_render/fixtures/expected-compiled/lessons/test_subpages/index.html b/test_naucse_render/fixtures/expected-compiled/lessons/test_subpages/index.html index f305c88..1c31e54 100644 --- a/test_naucse_render/fixtures/expected-compiled/lessons/test_subpages/index.html +++ b/test_naucse_render/fixtures/expected-compiled/lessons/test_subpages/index.html @@ -1 +1 @@ -

This is the main page with links to subpages one, two and three.

\ No newline at end of file +

This is the main page with links to subpages one, two and three.

\ No newline at end of file diff --git a/test_naucse_render/fixtures/expected-dumps/beginners/install-editor.yaml b/test_naucse_render/fixtures/expected-dumps/beginners/install-editor.yaml index 2a2be7c..abbc023 100644 --- a/test_naucse_render/fixtures/expected-dumps/beginners/install-editor.yaml +++ b/test_naucse_render/fixtures/expected-dumps/beginners/install-editor.yaml @@ -98,13 +98,13 @@ data: nd\">@app.route('/courses/<course:course>/')\n 2 def course_page(course):\n 3 ...\n

Volba a nastaven\xED editoru\n#\n

\n

...

\n
    \n
  • def course_page(course):\n 3 ...\nVolba a nastaven\xED editoru\n\ + #\n\ +

\n

...

\n\n

...

\n