From bb00fc58cf0e08c07c5705c55cf7c9d5dcf94595 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Tue, 1 Jul 2008 23:13:02 -0700 Subject: Using control characters for HTML placeholders --- markdown.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/markdown.py b/markdown.py index 422cde4..0b1e325 100644 --- a/markdown.py +++ b/markdown.py @@ -108,8 +108,11 @@ EXECUTABLE_NAME_FOR_USAGE = "python markdown.py" # --------------- CONSTANTS YOU _SHOULD NOT_ HAVE TO CHANGE ---------- # a template for html placeholders -HTML_PLACEHOLDER_PREFIX = "qaodmasdkwaspemas" -HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%dajkqlsmdqpakldnzsdfls" +START = u'\u0001' +END = u'\u0002' +NULL = u'\u0001' +HTML_PLACEHOLDER_PREFIX = START+"html"+NULL +HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d"+END+"html"+NULL BLOCK_LEVEL_ELEMENTS = ['p', 'div', 'blockquote', 'pre', 'table', 'dl', 'ol', 'ul', 'script', 'noscript', @@ -1951,6 +1954,10 @@ class Markdown: return u"" # Fixup the source text + + for controlChar in (START, END, NULL) : + self.source = self.source.replace(controlChar, "") + self.source = self.source.replace("\r\n", "\n").replace("\r", "\n") self.source += "\n\n" self.source = self.source.expandtabs(TAB_LENGTH) -- cgit v1.2.3 From 2edd84eac6d419f7a20f779fbe120dd76ca195a8 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Tue, 1 Jul 2008 23:24:50 -0700 Subject: Switching to simpler non-printable placeholders. --- markdown.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/markdown.py b/markdown.py index 0b1e325..b141757 100644 --- a/markdown.py +++ b/markdown.py @@ -110,9 +110,8 @@ EXECUTABLE_NAME_FOR_USAGE = "python markdown.py" # a template for html placeholders START = u'\u0001' END = u'\u0002' -NULL = u'\u0001' -HTML_PLACEHOLDER_PREFIX = START+"html"+NULL -HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d"+END+"html"+NULL +HTML_PLACEHOLDER_PREFIX = START+"html:" +HTML_PLACEHOLDER = HTML_PLACEHOLDER_PREFIX + "%d"+END BLOCK_LEVEL_ELEMENTS = ['p', 'div', 'blockquote', 'pre', 'table', 'dl', 'ol', 'ul', 'script', 'noscript', @@ -1955,8 +1954,8 @@ class Markdown: # Fixup the source text - for controlChar in (START, END, NULL) : - self.source = self.source.replace(controlChar, "") + self.source = self.source.replace(START, "") + self.source = self.source.replace(END, "") self.source = self.source.replace("\r\n", "\n").replace("\r", "\n") self.source += "\n\n" -- cgit v1.2.3 From bf7cf776daa26d734c10a6039efe64113f066045 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 17 Jul 2008 15:03:50 -0400 Subject: Import failures in load_extension are again silent (Markdown continues without the extension). Added the overridable extendMarkdown method to the Extension class which makes it easy for load_extension to create and return a dummy extension on import failure. Besides, it should be there anyway to document the API. --- markdown.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/markdown.py b/markdown.py index b141757..95c5f4b 100644 --- a/markdown.py +++ b/markdown.py @@ -2106,6 +2106,22 @@ class Extension: """ Set a config setting for `key` with the given `value`. """ self.config[key][0] = value + def extendMarkdown(self, md, md_globals): + """ + Add the various proccesors and patterns to the Markdown Instance. + + This method must be overriden by every extension. + + Ketword arguments: + + * md: The Markdown instance. + + * md_globals: All global variables availabel in the markdown module + namespace. + + """ + pass + def load_extension(ext_name, configs = []): """ @@ -2135,11 +2151,12 @@ def load_extension(ext_name, configs = []): try: module = __import__(extension_module_name) - except: - message(CRITICAL, - "couldn't load extension %s (looking for %s module)" + except ImportError: + message(WARN, + "Couldn't load extension '%s' from \"%s\" - continuing without." % (ext_name, extension_module_name) ) - sys.exit(1) + # Return a dummy (do nothing) Extension as silent failure + return Extension(configs={}) return module.makeExtension(configs.items()) -- cgit v1.2.3 From caef3e90d46830db37888a7f7f897c450cf4f1e7 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Sun, 20 Jul 2008 00:15:08 -0700 Subject: Fixing ticket 000007 (Ordered and unordered list merged). --- markdown.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/markdown.py b/markdown.py index 95c5f4b..86f83ab 100644 --- a/markdown.py +++ b/markdown.py @@ -1669,8 +1669,7 @@ class Markdown: break # Check if the next non-blank line is still a part of the list - if ( RE.regExp['ul'].match(next) or - RE.regExp['ol'].match(next) or + if ( RE.regExp[listexpr].match(next) or RE.regExp['tabbed'].match(next) ): # get rid of any white space in the line items[item].append(line.strip()) -- cgit v1.2.3 From 99cda0ae525470c23bb59334e141baeabe963445 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Fri, 25 Jul 2008 10:52:38 -0700 Subject: Darius Bacon's patch for the RSS extension for the case where no items are defined. --- mdx_rss.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mdx_rss.py b/mdx_rss.py index 2117baf..c30440a 100644 --- a/mdx_rss.py +++ b/mdx_rss.py @@ -78,6 +78,7 @@ class RssPostProcessor (markdown.Postprocessor): ("description", None)): channel.appendChild(doc.createElement(tag, textNode = text)) + item = None for child in oldDocElement.childNodes : if child.type == "element" : -- cgit v1.2.3 From 6a63cadc9a7738c9495bb1eec435908a11fec469 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Tue, 29 Jul 2008 09:33:27 -0700 Subject: Adding extensions tests. --- test-markdown.py | 3 ++- tests/extensions-x-codehilite/code.html | 19 +++++++++++++++++++ tests/extensions-x-codehilite/code.txt | 12 ++++++++++++ tests/extensions-x-tables/tables.html | 30 ++++++++++++++++++++++++++++++ tests/extensions-x-tables/tables.txt | 15 +++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/extensions-x-codehilite/code.html create mode 100644 tests/extensions-x-codehilite/code.txt create mode 100644 tests/extensions-x-tables/tables.html create mode 100644 tests/extensions-x-tables/tables.txt diff --git a/test-markdown.py b/test-markdown.py index bc2b891..440ec42 100644 --- a/test-markdown.py +++ b/test-markdown.py @@ -358,6 +358,7 @@ markdown = __import__(MARKDOWN_FILE) testDirectory("tests/markdown-test", measure_time=True) testDirectory("tests/misc", measure_time=True) -#testDirectory("tests/extensions-x-footnotes") +testDirectory("tests/extensions-x-footnotes") +#testDirectory("tests/extensions-x-tables") # testDirectory("tests/extensions-x-ext1-ext2") testDirectory("tests/safe_mode", measure_time=True, safe_mode="escape") diff --git a/tests/extensions-x-codehilite/code.html b/tests/extensions-x-codehilite/code.html new file mode 100644 index 0000000..43b09ea --- /dev/null +++ b/tests/extensions-x-codehilite/code.html @@ -0,0 +1,19 @@ + +

Some text +

+
1
+2
+3
+4
+5
+6
def __init__ (self, pattern) :
+    self.pattern = pattern
+    self.compiled_re = re.compile("^(.*)%s(.*)$" % pattern, re.DOTALL)
+
+def getCompiledRegExp (self) :
+    return self.compiled_re
+
+

More text +

+ + diff --git a/tests/extensions-x-codehilite/code.txt b/tests/extensions-x-codehilite/code.txt new file mode 100644 index 0000000..6c62e6a --- /dev/null +++ b/tests/extensions-x-codehilite/code.txt @@ -0,0 +1,12 @@ + +Some text + + #!python + def __init__ (self, pattern) : + self.pattern = pattern + self.compiled_re = re.compile("^(.*)%s(.*)$" % pattern, re.DOTALL) + + def getCompiledRegExp (self) : + return self.compiled_re + +More text \ No newline at end of file diff --git a/tests/extensions-x-tables/tables.html b/tests/extensions-x-tables/tables.html new file mode 100644 index 0000000..fad47b2 --- /dev/null +++ b/tests/extensions-x-tables/tables.html @@ -0,0 +1,30 @@ + +

Before +

+ + + + + + +
a b
c d

Another +

+ + + + + + + + + + + + + + + +
a b
a b
a b
a b
c d

After +

+ + diff --git a/tests/extensions-x-tables/tables.txt b/tests/extensions-x-tables/tables.txt new file mode 100644 index 0000000..1cdab46 --- /dev/null +++ b/tests/extensions-x-tables/tables.txt @@ -0,0 +1,15 @@ +Before + +| a |* b *| +| [c](#) | *d* | + +Another + +| a | b | +| _a_ | b | +| a | b | +| a | b | +| c | *d* | + +After + -- cgit v1.2.3