From dfc2f0faec4b89c3f13425c6e370dce4ad476445 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 17 Feb 2024 14:29:02 +0000 Subject: [PATCH 1/5] Add `prepend` arg to toc extra --- lib/markdown2.py | 2 +- test/tm-cases/toc_prepend.html | 40 ++++++++++++++++++++++++++++++ test/tm-cases/toc_prepend.opts | 1 + test/tm-cases/toc_prepend.tags | 1 + test/tm-cases/toc_prepend.text | 20 +++++++++++++++ test/tm-cases/toc_prepend.toc_html | 20 +++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/toc_prepend.html create mode 100644 test/tm-cases/toc_prepend.opts create mode 100644 test/tm-cases/toc_prepend.tags create mode 100644 test/tm-cases/toc_prepend.text create mode 100644 test/tm-cases/toc_prepend.toc_html diff --git a/lib/markdown2.py b/lib/markdown2.py index 3a1db281..01252ff8 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -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" diff --git a/test/tm-cases/toc_prepend.html b/test/tm-cases/toc_prepend.html new file mode 100644 index 00000000..7aa0a0e5 --- /dev/null +++ b/test/tm-cases/toc_prepend.html @@ -0,0 +1,40 @@ + + +

README for Blah

+ +

Introduction

+ +

The Meat

+ +

Beef

+ +
Steak
+ +
Burgers
+ +

Chicken

+ +

Pork

+ +

Mmmmmmmm, bacon

+ +

At the top level again!?

diff --git a/test/tm-cases/toc_prepend.opts b/test/tm-cases/toc_prepend.opts new file mode 100644 index 00000000..261151cd --- /dev/null +++ b/test/tm-cases/toc_prepend.opts @@ -0,0 +1 @@ +{"extras": {"toc": {"prepend": True}}} diff --git a/test/tm-cases/toc_prepend.tags b/test/tm-cases/toc_prepend.tags new file mode 100644 index 00000000..2b2472e0 --- /dev/null +++ b/test/tm-cases/toc_prepend.tags @@ -0,0 +1 @@ +toc extra diff --git a/test/tm-cases/toc_prepend.text b/test/tm-cases/toc_prepend.text new file mode 100644 index 00000000..34f629a6 --- /dev/null +++ b/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!? + diff --git a/test/tm-cases/toc_prepend.toc_html b/test/tm-cases/toc_prepend.toc_html new file mode 100644 index 00000000..08288703 --- /dev/null +++ b/test/tm-cases/toc_prepend.toc_html @@ -0,0 +1,20 @@ + From f90c2e1352d38ab6349b1dcc4b2ab91978889e48 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 17 Feb 2024 14:32:24 +0000 Subject: [PATCH 2/5] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 6430e856..1987d1c2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - [pull #519] Add support for custom extras - [pull #519] Drop Python 3.5 support +- [pull #568] Add `prepend` arg to toc extra (#397) ## python-markdown2 2.4.13 From 4229e24c8b587516eaacc219a8af018e243cfaf0 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 17 Feb 2024 15:32:43 +0000 Subject: [PATCH 3/5] Make test warnings more visible --- test/test_markdown2.py | 8 ++++++-- test/testall.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test_markdown2.py b/test/test_markdown2.py index 1f08afd5..d6618052 100755 --- a/test/test_markdown2.py +++ b/test/test_markdown2.py @@ -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: @@ -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): diff --git a/test/testall.py b/test/testall.py index 38f8d8b8..68fab2ee 100644 --- a/test/testall.py +++ b/test/testall.py @@ -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)) From 91fb3e4d8030624d945e2193516d8f1cfb8fe015 Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 17 Feb 2024 15:41:26 +0000 Subject: [PATCH 4/5] Fix invalid escape sequences in test suite --- test/tm-cases/link_patterns.opts | 7 +++---- test/tm-cases/link_patterns_double_hit.opts | 3 +-- test/tm-cases/link_patterns_edge_cases.opts | 3 +-- test/tm-cases/link_patterns_escape.opts | 7 +++---- test/tm-cases/link_patterns_hash_matching_issue287.opts | 4 ++-- test/tm-cases/link_patterns_markdown_syntax.opts | 4 ++-- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/test/tm-cases/link_patterns.opts b/test/tm-cases/link_patterns.opts index 440d5a6d..346d99f4 100644 --- a/test/tm-cases/link_patterns.opts +++ b/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))), ], } - diff --git a/test/tm-cases/link_patterns_double_hit.opts b/test/tm-cases/link_patterns_double_hit.opts index d64982d8..563952fd 100644 --- a/test/tm-cases/link_patterns_double_hit.opts +++ b/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"), ], } - diff --git a/test/tm-cases/link_patterns_edge_cases.opts b/test/tm-cases/link_patterns_edge_cases.opts index 35761884..39235f28 100644 --- a/test/tm-cases/link_patterns_edge_cases.opts +++ b/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"), ], } - diff --git a/test/tm-cases/link_patterns_escape.opts b/test/tm-cases/link_patterns_escape.opts index 440d5a6d..346d99f4 100644 --- a/test/tm-cases/link_patterns_escape.opts +++ b/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))), ], } - diff --git a/test/tm-cases/link_patterns_hash_matching_issue287.opts b/test/tm-cases/link_patterns_hash_matching_issue287.opts index 21062d75..2c8e3b33 100644 --- a/test/tm-cases/link_patterns_hash_matching_issue287.opts +++ b/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") ] } diff --git a/test/tm-cases/link_patterns_markdown_syntax.opts b/test/tm-cases/link_patterns_markdown_syntax.opts index f33b27ee..2c8a9047 100644 --- a/test/tm-cases/link_patterns_markdown_syntax.opts +++ b/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/"), ], -} \ No newline at end of file +} From b8b4e8f0b34cfbcd4ec090635c75bed2fa26d2ab Mon Sep 17 00:00:00 2001 From: Crozzers Date: Sat, 17 Feb 2024 15:43:44 +0000 Subject: [PATCH 5/5] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 6430e856..9c89ac91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ - [pull #519] Add support for custom extras - [pull #519] Drop Python 3.5 support +- [pull #570] Fix syntax warnings in test suite ## python-markdown2 2.4.13