markdown2-2.3.7/ 0000755 0000765 0000024 00000000000 13402017660 013475 5 ustar nick staff 0000000 0000000 markdown2-2.3.7/bin/ 0000755 0000765 0000024 00000000000 13402017660 014245 5 ustar nick staff 0000000 0000000 markdown2-2.3.7/bin/markdown2 0000755 0000765 0000024 00000000737 12240460102 016076 0 ustar nick staff 0000000 0000000 #!/usr/bin/env python
import sys
from os.path import join, dirname, exists
# Use the local markdown2.py if we are in the source tree.
source_tree_markdown2 = join(dirname(__file__), "..", "lib", "markdown2.py")
if exists(source_tree_markdown2):
sys.path.insert(0, dirname(source_tree_markdown2))
try:
from markdown2 import main
finally:
del sys.path[0]
else:
from markdown2 import main
if __name__ == "__main__":
sys.exit( main(sys.argv) )
markdown2-2.3.7/CHANGES.md 0000644 0000765 0000024 00000045742 13402017423 015100 0 ustar nick staff 0000000 0000000 # python-markdown2 Changelog
## python-markdown2 2.3.7
- [pull #306] Drop support for legacy Python versions
- [pull #307] Fix syntax highlighting test cases that depend on Pygments output
- [pull #308] Add support for Python 3.7
- [pull #304] Add Wheel package support
- [pull #312] Fix toc_depth initialization regression
- [pull #315] XSS fix
## python-markdown2 2.3.6
- [pull #282] Add TOC depth option
- [pull #283] Fix to add TOC html to output via CLI
- [pull #284] Do not remove anchors in safe_mode
- [pull #288] fixing cuddled-lists with a single list item
- [pull #292] Fix Wrong rendering of last list element
- [pull #295] link-patterns fix
- [pull #300] Replace a deprecated method
- [pull #301] DeprecationWarning: invalid escape sequence
- [pull #302] Fix "make test" in Python 3
- [pull #303] Fix CVE-2018-5773
## python-markdown2 2.3.5
- [pull #238] Fenced code blocks lang with leading space
- [pull #260] Search for items only within metadata header
- [pull #264] highlightjs language class support
- [pull #265] FIPS compliance
- [pull #274] Fix for double amp replacement inside link title
## python-markdown2 2.3.4
- [pull #243] task list extra visual changes
- [pull #245] Don't let "target-blank-lines" break footnotes
- [pull #247] Translatable footnote titles
- [pull #252] Add pipe escaping in table extension
## python-markdown2 2.3.3
- [pull #236] Fix for safe_mode links regression
- [pull #235] Fix for overgreedy regex in metadata
- [pull #237] Fix for header-ids extra non-alpha character issue
## python-markdown2 2.3.2
- [pull #204] toc extra Python 3 error
- [pull #207] Performance improvements
- [pull #210] Leading paragraph with fenced code blocks
- [pull #212] Target blank links extra
- [pull #215] Optional metadata fences
- [pull #218] Github style task list
- [pull #220] Numbering extra
- [pull #224] Metadata in blocks
- [pull #230] safe_mode changes
## python-markdown2 2.3.1
- [pull #131] Markdown "spoiler" extra
- [pull #170] html-classes support for table tags
- [pull #190] "strike" extra
- [pull #201] Allow empty table cells
## python-markdown2 2.3.0
- New "tables" extra for table syntax that matches GFM
I did these things:
Here is PEP 42.
\n' ## python-markdown2 1.0.1.11 - Fix syntax_color test for the latest Pygments. - [Issue 20] Can't assume that `sys.argv` is defined at top-level code -- e.g. when used at a PostreSQL stored procedure. Fix that. ## python-markdown2 1.0.1.10 - Fix sys.path manipulation in setup.py so `easy_install markdown2-*.tar.gz` works. (Henry Precheur pointed out the problem.) - "bin/markdown2" is now a stub runner script rather than a symlink to "lib/markdown2.py". The symlink was a problem for sdist: tar makes it a copy. - Added 'xml' extra: passes *one-liner* XML processing instructions and namespaced XML tags without wrapping in a `` -- i.e. treats them as a HTML
block tag.
## python-markdown2 1.0.1.9
- Fix bug in processing text with two HTML comments, where the first comment
is cuddled to other content. See "test/tm-cases/two_comments.text". Noted
by Wolfgang Machert.
- Revert change in v1.0.1.6 passing XML processing instructions and one-liner
tags. This changed caused some bugs. Similar XML processing support will
make it back via an "xml" extra.
## python-markdown2 1.0.1.8
- License note updates to facilitate Thomas Moschny building a package for
Fedora Core Linux. No functional change.
## python-markdown2 1.0.1.7
- Add a proper setup.py and release to pypi:
http://pypi.python.org/pypi/markdown2/
- Move markdown2.py module to a lib subdir. This allows one to put the "lib"
dir of a source checkout (e.g. via an svn:externals) on ones Python Path
without have the .py files at the top-level getting in the way.
## python-markdown2 1.0.1.6
- Fix Python 2.6 deprecation warning about the `md5` module.
- Pass XML processing instructions and one-liner tags. For example:
tags.
"""
yield 0, ""
for tup in inner:
yield tup
yield 0, "
"
def wrap(self, source, outfile):
"""Return the source with a code, pre, and div."""
return self._wrap_div(self._wrap_pre(self._wrap_code(source)))
formatter_opts.setdefault("cssclass", "codehilite")
formatter = HtmlCodeFormatter(**formatter_opts)
return pygments.highlight(codeblock, lexer, formatter)
def _code_block_sub(self, match, is_fenced_code_block=False):
lexer_name = None
if is_fenced_code_block:
lexer_name = match.group(1)
if lexer_name:
formatter_opts = self.extras['fenced-code-blocks'] or {}
codeblock = match.group(2)
codeblock = codeblock[:-1] # drop one trailing newline
else:
codeblock = match.group(1)
codeblock = self._outdent(codeblock)
codeblock = self._detab(codeblock)
codeblock = codeblock.lstrip('\n') # trim leading newlines
codeblock = codeblock.rstrip() # trim trailing whitespace
# Note: "code-color" extra is DEPRECATED.
if "code-color" in self.extras and codeblock.startswith(":::"):
lexer_name, rest = codeblock.split('\n', 1)
lexer_name = lexer_name[3:].strip()
codeblock = rest.lstrip("\n") # Remove lexer declaration line.
formatter_opts = self.extras['code-color'] or {}
# Use pygments only if not using the highlightjs-lang extra
if lexer_name and "highlightjs-lang" not in self.extras:
def unhash_code(codeblock):
for key, sanitized in list(self.html_spans.items()):
codeblock = codeblock.replace(key, sanitized)
replacements = [
("&", "&"),
("<", "<"),
(">", ">")
]
for old, new in replacements:
codeblock = codeblock.replace(old, new)
return codeblock
lexer = self._get_pygments_lexer(lexer_name)
if lexer:
codeblock = unhash_code( codeblock )
colored = self._color_with_pygments(codeblock, lexer,
**formatter_opts)
return "\n\n%s\n\n" % colored
codeblock = self._encode_code(codeblock)
pre_class_str = self._html_class_str_from_tag("pre")
if "highlightjs-lang" in self.extras and lexer_name:
code_class_str = ' class="%s"' % lexer_name
else:
code_class_str = self._html_class_str_from_tag("code")
return "\n\n%s\n
\n\n" % (
pre_class_str, code_class_str, codeblock)
def _html_class_str_from_tag(self, tag):
"""Get the appropriate ' class="..."' string (note the leading
space), if any, for the given tag.
"""
if "html-classes" not in self.extras:
return ""
try:
html_classes_from_tag = self.extras["html-classes"]
except TypeError:
return ""
else:
if tag in html_classes_from_tag:
return ' class="%s"' % html_classes_from_tag[tag]
return ""
def _do_code_blocks(self, text):
"""Process Markdown `` blocks."""
code_block_re = re.compile(r'''
(?:\n\n|\A\n?)
( # $1 = the code block -- one or more lines, starting with a space/tab
(?:
(?:[ ]{%d} | \t) # Lines must start with a tab or a tab-width of spaces
.*\n+
)+
)
((?=^[ ]{0,%d}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
# Lookahead to make sure this block isn't already in a code block.
# Needed when syntax highlighting is being used.
(?![^<]*\
)
''' % (self.tab_width, self.tab_width),
re.M | re.X)
return code_block_re.sub(self._code_block_sub, text)
_fenced_code_block_re = re.compile(r'''
(?:\n+|\A\n?)
^```\s*?([\w+-]+)?\s*?\n # opening fence, $1 = optional lang
(.*?) # $2 = code block content
^```[ \t]*\n # closing fence
''', re.M | re.X | re.S)
def _fenced_code_block_sub(self, match):
return self._code_block_sub(match, is_fenced_code_block=True)
def _do_fenced_code_blocks(self, text):
"""Process ```-fenced unindented code blocks ('fenced-code-blocks' extra)."""
return self._fenced_code_block_re.sub(self._fenced_code_block_sub, text)
# Rules for a code span:
# - backslash escapes are not interpreted in a code span
# - to include one or or a run of more backticks the delimiters must
# be a longer run of backticks
# - cannot start or end a code span with a backtick; pad with a
# space and that space will be removed in the emitted HTML
# See `test/tm-cases/escapes.text` for a number of edge-case
# examples.
_code_span_re = re.compile(r'''
(?%s
" % c
def _do_code_spans(self, text):
# * Backtick quotes are used for
spans.
#
# * You can use multiple backticks as the delimiters if you want to
# include literal backticks in the code span. So, this input:
#
# Just type ``foo `bar` baz`` at the prompt.
#
# Will translate to:
#
# Just type foo `bar` baz
at the prompt.
`bar`
...
return self._code_span_re.sub(self._code_span_sub, text)
def _encode_code(self, text):
"""Encode/escape certain characters inside Markdown code runs.
The point is that in code, these characters are literals,
and lose their special Markdown meanings.
"""
replacements = [
# Encode all ampersands; HTML entities are not
# entities within a Markdown code span.
('&', '&'),
# Do the angle bracket song and dance:
('<', '<'),
('>', '>'),
]
for before, after in replacements:
text = text.replace(before, after)
hashed = _hash_text(text)
self._escape_table[text] = hashed
return hashed
_strike_re = re.compile(r"~~(?=\S)(.+?)(?<=\S)~~", re.S)
def _do_strike(self, text):
text = self._strike_re.sub(r".+?)', re.S) def _dedent_two_spaces_sub(self, match): return re.sub(r'(?m)^ ', '', match.group(1)) def _block_quote_sub(self, match): bq = match.group(1) is_spoiler = 'spoiler' in self.extras and self._bq_all_lines_spoilers.match(bq) # trim one level of quoting if is_spoiler: bq = self._bq_one_level_re_spoiler.sub('', bq) else: bq = self._bq_one_level_re.sub('', bq) # trim whitespace-only lines bq = self._ws_only_line_re.sub('', bq) bq = self._run_block_gamut(bq) # recurse bq = re.sub('(?m)^', ' ', bq) # These leading spaces screw with
content, so we need to fix that: bq = self._html_pre_block_re.sub(self._dedent_two_spaces_sub, bq) if is_spoiler: return '\n%s\n\n\n' % bq else: return '\n%s\n\n\n' % bq def _do_block_quotes(self, text): if '>' not in text: return text if 'spoiler' in self.extras: return self._block_quote_re_spoiler.sub(self._block_quote_sub, text) else: return self._block_quote_re.sub(self._block_quote_sub, text) def _form_paragraphs(self, text): # Strip leading and trailing lines: text = text.strip('\n') # Wraptags. grafs = [] for i, graf in enumerate(re.split(r"\n{2,}", text)): if graf in self.html_blocks: # Unhashify HTML blocks grafs.append(self.html_blocks[graf]) else: cuddled_list = None if "cuddled-lists" in self.extras: # Need to put back trailing '\n' for `_list_item_re` # match at the end of the paragraph. li = self._list_item_re.search(graf + '\n') # Two of the same list marker in this paragraph: a likely # candidate for a list cuddled to preceding paragraph # text (issue 33). Note the `[-1]` is a quick way to # consider numeric bullets (e.g. "1." and "2.") to be # equal. if (li and len(li.group(2)) <= 3 and ( (li.group("next_marker") and li.group("marker")[-1] == li.group("next_marker")[-1]) or li.group("next_marker") is None ) ): start = li.start() cuddled_list = self._do_lists(graf[start:]).rstrip("\n") assert cuddled_list.startswith("
tags. graf = self._run_span_gamut(graf) grafs.append("
" + graf.lstrip(" \t") + "
") if cuddled_list: grafs.append(cuddled_list) return "\n\n".join(grafs) def _add_footnotes(self, text): if self.footnotes: footer = [ '%s
" % backlink) footer.append('boo
\n' >>> m = markdown2.Markdown() >>> str( m.convert("*boo*") ) 'boo
\n' >>> m = markdown2.MarkdownWithExtras() >>> str( m.convert("*boo*") ) 'boo
\n' markdown2-2.3.7/test/test.py 0000755 0000765 0000024 00000002366 13347747577 016050 0 ustar nick staff 0000000 0000000 #!/usr/bin/env python # Copyright (c) 2007-2008 ActiveState Software Inc. # License: MIT (http://www.opensource.org/licenses/mit-license.php) """The markdown2 test suite entry point.""" import os from os.path import exists, join, abspath, dirname, normpath import sys import logging import testlib log = logging.getLogger("test") testdir_from_ns = { None: os.curdir, } def setup(): top_dir = dirname(dirname(abspath(__file__))) lib_dir = join(top_dir, "lib") sys.path.insert(0, lib_dir) # Attempt to get 'pygments' on the import path. try: # If already have it, use that one. import pygments except ImportError: pygments_dir = join(top_dir, "deps", "pygments") if sys.version_info[0] <= 2: sys.path.insert(0, pygments_dir) else: sys.path.insert(0, pygments_dir + "3") if __name__ == "__main__": logging.basicConfig() setup() default_tags = [] try: import pygments except ImportError: log.warning("skipping pygments tests ('pygments' module not found)") default_tags.append("-pygments") retval = testlib.harness(testdir_from_ns=testdir_from_ns, default_tags=default_tags) sys.exit(retval) markdown2-2.3.7/test/test_markdown2.py 0000644 0000765 0000024 00000046673 13352553746 020027 0 ustar nick staff 0000000 0000000 #!/usr/bin/env python # Copyright (c) 2007-2008 ActiveState Software Inc. # License: MIT (http://www.opensource.org/licenses/mit-license.php) """Test the Python markdown2.py.""" import os import sys from os.path import join, dirname, abspath, exists, splitext, basename import re from glob import glob from pprint import pprint import unittest import codecs import difflib import doctest from json import loads as json_loads from testlib import TestError, TestSkipped, tag sys.path.insert(0, join(dirname(dirname(abspath(__file__))))) try: import markdown2 finally: del sys.path[0] #---- Python version compat # Use `bytes` for byte strings and `unicode` for unicode strings (str in Py3). if sys.version_info[0] <= 2: py3 = False try: bytes except NameError: bytes = str base_string_type = basestring elif sys.version_info[0] >= 3: py3 = True unicode = str base_string_type = str unichr = chr #---- Test cases class _MarkdownTestCase(unittest.TestCase): """Helper class for Markdown tests.""" maxDiff = None def _assertMarkdownParity(self, text): """Assert that markdown2.py produces same output as Markdown.pl.""" #TODO add normalization python_html = markdown2.markdown(text) perl_html = _markdown_with_perl(text) close_though = "" if python_html != perl_html \ and (python_html.replace('\n', '') == perl_html.replace('\n', '')): close_though = " (close though -- all but EOLs match)" self.assertEqual(python_html, perl_html, _dedent("""\ markdown2.py didn't produce the same output as Markdown.pl%s: ---- text ---- %s ---- Python markdown2.py HTML ---- %s ---- Perl Markdown.pl HTML ---- %s""") % (close_though, _display(text), _display(python_html), _display(perl_html))) def _assertMarkdownPath(self, text_path, encoding="utf-8", opts=None, toc_html_path=None, metadata_path=None): text = codecs.open(text_path, 'r', encoding=encoding).read() html_path = splitext(text_path)[0] + ".html" html = codecs.open(html_path, 'r', encoding=encoding).read() extra = {} if toc_html_path: extra["toc_html"] = codecs.open(toc_html_path, 'r', encoding=encoding).read() extra["toc_html_path"] = toc_html_path if metadata_path: extra["metadata"] = json_loads( codecs.open(metadata_path, 'r', encoding=encoding).read()) extra["metadata_path"] = metadata_path self._assertMarkdown(text, html, text_path, html_path, opts=opts, **extra) def _assertMarkdown(self, text, html, text_path=None, html_path=None, opts=None, toc_html=None, toc_html_path=None, metadata=None, metadata_path=None): """Assert that markdown2.py produces the expected HTML.""" if text_path is None: text_path = "This on almost looks like an hr, except for the trailing '+'. In older versions of markdown2.py this was pathologically slow:
- - - - - - - - - - - - - - - - - - - - - - - - - +
""" start = time.time() self._assertMarkdown(text, html) end = time.time() delta = end - start self.assertTrue(delta < 1.0, "It took more than 1s to process " "'slow-hr'. It took %.2fs. Too slow!" % delta) test_slow_hr.tags = ["perf"] def test_code_in_strong(self): self._assertMarkdown( '**look at `this code` call**', 'look at this code
call
#!/usr/bin/python\nprint "hi"\n
\n')
test_starter_pre.tags = ["pre", "recipes"]
def test_pre(self):
self._assertMarkdown(_dedent('''\
some starter text
#!/usr/bin/python
print "hi"'''),
'some starter text
\n\n#!/usr/bin/python\nprint "hi"\n
\n')
def test_russian(self):
ko = '\u043b\u0449' # 'ko' on russian keyboard
self._assertMarkdown("## %s" % ko,
'&
AT&T
AT&T
markdown2-2.3.7/test/tm-cases/ampersands.tags 0000644 0000765 0000024 00000000015 13166755316 021217 0 ustar nick staff 0000000 0000000 htmlentities markdown2-2.3.7/test/tm-cases/ampersands.text 0000644 0000765 0000024 00000000046 13166755316 021251 0 ustar nick staff 0000000 0000000 & AT&T AT&T [AT&T AT&T](/) markdown2-2.3.7/test/tm-cases/auto_link.html 0000644 0000765 0000024 00000000613 12240460102 021033 0 ustar nick staff 0000000 0000000I can has autolink? http://icanhascheeseburger.com
Ask garfield: garfield@example.com
markdown2-2.3.7/test/tm-cases/auto_link.text 0000644 0000765 0000024 00000000133 12240460102 021050 0 ustar nick staff 0000000 0000000 I can has autolink?Auto-link email with underscores failed at one point: - foo_bar@example.com - foo@_example.com - foo@an_example.com - foo@_example_.com - nounderscore@example.com - check_this_out@coolpeople.com
markdown2-2.3.7/test/tm-cases/auto_link_email_with_underscore.tags 0000644 0000765 0000024 00000000010 12240460102 025447 0 ustar nick staff 0000000 0000000 issue26 markdown2-2.3.7/test/tm-cases/auto_link_email_with_underscore.text 0000644 0000765 0000024 00000000317 12240460102 025507 0 ustar nick staff 0000000 0000000 Auto-link email with underscores failed at one point: -I can has autolink? http://icanhascheeseburger.com
Ask garfield: garfield@example.com
markdown2-2.3.7/test/tm-cases/auto_link_safe_mode.opts 0000644 0000765 0000024 00000000024 12240460102 023052 0 ustar nick staff 0000000 0000000 {'safe_mode': True} markdown2-2.3.7/test/tm-cases/auto_link_safe_mode.tags 0000644 0000765 0000024 00000000021 12240460102 023020 0 ustar nick staff 0000000 0000000 issue7 safe_mode markdown2-2.3.7/test/tm-cases/auto_link_safe_mode.text 0000644 0000765 0000024 00000000133 12240460102 023052 0 ustar nick staff 0000000 0000000 I can has autolink?blah [HTML_REMOVED] blah
[HTML_REMOVED]yowzer![HTML_REMOVED]
blah
[HTML_REMOVED]alert(1)[HTML_REMOVED]
link4 >[HTML_REMOVED]alert(1)[HTML_REMOVED]
<img src="javascript:alert(1)"