From 577acbd9f53cc398b43420dafe97fae100e38f62 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Thu, 27 Mar 2014 18:25:36 +0100 Subject: [PATCH] Add underline command in markdown --- dynastie/generators/__init__.py | 2 +- dynastie/generators/generator.py | 32 +++++++++++++++++++------------ dynastie/generators/markdown2.py | 3 +++ dynastie/templates/add_post.html | 1 + dynastie/templates/edit_post.html | 1 + dynastie/templates/generate.html | 4 ++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/dynastie/generators/__init__.py b/dynastie/generators/__init__.py index d766c5d..30b397f 100755 --- a/dynastie/generators/__init__.py +++ b/dynastie/generators/__init__.py @@ -18,4 +18,4 @@ along with Dynastie. If not, see . """ -__all__ = ["generator", "index", "post", "category", "tag", "archive", "rss", "atom", "all_posts"] +__all__ = ["generator", "index", "post", "category", "tag", "archive", "rss", "atom", "all_posts", "ljdc"] diff --git a/dynastie/generators/generator.py b/dynastie/generators/generator.py index b546d69..428c495 100755 --- a/dynastie/generators/generator.py +++ b/dynastie/generators/generator.py @@ -205,15 +205,20 @@ class DynastieGenerator: return root filename = base.getAttribute('file') - if not base.hasAttribute('block'): - self.addError('No \'block\' attribute defined') - return root - target_block = base.getAttribute('block') - if not os.path.exists(src + '/' + filename): self.addError('Base ' + filename + ' doesn\'t exists') return root + target_blocks = base.getElementsByTagNameNS(self.URI, 'block') + if len(target_blocks) == 0: + self.addError('No \'block\' defined in ' + src + '/' + filename) + return root + + for target_block in target_blocks: + if not target_block.hasAttribute('name'): + self.addError('Every block must have a name in ' + src + '/' + filename) + return root + dom2 = root try: dom2 = parse(src + '/' + filename) @@ -225,19 +230,22 @@ class DynastieGenerator: block_found = False for block in blocks: if not block.hasAttribute('name'): - self.addError('block has no attribute \'name\' in ' + filename) + self.addError('block has no attribute \'name\' in ' + src + '/' + filename) return root blockname = block.getAttribute('name') - if blockname != target_block: - continue + for target_block in target_blocks: + + if blockname != target_block.getAttribute('name'): + continue - for child in root.childNodes: - block.parentNode.appendChild(child.cloneNode(True)) + for child in target_block.childNodes: + block.parentNode.appendChild(child.cloneNode(True)) + block_found = True + break block.parentNode.removeChild(block) - block_found = True if not block_found: - self.addError('Block ' + target_block + ' not found in ' + src + '/' + filename) + self.addError('Any block found in ' + src + '/' + filename) return root root = dom2.firstChild diff --git a/dynastie/generators/markdown2.py b/dynastie/generators/markdown2.py index 6cf850d..dafa409 100755 --- a/dynastie/generators/markdown2.py +++ b/dynastie/generators/markdown2.py @@ -1614,16 +1614,19 @@ class Markdown(object): _code_friendly_strong_re = re.compile(r"\*\*(?=\S)(.+?[*_]*)(?<=\S)\*\*", re.S) _code_friendly_em_re = re.compile(r"\*(?=\S)(.+?)(?<=\S)\*", re.S) _code_friendly_line_re = re.compile(r"\~\~(?=\S)(.+?)(?<=\S)\~\~", re.S) + _code_friendly_underline_re = re.compile(r"\~(?=\S)(.+?)(?<=\S)\~", re.S) def _do_italics_and_bold(self, text): # must go first: if "code-friendly" in self.extras: text = self._code_friendly_strong_re.sub(r"\1", text) text = self._code_friendly_em_re.sub(r"\1", text) text = self._code_friendly_line_re.sub(r"\1", text) + text = self._code_friendly_underline_re.sub(r"\1", text) else: text = self._strong_re.sub(r"\2", text) text = self._em_re.sub(r"\2", text) text = self._code_friendly_line_re.sub(r"\1", text) + text = self._code_friendly_underline_re.sub(r"\1", text) return text # "smarty-pants" extra: Very liberal in interpreting a single prime as an diff --git a/dynastie/templates/add_post.html b/dynastie/templates/add_post.html index adc194c..05909a8 100755 --- a/dynastie/templates/add_post.html +++ b/dynastie/templates/add_post.html @@ -46,6 +46,7 @@ Available tags:
_italic_
italic
**bold**
bold
~~line through~~
line through
+
~underline~
underline
>Citation

 * Unordered list
diff --git a/dynastie/templates/edit_post.html b/dynastie/templates/edit_post.html
index 63444c1..70ad474 100755
--- a/dynastie/templates/edit_post.html
+++ b/dynastie/templates/edit_post.html
@@ -58,6 +58,7 @@ Available tags:
 
_italic_
italic
**bold**
bold
~~line through~~
line through
+
~underline~
underline
>Citation

 * Unordered list
diff --git a/dynastie/templates/generate.html b/dynastie/templates/generate.html
index 3bac384..f2bb919 100755
--- a/dynastie/templates/generate.html
+++ b/dynastie/templates/generate.html
@@ -19,6 +19,10 @@
 

{% endautoescape %} {% endif %} +
+{% csrf_token %} + +
{% if posts|length == 0 %}

Any post available