Skip to content

Commit

Permalink
Merge branch 'master' into process-escaped-html-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasserra committed Mar 4, 2024
2 parents 2390b87 + 796e57f commit e5e73ca
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -4,7 +4,9 @@

- [pull #519] Add support for custom extras
- [pull #519] Drop Python 3.5 support
- [pull #568] Add `prepend` arg to toc extra (#397)
- [pull #569] Process HTML comments as markdown in 'escape' safe mode
- [pull #570] Fix syntax warnings in test suite


## python-markdown2 2.4.13
Expand Down
2 changes: 1 addition & 1 deletion lib/markdown2.py
Expand Up @@ -513,7 +513,7 @@ def toc_sort(entry):
self._toc_html = calculate_toc_html(self._toc)

# Prepend toc html to output
if self.cli:
if self.cli or (self.extras['toc'] is not None and self.extras['toc'].get('prepend', False)):
text = '{}\n{}'.format(self._toc_html, text)

text += "\n"
Expand Down
8 changes: 6 additions & 2 deletions test/test_markdown2.py
Expand Up @@ -14,6 +14,7 @@
import difflib
import doctest
from json import loads as json_loads
import warnings

sys.path.insert(0, join(dirname(dirname(abspath(__file__)))))
try:
Expand Down Expand Up @@ -150,11 +151,14 @@ def generate_tests(cls):
opts_path = splitext(text_path)[0] + ".opts"
if exists(opts_path):
try:
opts = eval(open(opts_path, 'r').read())
with warnings.catch_warnings(record=True) as caught_warnings:
opts = eval(open(opts_path, 'r').read())
for warning in caught_warnings:
print("WARNING: loading %s generated warning: %s - lineno %d" % (opts_path, warning.message, warning.lineno), file=sys.stderr)
except Exception:
_, ex, _ = sys.exc_info()
print("WARNING: couldn't load `%s' opts file: %s" \
% (opts_path, ex))
% (opts_path, ex), file=sys.stderr)

toc_html_path = splitext(text_path)[0] + ".toc_html"
if not exists(toc_html_path):
Expand Down
2 changes: 1 addition & 1 deletion test/testall.py
Expand Up @@ -68,7 +68,7 @@ def testall():
# capture and re-print stderr while process is running
line = proc.stderr.readline().decode().strip()
print(line, file=sys.stderr)
if 'WARNING:test:' in line:
if 'WARNING:' in line:
# if stderr contains a warning, save this for later
all_warnings.append((python, ver_str, line))

Expand Down
7 changes: 3 additions & 4 deletions test/tm-cases/link_patterns.opts
@@ -1,8 +1,7 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile("recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
(re.compile("(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
(re.compile("PEP\s+(\d+)", re.I), lambda m: "http://www.python.org/dev/peps/pep-%04d/" % int(m.group(1))),
(re.compile(r"recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
(re.compile(r"(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
(re.compile(r"PEP\s+(\d+)", re.I), lambda m: "http://www.python.org/dev/peps/pep-%04d/" % int(m.group(1))),
],
}

3 changes: 1 addition & 2 deletions test/tm-cases/link_patterns_double_hit.opts
@@ -1,7 +1,6 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile(r'mozilla\s+bug\s+(\d+)', re.I), r'http://bugzilla.mozilla.org/show_bug.cgi?id=\1'),
(re.compile("(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
(re.compile(r"(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
],
}

3 changes: 1 addition & 2 deletions test/tm-cases/link_patterns_edge_cases.opts
@@ -1,7 +1,6 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile("Blah\s+(\d+)", re.I), r"http://foo.com/blah_blah_blah/\1"),
(re.compile(r"Blah\s+(\d+)", re.I), r"http://foo.com/blah_blah_blah/\1"),
(re.compile("#([1-9][0-9]*)"), r"http://localhost/issue/\1"),
],
}

7 changes: 3 additions & 4 deletions test/tm-cases/link_patterns_escape.opts
@@ -1,8 +1,7 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile("recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
(re.compile("(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
(re.compile("PEP\s+(\d+)", re.I), lambda m: "http://www.python.org/dev/peps/pep-%04d/" % int(m.group(1))),
(re.compile(r"recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
(re.compile(r"(?:komodo\s+)?bug\s+(\d+)", re.I), r"http://bugs.activestate.com/show_bug.cgi?id=\1"),
(re.compile(r"PEP\s+(\d+)", re.I), lambda m: "http://www.python.org/dev/peps/pep-%04d/" % int(m.group(1))),
],
}

4 changes: 2 additions & 2 deletions test/tm-cases/link_patterns_hash_matching_issue287.opts
@@ -1,7 +1,7 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile("#(\d+)", re.I), r"https://github.com/pyfa-org/Pyfa/issues/\1"),
(re.compile("@(\w+)", re.I), r"https://github.com/\1"),
(re.compile(r"#(\d+)", re.I), r"https://github.com/pyfa-org/Pyfa/issues/\1"),
(re.compile(r"@(\w+)", re.I), r"https://github.com/\1"),
(re.compile("([0-9a-f]{6,40})", re.I), r"https://github.com/pyfa-org/Pyfa/commit/\1")
]
}
4 changes: 2 additions & 2 deletions test/tm-cases/link_patterns_markdown_syntax.opts
@@ -1,5 +1,5 @@
{"extras": ["link-patterns"],
"link_patterns": [
(re.compile("recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
(re.compile(r"recipe\s+(\d+)", re.I), r"http://code.activestate.com/recipes/\1/"),
],
}
}
40 changes: 40 additions & 0 deletions test/tm-cases/toc_prepend.html
@@ -0,0 +1,40 @@
<ul>
<li><a href="#readme-for-blah">README for Blah</a>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#the-meat">The Meat</a>
<ul>
<li><a href="#beef">Beef</a>
<ul>
<li><a href="#steak">Steak</a></li>
<li><a href="#burgers">Burgers</a></li>
</ul></li>
<li><a href="#chicken">Chicken</a></li>
<li><a href="#pork">Pork</a>
<ul>
<li><a href="#mmmmmmmm-bacon">Mmmmmmmm, bacon</a></li>
</ul></li>
</ul></li>
</ul></li>
<li><a href="#at-the-top-level-again">At the <em>top</em> level again!?</a></li>
</ul>

<h1 id="readme-for-blah">README for Blah</h1>

<h2 id="introduction">Introduction</h2>

<h2 id="the-meat">The Meat</h2>

<h3 id="beef">Beef</h3>

<h5 id="steak">Steak</h5>

<h5 id="burgers">Burgers</h5>

<h3 id="chicken">Chicken</h3>

<h3 id="pork">Pork</h3>

<h4 id="mmmmmmmm-bacon">Mmmmmmmm, bacon</h4>

<h1 id="at-the-top-level-again">At the <em>top</em> level again!?</h1>
1 change: 1 addition & 0 deletions test/tm-cases/toc_prepend.opts
@@ -0,0 +1 @@
{"extras": {"toc": {"prepend": True}}}
1 change: 1 addition & 0 deletions test/tm-cases/toc_prepend.tags
@@ -0,0 +1 @@
toc extra
20 changes: 20 additions & 0 deletions test/tm-cases/toc_prepend.text
@@ -0,0 +1,20 @@
# README for Blah

## Introduction

## The Meat

### Beef

##### Steak

##### Burgers

### Chicken

### Pork

#### Mmmmmmmm, bacon

# At the *top* level again!?

20 changes: 20 additions & 0 deletions test/tm-cases/toc_prepend.toc_html
@@ -0,0 +1,20 @@
<ul>
<li><a href="#readme-for-blah">README for Blah</a>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#the-meat">The Meat</a>
<ul>
<li><a href="#beef">Beef</a>
<ul>
<li><a href="#steak">Steak</a></li>
<li><a href="#burgers">Burgers</a></li>
</ul></li>
<li><a href="#chicken">Chicken</a></li>
<li><a href="#pork">Pork</a>
<ul>
<li><a href="#mmmmmmmm-bacon">Mmmmmmmm, bacon</a></li>
</ul></li>
</ul></li>
</ul></li>
<li><a href="#at-the-top-level-again">At the <em>top</em> level again!?</a></li>
</ul>

0 comments on commit e5e73ca

Please sign in to comment.