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 = '
{}...
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 ...
...
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 ...
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...
\n...
\n...
\nThis is the main page with links to subpages one, - two - and three.
+ content:This is the main page with links to subpages one, + two + and three.
ids: [] license: cc0 links: diff --git a/test_naucse_render/test_markdown.py b/test_naucse_render/test_markdown.py index 787cf94..c8a68ab 100644 --- a/test_naucse_render/test_markdown.py +++ b/test_naucse_render/test_markdown.py @@ -226,8 +226,8 @@ def test_convert_with_prompt_spaces_pycon(): """) expected = dedent("""
- >>> def
- foo(
+ >>> def
+ foo(
req):
...
return req
diff --git a/tox.ini b/tox.ini
index 5b3e97d..3692f57 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py{38,39,310,311,312}
+envlist = py{311,312,313,314,315}
isolated_build = True
[testenv]