From 425fde141f17973aea0a3a85e44632fe18737996 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 12 Jan 2012 23:20:45 -0500 Subject: attempt at a fix for issue w/ MD links inside of html tagish stuff with safe mode on. --- markdown/postprocessors.py | 7 +++++-- tests/html4_safe/link.html | 1 + tests/html4_safe/link.txt | 1 + tests/html4_safe/test.cfg | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/html4_safe/link.html create mode 100644 tests/html4_safe/link.txt create mode 100644 tests/html4_safe/test.cfg diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py index b21a569..962728b 100644 --- a/markdown/postprocessors.py +++ b/markdown/postprocessors.py @@ -49,7 +49,6 @@ class RawHtmlPostprocessor(Postprocessor): """ Iterate over html stash and restore "safe" html. """ for i in range(self.markdown.htmlStash.html_counter): html, safe = self.markdown.htmlStash.rawHtmlBlocks[i] - html = self.unescape(html) if self.markdown.safeMode and not safe: if str(self.markdown.safeMode).lower() == 'escape': html = self.escape(html) @@ -61,6 +60,7 @@ class RawHtmlPostprocessor(Postprocessor): text = text.replace("

%s

" % (self.markdown.htmlStash.get_placeholder(i)), html + "\n") + html = self.unescape(html) text = text.replace(self.markdown.htmlStash.get_placeholder(i), html) return text @@ -69,7 +69,10 @@ class RawHtmlPostprocessor(Postprocessor): """ Unescape any markdown escaped text within inline html. """ for k, v in self.markdown.treeprocessors['inline'].stashed_nodes.items(): ph = util.INLINE_PLACEHOLDER % k - html = html.replace(ph, '\%s' % v) + try: + html = html.replace(ph, '%s' % util.etree.tostring(v)) + except: + html = html.replace(ph, '\%s' % v) return html def escape(self, html): diff --git a/tests/html4_safe/link.html b/tests/html4_safe/link.html new file mode 100644 index 0000000..642f4be --- /dev/null +++ b/tests/html4_safe/link.html @@ -0,0 +1 @@ +

<here gmail.com is a link>

\ No newline at end of file diff --git a/tests/html4_safe/link.txt b/tests/html4_safe/link.txt new file mode 100644 index 0000000..28331a7 --- /dev/null +++ b/tests/html4_safe/link.txt @@ -0,0 +1 @@ + diff --git a/tests/html4_safe/test.cfg b/tests/html4_safe/test.cfg new file mode 100644 index 0000000..66f7bf0 --- /dev/null +++ b/tests/html4_safe/test.cfg @@ -0,0 +1,3 @@ +[DEFAULT] +output_format=html4 +safe_mode=escape -- cgit v1.2.3 From 1a291cf491a8e6aa4a2e602f5f732d1092fba2a6 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 20 Dec 2011 17:50:19 +0800 Subject: New footnotes configuration option: BACKLINK_TEXT (second try). BACKLINK_TEXT specifies the text that's used in the link at the end of the footnote to link back up to the reader's place. It still defaults to "↩". Okay, so at first I had an uncessarily complicated commit for this and submitted a pull request. Waylan showed me a better way to do it, here: https://github.com/startling/Python-Markdown/commit/ee7d1a26c76f970c12226ca48ba52dc1d32f2488#markdown/extensions/footnotes.py-P19 So I made another commit and added it to the pull request. But then I accidentally added yet another commit to the pull request, accidentally. Since then, I've realized it would be best to start with a new branch and closed that first pull request. Hopefully this will be the last try. --- markdown/extensions/footnotes.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index d05edda..a4c897b 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -43,7 +43,11 @@ class FootnoteExtension(markdown.Extension): 'UNIQUE_IDS': [False, "Avoid name collisions across " - "multiple calls to reset()."]} + "multiple calls to reset()."], + "BACKLINK_TEXT": + ["↩", + "The text string that links from the footnote to the reader's place."] + } for key, value in configs: self.config[key][0] = value @@ -282,10 +286,12 @@ class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor): class FootnotePostprocessor(markdown.postprocessors.Postprocessor): """ Replace placeholders with html entities. """ + def __init__(self, footnotes): + self.footnotes = footnotes def run(self, text): text = text.replace(FN_BACKLINK_TEXT, "↩") - return text.replace(NBSP_PLACEHOLDER, " ") + return text.replace(NBSP_PLACEHOLDER, self.footnotes.getConfig("BACKLINK_TEXT")) def makeExtension(configs=[]): """ Return an instance of the FootnoteExtension """ -- cgit v1.2.3 From e5188ca6cc170b83a7145b10deb9edd4c051e9d0 Mon Sep 17 00:00:00 2001 From: tim Date: Wed, 21 Dec 2011 05:08:22 +0800 Subject: fixed an error in the BACKLINK_TEXT option in the footnotes extension. I accidentally changed the wrong line (L294 instead of L293) to "self.footnotes.getConfig("BACKLINK_TEXT")" before. This fixes that. --- markdown/extensions/footnotes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index a4c897b..2f3ceac 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -290,8 +290,8 @@ class FootnotePostprocessor(markdown.postprocessors.Postprocessor): self.footnotes = footnotes def run(self, text): - text = text.replace(FN_BACKLINK_TEXT, "↩") - return text.replace(NBSP_PLACEHOLDER, self.footnotes.getConfig("BACKLINK_TEXT")) + text = text.replace(FN_BACKLINK_TEXT, self.footnotes.getConfig("BACKLINK_TEXT")) + return text.replace(NBSP_PLACEHOLDER, " ") def makeExtension(configs=[]): """ Return an instance of the FootnoteExtension """ -- cgit v1.2.3 From 4366483519f8fd935b916ede228c3b8a2b45dba9 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 29 Dec 2011 00:03:41 +0800 Subject: Fixed issue #66. Silly error. Not sure why the shebang lines were capitalized. Thanks for the report. --- markdown/extensions/def_list.py | 2 +- markdown/extensions/tables.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/extensions/def_list.py b/markdown/extensions/def_list.py index b5ba92f..da1726a 100644 --- a/markdown/extensions/def_list.py +++ b/markdown/extensions/def_list.py @@ -1,4 +1,4 @@ -#!/usr/bin/env Python +#!/usr/bin/env python """ Definition List Extension for Python-Markdown ============================================= diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index f780bb3..1388cb5 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -1,4 +1,4 @@ -#!/usr/bin/env Python +#!/usr/bin/env python """ Tables Extension for Python-Markdown ==================================== -- cgit v1.2.3 From 12baab2e34a49530f3b712d2faaf59560ff993ef Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 29 Dec 2011 00:20:22 +0800 Subject: Fixed #60. When we updated codehilite, we forgot to update fenced_codee to work with it. --- markdown/extensions/fenced_code.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 5a50ba3..0534251 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -130,12 +130,12 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor): # is enabled, so we call it to highlite the code if self.codehilite_conf: highliter = CodeHilite(m.group('code'), - linenos=self.codehilite_conf['force_linenos'], - guess_lang=self.codehilite_conf['guess_lang'], - css_class=self.codehilite_conf['css_class'], - style=self.codehilite_conf['pygments_style'], + linenos=self.codehilite_conf['force_linenos'][0], + guess_lang=self.codehilite_conf['guess_lang'][0], + css_class=self.codehilite_conf['css_class'][0], + style=self.codehilite_conf['pygments_style'][0], lang=(m.group('lang') or None), - noclasses=self.codehilite_conf['noclasses']) + noclasses=self.codehilite_conf['noclasses'][0]) code = highliter.hilite() else: -- cgit v1.2.3 From 35930e0928e19e37f81c906d5d11dfcc1087092b Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 29 Dec 2011 02:11:48 +0800 Subject: Fixed #69. url_sanitize no longer crashes on unparsable urls. Also optimized the code to bypass parsing when not in safe_mode and return immediately upon failure rather than continue parsing when in safe_mode. Note that in Python2.7+ more urls may fail than in older versions because IPv6 support was added to urlparse and it apparently mistakenly identifies some urls as IPv6 when they are not. Seeing this only applies to safe_mode now, I don't really care. --- markdown/inlinepatterns.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 109cc05..51b06d9 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -311,20 +311,29 @@ class LinkPattern(Pattern): `username:password@host:port`. """ + if not self.markdown.safeMode: + # Return immediately bipassing parsing. + return url + + try: + scheme, netloc, path, params, query, fragment = url = urlparse(url) + except ValueError: + # Bad url - so bad it couldn't be parsed. + return '' + locless_schemes = ['', 'mailto', 'news'] - scheme, netloc, path, params, query, fragment = url = urlparse(url) - safe_url = False - if netloc != '' or scheme in locless_schemes: - safe_url = True + if netloc == '' or scheme not in locless_schemes: + # This fails regardless of anything else. + # Return immediately to save additional proccessing + return '' for part in url[2:]: if ":" in part: - safe_url = False + # Not a safe url + return '' - if self.markdown.safeMode and not safe_url: - return '' - else: - return urlunparse(url) + # Url passes all tests. Return url as-is. + return urlunparse(url) class ImagePattern(LinkPattern): """ Return a img element from the given match. """ -- cgit v1.2.3 From f3959302ef1ffa5ea3811a92ef97903320331020 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 29 Dec 2011 04:59:47 +0800 Subject: Fixed #61. stdin and stdout should work better in python 3. Apparently, in Python3 stdin and stdout take str (unicode) not bytes. This provides a solution that will work in both python 2 & 3. --- markdown/__init__.py | 40 +++++++++++++++++++++++++--------------- markdown/__main__.py | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/markdown/__init__.py b/markdown/__init__.py index 5764c60..0a27475 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -333,28 +333,38 @@ class Markdown: encoding = encoding or "utf-8" # Read the source - if isinstance(input, basestring): - input_file = codecs.open(input, mode="r", encoding=encoding) + if input: + if isinstance(input, str): + input_file = codecs.open(input, mode="r", encoding=encoding) + else: + input_file = codecs.getreader(encoding)(input) + text = input_file.read() + input_file.close() else: - input = input or sys.stdin - input_file = codecs.getreader(encoding)(input) - text = input_file.read() - input_file.close() - text = text.lstrip(u'\ufeff') # remove the byte-order mark + text = sys.stdin.read() + if not isinstance(text, unicode): + text = text.decode(encoding) + + text = text.lstrip('\ufeff') # remove the byte-order mark # Convert html = self.convert(text) # Write to file or stdout - if isinstance(output, basestring): - output_file = codecs.open(output, "w", - encoding=encoding, - errors="xmlcharrefreplace") - output_file.write(html) - output_file.close() + if output: + if isinstance(output, str): + output_file = codecs.open(output, "w", + encoding=encoding, + errors="xmlcharrefreplace") + output_file.write(html) + output_file.close() + else: + writer = codecs.getwriter(encoding) + output_file = writer(output, errors="xmlcharrefreplace") + output_file.write(html) + # Don't close here. User may want to write more. else: - output = output or sys.stdout - output.write(html.encode(encoding, "xmlcharrefreplace")) + sys.stdout.write(html) return self diff --git a/markdown/__main__.py b/markdown/__main__.py index 56afc10..b6a2e23 100644 --- a/markdown/__main__.py +++ b/markdown/__main__.py @@ -53,7 +53,7 @@ def parse_options(): (options, args) = parser.parse_args() if len(args) == 0: - input_file = sys.stdin + input_file = None else: input_file = args[0] -- cgit v1.2.3 From 5f959a21dac3a0245630a201f11fe95fb43c725f Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 30 Dec 2011 04:07:01 +0800 Subject: Fixed #70. Empty anglebrackets '<>' are now properly recognized as raw html. --- markdown/preprocessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index b59f057..28f731f 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -78,7 +78,7 @@ class HtmlBlockPreprocessor(Preprocessor): attrs[ma.group('attr2').strip()] = "" return tag, len(m.group(0)), attrs else: - tag = block[1:].replace(">", " ", 1).split()[0].lower() + tag = block[1:].split(">", 1)[0].lower() return tag, len(tag)+2, {} def _recursive_tagfind(self, ltag, rtag, start_index, block): -- cgit v1.2.3 From 44caa3aaa1022532f3ecdada6cff7fe5fd0a2c44 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 30 Dec 2011 05:19:46 +0800 Subject: Fixed #57. Multiline HTML Blocks no longer require a blank line after them. --- markdown/preprocessors.py | 9 ++++++++- tests/misc/multi-line-tags.html | 10 +++++++++- tests/misc/multi-line-tags.txt | 7 +++++++ tests/misc/multiline-comments.html | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 28f731f..a80f9fb 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -202,14 +202,21 @@ class HtmlBlockPreprocessor(Preprocessor): new_blocks.append(block) else: + #import pdb; pdb.set_trace() items.append(block) right_tag, data_index = self._get_right_tag(left_tag, - left_index, + 0, block) if self._equal_tags(left_tag, right_tag): # if find closing tag + + if data_index < len(block): + # we have more text after right_tag + items[-1] = block[:data_index] + text.insert(0, block[data_index:]) + in_tag = False if self.markdown_in_raw and 'markdown' in attrs.keys(): start = re.sub(r'\smarkdown(=[\'"]?[^> ]*[\'"]?)?', diff --git a/tests/misc/multi-line-tags.html b/tests/misc/multi-line-tags.html index 784c1dd..69899aa 100644 --- a/tests/misc/multi-line-tags.html +++ b/tests/misc/multi-line-tags.html @@ -2,4 +2,12 @@ asdf asdfasd - \ No newline at end of file + + +
+ +foo bar + +
+ +

No blank line.

\ No newline at end of file diff --git a/tests/misc/multi-line-tags.txt b/tests/misc/multi-line-tags.txt index 4ea3b02..9056473 100644 --- a/tests/misc/multi-line-tags.txt +++ b/tests/misc/multi-line-tags.txt @@ -4,3 +4,10 @@ asdf asdfasd + +
+ +foo bar + +
+No blank line. diff --git a/tests/misc/multiline-comments.html b/tests/misc/multiline-comments.html index 12f8cb5..29c17e9 100644 --- a/tests/misc/multiline-comments.html +++ b/tests/misc/multiline-comments.html @@ -2,7 +2,7 @@ foo ---> +-->

-- cgit v1.2.3 From 5d177e635c4c0c5ce2db636ba395d0d9b715892d Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 30 Dec 2011 06:31:32 +0800 Subject: Fixed #68. Blank line is not required after html comments. Interestingly, the change to the misc/mismatched-tags test is inline with PHP Markdown Extra's behavior but not markdown.pl, which produces invalid html. --- markdown/preprocessors.py | 24 ++++++++++-------------- tests/misc/comments.html | 6 +++++- tests/misc/comments.txt | 3 +++ tests/misc/mismatched-tags.html | 5 ++++- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index a80f9fb..0094d7b 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -143,21 +143,20 @@ class HtmlBlockPreprocessor(Preprocessor): if not in_tag: if block.startswith("<") and len(block.strip()) > 1: - left_tag, left_index, attrs = self._get_left_tag(block) - right_tag, data_index = self._get_right_tag(left_tag, - left_index, - block) if block[1] == "!": # is a comment block - left_tag = "--" - right_tag, data_index = self._get_right_tag(left_tag, - left_index, - block) - # keep checking conditions below and maybe just append + left_tag, left_index, attrs = "--", 2, () + else: + left_tag, left_index, attrs = self._get_left_tag(block) + right_tag, data_index = self._get_right_tag(left_tag, + left_index, + block) + # keep checking conditions below and maybe just append if data_index < len(block) \ - and util.isBlockLevel(left_tag): + and (util.isBlockLevel(left_tag) + or left_tag == '--'): text.insert(0, block[data_index:]) block = block[:data_index] @@ -202,12 +201,9 @@ class HtmlBlockPreprocessor(Preprocessor): new_blocks.append(block) else: - #import pdb; pdb.set_trace() items.append(block) - right_tag, data_index = self._get_right_tag(left_tag, - 0, - block) + right_tag, data_index = self._get_right_tag(left_tag, 0, block) if self._equal_tags(left_tag, right_tag): # if find closing tag diff --git a/tests/misc/comments.html b/tests/misc/comments.html index 005a755..2240ab9 100644 --- a/tests/misc/comments.html +++ b/tests/misc/comments.html @@ -2,4 +2,8 @@

X>0

-
as if
\ No newline at end of file +
as if
+ + + +

no blank line

\ No newline at end of file diff --git a/tests/misc/comments.txt b/tests/misc/comments.txt index 68302b0..d9186f0 100644 --- a/tests/misc/comments.txt +++ b/tests/misc/comments.txt @@ -5,3 +5,6 @@ X>0
as if
+ + +__no blank line__ diff --git a/tests/misc/mismatched-tags.html b/tests/misc/mismatched-tags.html index ec087e1..06bd57f 100644 --- a/tests/misc/mismatched-tags.html +++ b/tests/misc/mismatched-tags.html @@ -6,6 +6,9 @@

And this output

Compatible with PHP Markdown Extra 1.2.2 and Markdown.pl1.0.2b8:

-

text


+ +

text

+ +


Should be in p

\ No newline at end of file -- cgit v1.2.3 From e5d49077660d0000fd10d937f24b73b26712724a Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Sat, 14 Jan 2012 11:42:17 -0500 Subject: minor: adding some common OSX / emacs gitignore patterns --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ebf5e84..c57cc74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS* *.pyc *.bak *.swp @@ -8,4 +9,4 @@ tmp/* MANIFEST .venv *~ -#* +*#* -- cgit v1.2.3 From 542324b626e96eb368c1cac34beba2b95af5deb7 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Sat, 14 Jan 2012 12:47:20 -0500 Subject: Fix logic bug introduced in 35930e0928e19... --- markdown/inlinepatterns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 51b06d9..1829348 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -322,7 +322,7 @@ class LinkPattern(Pattern): return '' locless_schemes = ['', 'mailto', 'news'] - if netloc == '' or scheme not in locless_schemes: + if netloc == '' and scheme not in locless_schemes: # This fails regardless of anything else. # Return immediately to save additional proccessing return '' -- cgit v1.2.3 From a2377e1129331430998de821ed3abf38247edca1 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Sat, 14 Jan 2012 13:10:44 -0500 Subject: When safe mode is 'escape', don't allow bad html to stop further processing. See tests/html4_safe/html_then_blockquote.(txt|html). It looks like having unclosed block-level html elements was causing further processing not to happen, even in the case where we're escaping HTML. Since we're escaping HTML, it seems like it shouldn't affect processing at all. This changes output results in a couple of other tests, but the new output seems reasonable to me. --- markdown/preprocessors.py | 3 ++- tests/html4_safe/html_then_blockquote.html | 6 ++++++ tests/html4_safe/html_then_blockquote.txt | 6 ++++++ tests/safe_mode/inline-html-simple.html | 11 +++++++---- tests/safe_mode/script_tags.html | 26 +++++++++----------------- 5 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 tests/html4_safe/html_then_blockquote.html create mode 100644 tests/html4_safe/html_then_blockquote.txt diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 0094d7b..c0f0034 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -14,7 +14,8 @@ import odict def build_preprocessors(md_instance, **kwargs): """ Build the default set of preprocessors used by Markdown. """ preprocessors = odict.OrderedDict() - preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance) + if md_instance.safeMode != 'escape': + preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance) preprocessors["reference"] = ReferencePreprocessor(md_instance) return preprocessors diff --git a/tests/html4_safe/html_then_blockquote.html b/tests/html4_safe/html_then_blockquote.html new file mode 100644 index 0000000..5833cd4 --- /dev/null +++ b/tests/html4_safe/html_then_blockquote.html @@ -0,0 +1,6 @@ +

to:

+

<td /><td style="text-align: center; white-space: nowrap;"><br />

+
+

3) You don't need to alter all localization files. + Adding the new labels to the en_US files will do it.

+
\ No newline at end of file diff --git a/tests/html4_safe/html_then_blockquote.txt b/tests/html4_safe/html_then_blockquote.txt new file mode 100644 index 0000000..544df67 --- /dev/null +++ b/tests/html4_safe/html_then_blockquote.txt @@ -0,0 +1,6 @@ +to: + +
+ +> 3) You don't need to alter all localization files. +> Adding the new labels to the en_US files will do it. diff --git a/tests/safe_mode/inline-html-simple.html b/tests/safe_mode/inline-html-simple.html index ad19a77..aca9af0 100644 --- a/tests/safe_mode/inline-html-simple.html +++ b/tests/safe_mode/inline-html-simple.html @@ -29,7 +29,8 @@ Blah
<!-- Comment -->
 

Just plain comment, with trailing spaces on the line:

-

<!-- foo -->

+

<!-- foo -->
+

Code:

<hr />
 
@@ -37,9 +38,11 @@ Blah

<hr>

<hr/>

<hr />

-

<hr>

-

<hr/>

-

<hr />

+

<hr>
+

+

<hr/>
+

+

<hr />

<hr class="foo" id="bar" />

<hr class="foo" id="bar"/>

<hr class="foo" id="bar" >

\ No newline at end of file diff --git a/tests/safe_mode/script_tags.html b/tests/safe_mode/script_tags.html index df63ffc..f3b059d 100644 --- a/tests/safe_mode/script_tags.html +++ b/tests/safe_mode/script_tags.html @@ -1,13 +1,11 @@

This should be stripped/escaped in safe_mode.

<script> -alert("Hello world!") +alert("Hello world!") </script>

With blank lines.

-

<script> - -alert("Hello world!") - -</script>

+

<script>

+

alert("Hello world!")

+

</script>

Now with some weirdness

<script <!-- alert("Hello world!") @@ -15,14 +13,8 @@ alert("Hello world!")

Try another way.

<script <!-- alert("Hello world!") -</script <> - -This time with blank lines. - -<script <!-- - -alert("Hello world!") - -</script <> - -

\ No newline at end of file +</script <>

+

This time with blank lines.

+

<script <!--

+

alert("Hello world!")

+

</script <>

\ No newline at end of file -- cgit v1.2.3 From a9179833ae458861d8a4d72336a1df4ee4f6d070 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Tue, 17 Jan 2012 16:00:31 -0500 Subject: Fenced code blocks need to end with a fence on its own line. --- markdown/extensions/fenced_code.py | 2 +- tests/extensions/fenced_code.html | 32 ++++++++++++++++++++++++++++++++ tests/extensions/fenced_code.txt | 34 ++++++++++++++++++++++++++++++++++ tests/extensions/test.cfg | 3 +++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/extensions/fenced_code.html create mode 100644 tests/extensions/fenced_code.txt diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 0534251..9b99e5a 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -81,7 +81,7 @@ from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension # Global vars FENCED_BLOCK_RE = re.compile( \ - r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?P=fence)[ ]*$', + r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', re.MULTILINE|re.DOTALL ) CODE_WRAP = '
%s
' diff --git a/tests/extensions/fenced_code.html b/tests/extensions/fenced_code.html new file mode 100644 index 0000000..7b86e79 --- /dev/null +++ b/tests/extensions/fenced_code.html @@ -0,0 +1,32 @@ +

index 0000000..6e956a9

+
--- /dev/null
++++ b/test/data/stripped_text/mike-30-lili
+@@ -0,0 +1,27 @@
++Summary:
++ drift_mod.py |    1 +
++ 1 files changed, 1 insertions(+), 0 deletions(-)
++
++commit da4bfb04debdd994683740878d09988b2641513d
++Author: Mike Dirolf <mike@dirolf.com>
++Date:   Tue Jan 17 13:42:28 2012 -0500
++
++```
++minor: just wanted to push something.
++```
++
++diff --git a/drift_mod.py b/drift_mod.py
++index 34dfba6..8a88a69 100644
++
++```
++--- a/drift_mod.py
+++++ b/drift_mod.py
++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^('
++                                        '|\+ .*'
++                                        '|- .*'
++                                        ')$')
+++
++ def wrap_context_diffs(message_text):
++     return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,
++                       CONTEXT_DIFF_LINE_PATTERN,
++```
+
\ No newline at end of file diff --git a/tests/extensions/fenced_code.txt b/tests/extensions/fenced_code.txt new file mode 100644 index 0000000..73c0337 --- /dev/null +++ b/tests/extensions/fenced_code.txt @@ -0,0 +1,34 @@ +index 0000000..6e956a9 + +``` +--- /dev/null ++++ b/test/data/stripped_text/mike-30-lili +@@ -0,0 +1,27 @@ ++Summary: ++ drift_mod.py | 1 + ++ 1 files changed, 1 insertions(+), 0 deletions(-) ++ ++commit da4bfb04debdd994683740878d09988b2641513d ++Author: Mike Dirolf ++Date: Tue Jan 17 13:42:28 2012 -0500 ++ ++``` ++minor: just wanted to push something. ++``` ++ ++diff --git a/drift_mod.py b/drift_mod.py ++index 34dfba6..8a88a69 100644 ++ ++``` ++--- a/drift_mod.py +++++ b/drift_mod.py ++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^(' ++ '|\+ .*' ++ '|- .*' ++ ')$') +++ ++ def wrap_context_diffs(message_text): ++ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN, ++ CONTEXT_DIFF_LINE_PATTERN, ++``` +``` diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index c25bdfb..f3d0321 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -20,3 +20,6 @@ extensions=toc [wikilinks] extensions=wikilinks + +[fenced_code] +extensions=fenced_code -- cgit v1.2.3 From 69b365d07c7fabb206d9094398de2162cbcf6ba3 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Tue, 17 Jan 2012 16:52:39 -0500 Subject: Support github-flavored markdown by making the '.' optional before language type. --- markdown/extensions/fenced_code.py | 2 +- tests/extensions/github_flavored.html | 32 ++++++++++++++++++++++++++++++++ tests/extensions/github_flavored.txt | 34 ++++++++++++++++++++++++++++++++++ tests/extensions/test.cfg | 3 +++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/extensions/github_flavored.html create mode 100644 tests/extensions/github_flavored.txt diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 9b99e5a..95fe3b4 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -81,7 +81,7 @@ from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension # Global vars FENCED_BLOCK_RE = re.compile( \ - r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', + r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?<=\n)(?P=fence)[ ]*$', re.MULTILINE|re.DOTALL ) CODE_WRAP = '
%s
' diff --git a/tests/extensions/github_flavored.html b/tests/extensions/github_flavored.html new file mode 100644 index 0000000..60e16b1 --- /dev/null +++ b/tests/extensions/github_flavored.html @@ -0,0 +1,32 @@ +

index 0000000..6e956a9

+
--- /dev/null
++++ b/test/data/stripped_text/mike-30-lili
+@@ -0,0 +1,27 @@
++Summary:
++ drift_mod.py |    1 +
++ 1 files changed, 1 insertions(+), 0 deletions(-)
++
++commit da4bfb04debdd994683740878d09988b2641513d
++Author: Mike Dirolf <mike@dirolf.com>
++Date:   Tue Jan 17 13:42:28 2012 -0500
++
++```
++minor: just wanted to push something.
++```
++
++diff --git a/drift_mod.py b/drift_mod.py
++index 34dfba6..8a88a69 100644
++
++```
++--- a/drift_mod.py
+++++ b/drift_mod.py
++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^('
++                                        '|\+ .*'
++                                        '|- .*'
++                                        ')$')
+++
++ def wrap_context_diffs(message_text):
++     return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,
++                       CONTEXT_DIFF_LINE_PATTERN,
++```
+
\ No newline at end of file diff --git a/tests/extensions/github_flavored.txt b/tests/extensions/github_flavored.txt new file mode 100644 index 0000000..d0737bd --- /dev/null +++ b/tests/extensions/github_flavored.txt @@ -0,0 +1,34 @@ +index 0000000..6e956a9 + +```diff +--- /dev/null ++++ b/test/data/stripped_text/mike-30-lili +@@ -0,0 +1,27 @@ ++Summary: ++ drift_mod.py | 1 + ++ 1 files changed, 1 insertions(+), 0 deletions(-) ++ ++commit da4bfb04debdd994683740878d09988b2641513d ++Author: Mike Dirolf ++Date: Tue Jan 17 13:42:28 2012 -0500 ++ ++``` ++minor: just wanted to push something. ++``` ++ ++diff --git a/drift_mod.py b/drift_mod.py ++index 34dfba6..8a88a69 100644 ++ ++``` ++--- a/drift_mod.py +++++ b/drift_mod.py ++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^(' ++ '|\+ .*' ++ '|- .*' ++ ')$') +++ ++ def wrap_context_diffs(message_text): ++ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN, ++ CONTEXT_DIFF_LINE_PATTERN, ++``` +``` diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index f3d0321..ebe9a8f 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -23,3 +23,6 @@ extensions=wikilinks [fenced_code] extensions=fenced_code + +[github_flavored] +extensions=codehilite,fenced_code -- cgit v1.2.3