pdoc 13.1.0__tar.gz → 13.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pdoc-13.1.0 → pdoc-13.1.1}/CHANGELOG.md +10 -0
- {pdoc-13.1.0/pdoc.egg-info → pdoc-13.1.1}/PKG-INFO +1 -1
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/__init__.py +1 -1
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/doc.py +33 -4
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/doc_ast.py +10 -6
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/markdown2/__init__.py +61 -33
- {pdoc-13.1.0 → pdoc-13.1.1/pdoc.egg-info}/PKG-INFO +1 -1
- {pdoc-13.1.0 → pdoc-13.1.1}/LICENSE +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/MANIFEST.in +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/README.md +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/__main__.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/_compat.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/doc_pyi.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/doc_types.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/docstrings.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/extract.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/markdown2/LICENSE +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/markdown2/README.md +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/py.typed +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/render.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/render_helpers.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/search.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/README.md +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/build-search-index.js +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/content.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/custom.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/default/error.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/default/frame.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/default/index.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/default/module.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/README.md +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/bootstrap-reboot.min.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/box-arrow-in-left.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/elasticlunr.min.js +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/favicon.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/navtoggle.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/pdoc-logo.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/deprecated/resources/favicon.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/layout.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/livereload.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/math.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/mermaid.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/bootstrap-reboot.min.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/box-arrow-in-left.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/elasticlunr.min.js +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/exclamation-triangle-fill.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/info-circle-fill.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/lightning-fill.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/navtoggle.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/resources/pdoc-logo.svg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/search.html.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/search.js.jinja2 +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/syntax-highlighting.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/templates/theme.css +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc/web.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc.egg-info/SOURCES.txt +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc.egg-info/dependency_links.txt +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc.egg-info/entry_points.txt +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc.egg-info/requires.txt +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pdoc.egg-info/top_level.txt +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/pyproject.toml +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/setup.cfg +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_doc.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_doc_ast.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_doc_pyi.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_doc_types.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_docstrings.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_extract.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_main.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_render_helpers.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_search.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_smoke.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_snapshot.py +0 -0
- {pdoc-13.1.0 → pdoc-13.1.1}/test/test_web.py +0 -0
@@ -5,6 +5,16 @@
|
|
5
5
|
<!-- ✨ You do not need to add a pull request reference or an author, this will be added automatically by CI. ✨ -->
|
6
6
|
|
7
7
|
|
8
|
+
## 2023-04-24: pdoc 13.1.1
|
9
|
+
|
10
|
+
- Fix rendering of dynamically modified docstrings.
|
11
|
+
([#537](https://github.com/mitmproxy/pdoc/pull/537), @mhils)
|
12
|
+
- Updated bundled markdown2 version to fix a bug with empty code blocks.
|
13
|
+
([#537](https://github.com/mitmproxy/pdoc/pull/537), @mhils)
|
14
|
+
- `pdoc.doc_ast.AstInfo` now has separate `func_docstrings` and `var_docstrings` attributes
|
15
|
+
instead of one combined one.
|
16
|
+
([#537](https://github.com/mitmproxy/pdoc/pull/537), @mhils)
|
17
|
+
|
8
18
|
## 2023-03-31: pdoc 13.1.0
|
9
19
|
|
10
20
|
- Add support for rendering [Mermaid diagrams](https://mermaid.js.org/) by passing `--mermaid`.
|
@@ -461,7 +461,7 @@ You can find an example in [`examples/library-usage`](https://github.com/mitmpro
|
|
461
461
|
from __future__ import annotations
|
462
462
|
|
463
463
|
__docformat__ = "markdown" # explicitly disable rST processing in the examples above.
|
464
|
-
__version__ = "13.1.
|
464
|
+
__version__ = "13.1.1" # this is read from setup.py
|
465
465
|
|
466
466
|
from pathlib import Path
|
467
467
|
from typing import overload
|
@@ -223,6 +223,11 @@ class Namespace(Doc[T], metaclass=ABCMeta):
|
|
223
223
|
def _var_docstrings(self) -> dict[str, str]:
|
224
224
|
"""A mapping from some member variable names to their docstrings."""
|
225
225
|
|
226
|
+
@cached_property
|
227
|
+
@abstractmethod
|
228
|
+
def _func_docstrings(self) -> dict[str, str]:
|
229
|
+
"""A mapping from some member function names to their raw (not processed by any @decorators) docstrings."""
|
230
|
+
|
226
231
|
@cached_property
|
227
232
|
@abstractmethod
|
228
233
|
def _var_annotations(self) -> dict[str, Any]:
|
@@ -312,6 +317,8 @@ class Namespace(Doc[T], metaclass=ABCMeta):
|
|
312
317
|
)
|
313
318
|
if self._var_docstrings.get(name):
|
314
319
|
doc.docstring = self._var_docstrings[name]
|
320
|
+
if self._func_docstrings.get(name) and not doc.docstring:
|
321
|
+
doc.docstring = self._func_docstrings[name]
|
315
322
|
members[doc.name] = doc
|
316
323
|
|
317
324
|
if isinstance(self, Module):
|
@@ -409,7 +416,11 @@ class Module(Namespace[types.ModuleType]):
|
|
409
416
|
|
410
417
|
@cached_property
|
411
418
|
def _var_docstrings(self) -> dict[str, str]:
|
412
|
-
return doc_ast.walk_tree(self.obj).
|
419
|
+
return doc_ast.walk_tree(self.obj).var_docstrings
|
420
|
+
|
421
|
+
@cached_property
|
422
|
+
def _func_docstrings(self) -> dict[str, str]:
|
423
|
+
return doc_ast.walk_tree(self.obj).func_docstrings
|
413
424
|
|
414
425
|
@cached_property
|
415
426
|
def _var_annotations(self) -> dict[str, Any]:
|
@@ -478,7 +489,11 @@ class Module(Namespace[types.ModuleType]):
|
|
478
489
|
|
479
490
|
@cached_property
|
480
491
|
def _documented_members(self) -> set[str]:
|
481
|
-
return
|
492
|
+
return (
|
493
|
+
self._var_docstrings.keys()
|
494
|
+
| self._func_docstrings.keys()
|
495
|
+
| self._var_annotations.keys()
|
496
|
+
)
|
482
497
|
|
483
498
|
@cached_property
|
484
499
|
def _member_objects(self) -> dict[str, Any]:
|
@@ -526,6 +541,8 @@ class Module(Namespace[types.ModuleType]):
|
|
526
541
|
members[name] = obj
|
527
542
|
for name in self._var_docstrings:
|
528
543
|
members.setdefault(name, empty)
|
544
|
+
for name in self._func_docstrings:
|
545
|
+
members.setdefault(name, empty)
|
529
546
|
|
530
547
|
members, notfound = doc_ast.sort_by_source(self.obj, {}, members)
|
531
548
|
members.update(notfound)
|
@@ -587,7 +604,15 @@ class Class(Namespace[type]):
|
|
587
604
|
def _var_docstrings(self) -> dict[str, str]:
|
588
605
|
docstrings: dict[str, str] = {}
|
589
606
|
for cls in self._mro:
|
590
|
-
for name, docstr in doc_ast.walk_tree(cls).
|
607
|
+
for name, docstr in doc_ast.walk_tree(cls).var_docstrings.items():
|
608
|
+
docstrings.setdefault(name, docstr)
|
609
|
+
return docstrings
|
610
|
+
|
611
|
+
@cached_property
|
612
|
+
def _func_docstrings(self) -> dict[str, str]:
|
613
|
+
docstrings: dict[str, str] = {}
|
614
|
+
for cls in self._mro:
|
615
|
+
for name, docstr in doc_ast.walk_tree(cls).func_docstrings.items():
|
591
616
|
docstrings.setdefault(name, docstr)
|
592
617
|
return docstrings
|
593
618
|
|
@@ -642,7 +667,11 @@ class Class(Namespace[type]):
|
|
642
667
|
decls: dict[str, tuple[str, str]] = {}
|
643
668
|
for cls in self._mro:
|
644
669
|
treeinfo = doc_ast.walk_tree(cls)
|
645
|
-
for name in
|
670
|
+
for name in (
|
671
|
+
treeinfo.var_docstrings.keys()
|
672
|
+
| treeinfo.func_docstrings.keys()
|
673
|
+
| treeinfo.annotations.keys()
|
674
|
+
):
|
646
675
|
decls.setdefault(name, (cls.__module__, f"{cls.__qualname__}.{name}"))
|
647
676
|
for name in cls.__dict__:
|
648
677
|
decls.setdefault(name, (cls.__module__, f"{cls.__qualname__}.{name}"))
|
@@ -85,8 +85,10 @@ def unparse(tree: ast.AST):
|
|
85
85
|
class AstInfo:
|
86
86
|
"""The information extracted from walking the syntax tree."""
|
87
87
|
|
88
|
-
|
88
|
+
var_docstrings: dict[str, str]
|
89
89
|
"""A qualname -> docstring mapping."""
|
90
|
+
func_docstrings: dict[str, str]
|
91
|
+
"""A qualname -> docstring mapping for functions."""
|
90
92
|
annotations: dict[str, str]
|
91
93
|
"""A qualname -> annotation mapping.
|
92
94
|
|
@@ -104,7 +106,8 @@ def walk_tree(obj: types.ModuleType | type) -> AstInfo:
|
|
104
106
|
def _walk_tree(
|
105
107
|
tree: ast.Module | ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef,
|
106
108
|
) -> AstInfo:
|
107
|
-
|
109
|
+
var_docstrings = {}
|
110
|
+
func_docstrings = {}
|
108
111
|
annotations = {}
|
109
112
|
for a, b in _pairwise_longest(_nodes(tree)):
|
110
113
|
if isinstance(a, ast.AnnAssign) and isinstance(a.target, ast.Name) and a.simple:
|
@@ -122,7 +125,7 @@ def _walk_tree(
|
|
122
125
|
elif isinstance(a, ast.FunctionDef) and a.body:
|
123
126
|
first = a.body[0]
|
124
127
|
if isinstance(first, ast.Expr) and isinstance(first.value, ast.Str):
|
125
|
-
|
128
|
+
func_docstrings[a.name] = inspect.cleandoc(first.value.s).strip()
|
126
129
|
continue
|
127
130
|
else:
|
128
131
|
continue
|
@@ -131,14 +134,15 @@ def _walk_tree(
|
|
131
134
|
and isinstance(b.value, ast.Constant)
|
132
135
|
and isinstance(b.value.value, str)
|
133
136
|
):
|
134
|
-
|
137
|
+
var_docstrings[name] = inspect.cleandoc(b.value.value).strip()
|
135
138
|
elif isinstance(b, ast.Expr) and isinstance(
|
136
139
|
b.value, ast.Str
|
137
140
|
): # pragma: no cover
|
138
141
|
# Python <= 3.7
|
139
|
-
|
142
|
+
var_docstrings[name] = inspect.cleandoc(b.value.s).strip()
|
140
143
|
return AstInfo(
|
141
|
-
|
144
|
+
var_docstrings,
|
145
|
+
func_docstrings,
|
142
146
|
annotations,
|
143
147
|
)
|
144
148
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# fmt: off
|
2
2
|
# flake8: noqa
|
3
3
|
# type: ignore
|
4
|
-
# Taken from here: https://github.com/trentm/python-markdown2/blob/
|
4
|
+
# Taken from here: https://github.com/trentm/python-markdown2/blob/bce3f18ed86a19b418c8114a712bb6fee790c4c2/lib/markdown2.py
|
5
5
|
|
6
6
|
#!/usr/bin/env python
|
7
7
|
# Copyright (c) 2012 Trent Mick.
|
@@ -61,7 +61,7 @@ see <https://github.com/trentm/python-markdown2/wiki/Extras> for details):
|
|
61
61
|
highlighting when using fenced-code-blocks and highlightjs.
|
62
62
|
* html-classes: Takes a dict mapping html tag names (lowercase) to a
|
63
63
|
string to use for a "class" tag attribute. Currently only supports "img",
|
64
|
-
"table", "pre", "code", "ul" and "ol" tags. Add an issue if you require
|
64
|
+
"table", "thead", "pre", "code", "ul" and "ol" tags. Add an issue if you require
|
65
65
|
this for other tags.
|
66
66
|
* link-patterns: Auto-link given regex patterns in text (e.g. bug number
|
67
67
|
references, revision number references).
|
@@ -104,18 +104,18 @@ see <https://github.com/trentm/python-markdown2/wiki/Extras> for details):
|
|
104
104
|
# not yet sure if there implications with this. Compare 'pydoc sre'
|
105
105
|
# and 'perldoc perlre'.
|
106
106
|
|
107
|
-
__version_info__ = (2, 4,
|
107
|
+
__version_info__ = (2, 4, 9)
|
108
108
|
__version__ = '.'.join(map(str, __version_info__))
|
109
109
|
__author__ = "Trent Mick"
|
110
110
|
|
111
|
-
import
|
112
|
-
import re
|
113
|
-
import logging
|
114
|
-
from hashlib import sha256
|
115
|
-
import optparse
|
116
|
-
from random import random, randint
|
111
|
+
import argparse
|
117
112
|
import codecs
|
113
|
+
import logging
|
114
|
+
import re
|
115
|
+
import sys
|
118
116
|
from collections import defaultdict
|
117
|
+
from hashlib import sha256
|
118
|
+
from random import randint, random
|
119
119
|
|
120
120
|
# ---- globals
|
121
121
|
|
@@ -1144,7 +1144,7 @@ class Markdown(object):
|
|
1144
1144
|
align_from_col_idx[col_idx] = ' style="text-align:right;"'
|
1145
1145
|
|
1146
1146
|
# thead
|
1147
|
-
hlines = ['<table%s>' % self._html_class_str_from_tag('table'), '<thead>', '<tr>']
|
1147
|
+
hlines = ['<table%s>' % self._html_class_str_from_tag('table'), '<thead%s>' % self._html_class_str_from_tag('thead'), '<tr>']
|
1148
1148
|
cols = [re.sub(escape_bar_re, '|', cell.strip()) for cell in re.split(split_bar_re, re.sub(trim_bar_re, "", re.sub(trim_space_re, "", head)))]
|
1149
1149
|
for col_idx, col in enumerate(cols):
|
1150
1150
|
hlines.append(' <th%s>%s</th>' % (
|
@@ -1220,7 +1220,7 @@ class Markdown(object):
|
|
1220
1220
|
add_hline('<table%s>' % self._html_class_str_from_tag('table'))
|
1221
1221
|
# Check if first cell of first row is a header cell. If so, assume the whole row is a header row.
|
1222
1222
|
if rows and rows[0] and re.match(r"^\s*~", rows[0][0]):
|
1223
|
-
add_hline('<thead>', 1)
|
1223
|
+
add_hline('<thead%s>' % self._html_class_str_from_tag('thead'), 1)
|
1224
1224
|
add_hline('<tr>', 2)
|
1225
1225
|
for cell in rows[0]:
|
1226
1226
|
add_hline("<th>{}</th>".format(format_cell(cell)), 3)
|
@@ -2246,7 +2246,7 @@ class Markdown(object):
|
|
2246
2246
|
def _do_underline(self, text):
|
2247
2247
|
text = self._underline_re.sub(r"<u>\1</u>", text)
|
2248
2248
|
return text
|
2249
|
-
|
2249
|
+
|
2250
2250
|
_tg_spoiler_re = re.compile(r"\|\|\s?(.+?)\s?\|\|", re.S)
|
2251
2251
|
def _do_tg_spoiler(self, text):
|
2252
2252
|
text = self._tg_spoiler_re.sub(r"<tg-spoiler>\1</tg-spoiler>", text)
|
@@ -2538,6 +2538,9 @@ class Markdown(object):
|
|
2538
2538
|
for regex, repl in self.link_patterns:
|
2539
2539
|
replacements = []
|
2540
2540
|
for match in regex.finditer(text):
|
2541
|
+
if any(self._match_overlaps_substr(text, match, h) for h in link_from_hash):
|
2542
|
+
continue
|
2543
|
+
|
2541
2544
|
if hasattr(repl, "__call__"):
|
2542
2545
|
href = repl(match)
|
2543
2546
|
else:
|
@@ -2614,12 +2617,17 @@ class Markdown(object):
|
|
2614
2617
|
re.findall(r'^[ \t]*', line)[0] if line else None
|
2615
2618
|
for line in text.splitlines()
|
2616
2619
|
]
|
2620
|
+
whitespace_not_empty = [i for i in whitespace if i is not None]
|
2621
|
+
|
2622
|
+
# if no whitespace detected (ie: no lines in code block, issue #505)
|
2623
|
+
if not whitespace_not_empty:
|
2624
|
+
return '', text
|
2617
2625
|
|
2618
2626
|
# get minimum common whitespace
|
2619
|
-
outdent = min(
|
2627
|
+
outdent = min(whitespace_not_empty)
|
2620
2628
|
# adjust min common ws to be within bounds
|
2621
2629
|
if min_outdent is not None:
|
2622
|
-
outdent = min([i for i in
|
2630
|
+
outdent = min([i for i in whitespace_not_empty if i >= min_outdent] or [min_outdent])
|
2623
2631
|
if max_outdent is not None:
|
2624
2632
|
outdent = min(outdent, max_outdent)
|
2625
2633
|
|
@@ -2642,6 +2650,19 @@ class Markdown(object):
|
|
2642
2650
|
for line in text.splitlines(True)
|
2643
2651
|
)
|
2644
2652
|
|
2653
|
+
@staticmethod
|
2654
|
+
def _match_overlaps_substr(text, match, substr):
|
2655
|
+
'''
|
2656
|
+
Checks if a regex match overlaps with a substring in the given text.
|
2657
|
+
'''
|
2658
|
+
for instance in re.finditer(re.escape(substr), text):
|
2659
|
+
start, end = instance.span()
|
2660
|
+
if start <= match.start() <= end:
|
2661
|
+
return True
|
2662
|
+
if start <= match.end() <= end:
|
2663
|
+
return True
|
2664
|
+
return False
|
2665
|
+
|
2645
2666
|
|
2646
2667
|
class MarkdownWithExtras(Markdown):
|
2647
2668
|
"""A markdowner class that enables most extras:
|
@@ -2961,8 +2982,8 @@ def _html_escape_url(attr, safe_mode=False):
|
|
2961
2982
|
|
2962
2983
|
# ---- mainline
|
2963
2984
|
|
2964
|
-
class _NoReflowFormatter(
|
2965
|
-
"""An
|
2985
|
+
class _NoReflowFormatter(argparse.RawDescriptionHelpFormatter):
|
2986
|
+
"""An argparse formatter that does NOT reflow the description."""
|
2966
2987
|
def format_description(self, description):
|
2967
2988
|
return description or ""
|
2968
2989
|
|
@@ -2978,38 +2999,45 @@ def main(argv=None):
|
|
2978
2999
|
if not logging.root.handlers:
|
2979
3000
|
logging.basicConfig()
|
2980
3001
|
|
2981
|
-
|
2982
|
-
|
2983
|
-
|
2984
|
-
|
2985
|
-
|
2986
|
-
|
3002
|
+
parser = argparse.ArgumentParser(
|
3003
|
+
prog="markdown2", description=cmdln_desc, usage='%(prog)s [PATHS...]',
|
3004
|
+
formatter_class=_NoReflowFormatter
|
3005
|
+
)
|
3006
|
+
parser.add_argument('--version', action='version',
|
3007
|
+
version='%(prog)s {version}'.format(version=__version__))
|
3008
|
+
parser.add_argument('paths', nargs='*',
|
3009
|
+
help=(
|
3010
|
+
'optional list of files to convert.'
|
3011
|
+
'If none are given, stdin will be used'
|
3012
|
+
))
|
3013
|
+
parser.add_argument("-v", "--verbose", dest="log_level",
|
2987
3014
|
action="store_const", const=logging.DEBUG,
|
2988
3015
|
help="more verbose output")
|
2989
|
-
parser.
|
3016
|
+
parser.add_argument("--encoding",
|
2990
3017
|
help="specify encoding of text content")
|
2991
|
-
parser.
|
3018
|
+
parser.add_argument("--html4tags", action="store_true", default=False,
|
2992
3019
|
help="use HTML 4 style for empty element tags")
|
2993
|
-
parser.
|
3020
|
+
parser.add_argument("-s", "--safe", metavar="MODE", dest="safe_mode",
|
2994
3021
|
help="sanitize literal HTML: 'escape' escapes "
|
2995
3022
|
"HTML meta chars, 'replace' replaces with an "
|
2996
3023
|
"[HTML_REMOVED] note")
|
2997
|
-
parser.
|
3024
|
+
parser.add_argument("-x", "--extras", action="append",
|
2998
3025
|
help="Turn on specific extra features (not part of "
|
2999
3026
|
"the core Markdown spec). See above.")
|
3000
|
-
parser.
|
3027
|
+
parser.add_argument("--use-file-vars",
|
3001
3028
|
help="Look for and use Emacs-style 'markdown-extras' "
|
3002
3029
|
"file var to turn on extras. See "
|
3003
3030
|
"<https://github.com/trentm/python-markdown2/wiki/Extras>")
|
3004
|
-
parser.
|
3031
|
+
parser.add_argument("--link-patterns-file",
|
3005
3032
|
help="path to a link pattern file")
|
3006
|
-
parser.
|
3033
|
+
parser.add_argument("--self-test", action="store_true",
|
3007
3034
|
help="run internal self-tests (some doctests)")
|
3008
|
-
parser.
|
3035
|
+
parser.add_argument("--compare", action="store_true",
|
3009
3036
|
help="run against Markdown.pl as well (for testing)")
|
3010
3037
|
parser.set_defaults(log_level=logging.INFO, compare=False,
|
3011
3038
|
encoding="utf-8", safe_mode=None, use_file_vars=False)
|
3012
|
-
opts
|
3039
|
+
opts = parser.parse_args()
|
3040
|
+
paths = opts.paths
|
3013
3041
|
log.setLevel(opts.log_level)
|
3014
3042
|
|
3015
3043
|
if opts.self_test:
|
@@ -3051,7 +3079,7 @@ def main(argv=None):
|
|
3051
3079
|
else:
|
3052
3080
|
link_patterns = None
|
3053
3081
|
|
3054
|
-
from os.path import
|
3082
|
+
from os.path import abspath, dirname, exists, join
|
3055
3083
|
markdown_pl = join(dirname(dirname(abspath(__file__))), "test",
|
3056
3084
|
"Markdown.pl")
|
3057
3085
|
if not paths:
|
@@ -3064,7 +3092,7 @@ def main(argv=None):
|
|
3064
3092
|
text = fp.read()
|
3065
3093
|
fp.close()
|
3066
3094
|
if opts.compare:
|
3067
|
-
from subprocess import
|
3095
|
+
from subprocess import PIPE, Popen
|
3068
3096
|
print("==== Markdown.pl ====")
|
3069
3097
|
p = Popen('perl %s' % markdown_pl, shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)
|
3070
3098
|
p.stdin.write(text.encode('utf-8'))
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|