Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions naucse_render/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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:
Expand Down Expand Up @@ -132,9 +139,22 @@ def text_to_id(text):
class NaucseRenderer(mistune.HTMLRenderer):
code_tmpl = '<div class="highlight"><pre><code>{}</code></pre></div>'

def __init__(self, convert_url, *args, escape=False, **kwargs):
def __init__(
self,
convert_url,
*args,
escape=False,
allow_harmful_protocols=True,
Comment thread
hroncok marked this conversation as resolved.
Resolved
**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:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 id="co_programatorsky_editor_umi">Co programátorský editor umí
<p>...</p>
<div class="admonition note"><p>Pro ilustraci, takhle může v editoru vypadat kousek kódu:</p>
<div class="highlight"><pre><span></span> <span class="mi">1</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/courses/&lt;course:course&gt;/&#39;</span><span class="p">)</span>
<span class="mi">2</span> <span class="k">def</span> <span class="nf">course_page</span><span class="p">(</span><span class="n">course</span><span class="p">):</span>
<span class="mi">2</span> <span class="k">def</span><span class="w"> </span><span class="nf">course_page</span><span class="p">(</span><span class="n">course</span><span class="p">):</span>
<span class="mi">3</span> <span class="o">...</span>
</pre></div></div><h2 id="volba_a_nastaveni_editoru">Volba a nastavení editoru
<a href="#volba_a_nastaveni_editoru" class="header-link">#</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 id="co_programatorsky_editor_umi">Co programátorský editor umí
<p>...</p>
<div class="admonition note"><p>Pro ilustraci, takhle může v editoru vypadat kousek kódu:</p>
<div class="highlight"><pre><span></span> <span class="mi">1</span> <span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/courses/&lt;course:course&gt;/&#39;</span><span class="p">)</span>
<span class="mi">2</span> <span class="k">def</span> <span class="nf">course_page</span><span class="p">(</span><span class="n">course</span><span class="p">):</span>
<span class="mi">2</span> <span class="k">def</span><span class="w"> </span><span class="nf">course_page</span><span class="p">(</span><span class="n">course</span><span class="p">):</span>
<span class="mi">3</span> <span class="o">...</span>
</pre></div></div><h2 id="volba_a_nastaveni_editoru">Volba a nastavení editoru
<a href="#volba_a_nastaveni_editoru" class="header-link">#</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>This is the main page with links to subpages <a href="naucse:page?lesson=testcases/test_subpages&page=titled">one</a>, <a href="naucse:page?lesson=testcases/test_subpages&page=subtitled">two</a> and <a href="naucse:page?lesson=testcases/test_subpages&page=both-titles">three</a>.</p>
<p>This is the main page with links to subpages <a href="naucse:page?lesson=testcases/test_subpages&amp;page=titled">one</a>, <a href="naucse:page?lesson=testcases/test_subpages&amp;page=subtitled">two</a> and <a href="naucse:page?lesson=testcases/test_subpages&amp;page=both-titles">three</a>.</p>
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ data:
nd\">@app</span><span class=\"o\">.</span><span class=\"n\">route</span><span\
\ class=\"p\">(</span><span class=\"s1\">&#39;/courses/&lt;course:course&gt;/&#39;</span><span\
\ class=\"p\">)</span>\n <span class=\"mi\">2</span> <span\
\ class=\"k\">def</span> <span class=\"nf\">course_page</span><span\
\ class=\"p\">(</span><span class=\"n\">course</span><span class=\"\
p\">):</span>\n <span class=\"mi\">3</span> <span class=\"\
o\">...</span>\n</pre></div></div><h2 id=\"volba_a_nastaveni_editoru\"\
>Volba a nastaven\xED editoru\n<a href=\"#volba_a_nastaveni_editoru\"\
\ class=\"header-link\">#</a>\n</h2>\n<p>...</p>\n<ul>\n<li><a\
\ href=\"naucse:page?lesson=beginners/install-editor&amp;page=atom\"\
\ class=\"k\">def</span><span class=\"w\"> </span><span class=\"\
nf\">course_page</span><span class=\"p\">(</span><span class=\"\
n\">course</span><span class=\"p\">):</span>\n <span class=\"\
mi\">3</span> <span class=\"o\">...</span>\n</pre></div></div><h2\
\ id=\"volba_a_nastaveni_editoru\">Volba a nastaven\xED editoru\n\
<a href=\"#volba_a_nastaveni_editoru\" class=\"header-link\">#</a>\n\
</h2>\n<p>...</p>\n<ul>\n<li><a href=\"naucse:page?lesson=beginners/install-editor&amp;page=atom\"\
>Atom</a> \u2013 doporu\u010Den\xFD editor pro\nWindows a macOS.</li>\n\
</ul>\n<p>...</p>\n<ul>\n<li><a href=\"naucse:page?lesson=beginners/install-editor&amp;page=gedit\"\
>Gedit</a> \u2013 b\xFDv\xE1 na syst\xE9mech s\_prost\u0159ed\xED\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ data:
index:
attribution:
- Petr Viktorin
content: <p>This is the main page with links to subpages <a href="naucse:page?lesson=testcases/test_subpages&page=titled">one</a>,
<a href="naucse:page?lesson=testcases/test_subpages&page=subtitled">two</a>
and <a href="naucse:page?lesson=testcases/test_subpages&page=both-titles">three</a>.</p>
content: <p>This is the main page with links to subpages <a href="naucse:page?lesson=testcases/test_subpages&amp;page=titled">one</a>,
<a href="naucse:page?lesson=testcases/test_subpages&amp;page=subtitled">two</a>
and <a href="naucse:page?lesson=testcases/test_subpages&amp;page=both-titles">three</a>.</p>
ids: []
license: cc0
links:
Expand Down
4 changes: 2 additions & 2 deletions test_naucse_render/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def test_convert_with_prompt_spaces_pycon():
""")
expected = dedent("""
<div class="highlight"><pre><span></span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span>
<span class="nf">foo</span><span class="p">(</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span><span class="w">
</span><span class="nf">foo</span><span class="p">(</span>
<span class="n">req</span><span class="p">):</span>
<span class="gp">... </span>
<span class="k">return</span> <span class="n">req</span>
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{38,39,310,311,312}
envlist = py{311,312,313,314,315}
isolated_build = True

[testenv]
Expand Down
Loading