From 2a8550ea467e1534d525e1220716b8a5281028c1 Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Tue, 27 Dec 2011 16:21:39 -0500 Subject: Allow tildes or backticks in the fenced_code extension to support the syntax used by github --- markdown/extensions/fenced_code.py | 4 +- tests/extensions/fenced_code_blocks.html | 70 ++++++++++++++++++++++++++++ tests/extensions/fenced_code_blocks.txt | 80 ++++++++++++++++++++++++++++++++ tests/extensions/test.cfg | 6 ++- 4 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 tests/extensions/fenced_code_blocks.html create mode 100644 tests/extensions/fenced_code_blocks.txt diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index e5b3350..87cdfc8 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -49,6 +49,8 @@ Language tags:
# Some python code
     
+Optionally backticks instead of tildes as per how github's code block markdown is identified. + Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). Project website: @@ -69,7 +71,7 @@ from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension # Global vars FENCED_BLOCK_RE = re.compile( \ - r'(?P^~{3,})[ ]*(\{?\.(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?P=fence)[ ]*$', + r'(?P^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P.*?)(?P=fence)[ ]*$', re.MULTILINE|re.DOTALL ) CODE_WRAP = '
%s
' diff --git a/tests/extensions/fenced_code_blocks.html b/tests/extensions/fenced_code_blocks.html new file mode 100644 index 0000000..4a0a625 --- /dev/null +++ b/tests/extensions/fenced_code_blocks.html @@ -0,0 +1,70 @@ +Xo
Fenced
+
+ +

Code block starting and ending with empty lines:

+ +


Fenced + + +
+ +

Indented code block containing fenced code block sample:

+ +
~~~
+Fenced
+~~~
+
+ +

Fenced code block with indented code block sample:

+ +
Some text
+
+    Indented code block sample code
+
+ +

Fenced code block with long markers:

+ +
Fenced
+
+ +

Fenced code block with fenced code block markers of different length in it:

+ +
In code block
+~~~
+Still in code block
+~~~~~
+Still in code block
+
+ +

Fenced code block with Markdown header and horizontal rule:

+ +
#test
+---
+
+ +

Fenced code block with link definitions, footnote definition and +abbreviation definitions:

+ +
[example]: http://example.com/
+
+[^1]: Footnote def
+
+*[HTML]: HyperText Markup Language
+
+ +
[example]: http://backticks.com/
+
+[^1]: Footnote def
+
+*[HTML]: HyperText Markup Language
+
+ +
testing tildes in backticks
+
+~~~
+
+ +
testing tildes in backticks
+
+```
+
diff --git a/tests/extensions/fenced_code_blocks.txt b/tests/extensions/fenced_code_blocks.txt new file mode 100644 index 0000000..be0f997 --- /dev/null +++ b/tests/extensions/fenced_code_blocks.txt @@ -0,0 +1,80 @@ +~~~ +Fenced +~~~ + +Code block starting and ending with empty lines: +~~~ + + +Fenced + + +~~~ + +Indented code block containing fenced code block sample: + + ~~~ + Fenced + ~~~ + +Fenced code block with indented code block sample: + +~~~ +Some text + + Indented code block sample code +~~~ + +Fenced code block with long markers: + +~~~~~~~~~~~~~~~~~~ +Fenced +~~~~~~~~~~~~~~~~~~ + +Fenced code block with fenced code block markers of different length in it: + +~~~~ +In code block +~~~ +Still in code block +~~~~~ +Still in code block +~~~~ + +Fenced code block with Markdown header and horizontal rule: + +~~~ +#test +--- +~~~ + +Fenced code block with link definitions, footnote definition and +abbreviation definitions: + +~~~ +[example]: http://example.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +~~~ + +``` +[example]: http://backticks.com/ + +[^1]: Footnote def + +*[HTML]: HyperText Markup Language +``` + +````` +testing tildes in backticks + +~~~ +````` + +~~~ +testing backticks in tildes + +``` +~~~ diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index 671f2a5..c271b02 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -4,7 +4,7 @@ extensions=attr_list [codehilite] extensions=codehilite # This passes or not based on version of pygments. -skip=1 +skip=1 [toc] extensions=toc @@ -20,3 +20,7 @@ extensions=toc [wikilinks] extensions=wikilinks + +[fenced_code_blocks] +extensions=fenced_code +normalize=1 -- cgit v1.2.3 From 5adec8b440ffc2934ee7120308f7e6e9d27b6e74 Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Tue, 27 Dec 2011 16:22:04 -0500 Subject: common emacs support for a .gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a00737a..ebf5e84 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ dist/* tmp/* MANIFEST .venv +*~ +#* -- cgit v1.2.3 From da6f050f64b54cf81659107f24c1977fc5226cfb Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Tue, 27 Dec 2011 16:44:02 -0500 Subject: appropriately move the tests to the fenced code documentation in the extension source --- markdown/extensions/fenced_code.py | 12 ++++- tests/extensions/fenced_code_blocks.html | 70 ---------------------------- tests/extensions/fenced_code_blocks.txt | 80 -------------------------------- 3 files changed, 11 insertions(+), 151 deletions(-) delete mode 100644 tests/extensions/fenced_code_blocks.html delete mode 100644 tests/extensions/fenced_code_blocks.txt diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py index 87cdfc8..5a50ba3 100644 --- a/markdown/extensions/fenced_code.py +++ b/markdown/extensions/fenced_code.py @@ -49,7 +49,17 @@ Language tags:
# Some python code
     
-Optionally backticks instead of tildes as per how github's code block markdown is identified. +Optionally backticks instead of tildes as per how github's code block markdown is identified: + + >>> text = ''' + ... ````` + ... # Arbitrary code + ... ~~~~~ # these tildes will not close the block + ... `````''' + >>> print markdown.markdown(text, extensions=['fenced_code']) +
# Arbitrary code
+    ~~~~~ # these tildes will not close the block
+    
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). diff --git a/tests/extensions/fenced_code_blocks.html b/tests/extensions/fenced_code_blocks.html deleted file mode 100644 index 4a0a625..0000000 --- a/tests/extensions/fenced_code_blocks.html +++ /dev/null @@ -1,70 +0,0 @@ -Xo
Fenced
-
- -

Code block starting and ending with empty lines:

- -


Fenced - - -
- -

Indented code block containing fenced code block sample:

- -
~~~
-Fenced
-~~~
-
- -

Fenced code block with indented code block sample:

- -
Some text
-
-    Indented code block sample code
-
- -

Fenced code block with long markers:

- -
Fenced
-
- -

Fenced code block with fenced code block markers of different length in it:

- -
In code block
-~~~
-Still in code block
-~~~~~
-Still in code block
-
- -

Fenced code block with Markdown header and horizontal rule:

- -
#test
----
-
- -

Fenced code block with link definitions, footnote definition and -abbreviation definitions:

- -
[example]: http://example.com/
-
-[^1]: Footnote def
-
-*[HTML]: HyperText Markup Language
-
- -
[example]: http://backticks.com/
-
-[^1]: Footnote def
-
-*[HTML]: HyperText Markup Language
-
- -
testing tildes in backticks
-
-~~~
-
- -
testing tildes in backticks
-
-```
-
diff --git a/tests/extensions/fenced_code_blocks.txt b/tests/extensions/fenced_code_blocks.txt deleted file mode 100644 index be0f997..0000000 --- a/tests/extensions/fenced_code_blocks.txt +++ /dev/null @@ -1,80 +0,0 @@ -~~~ -Fenced -~~~ - -Code block starting and ending with empty lines: -~~~ - - -Fenced - - -~~~ - -Indented code block containing fenced code block sample: - - ~~~ - Fenced - ~~~ - -Fenced code block with indented code block sample: - -~~~ -Some text - - Indented code block sample code -~~~ - -Fenced code block with long markers: - -~~~~~~~~~~~~~~~~~~ -Fenced -~~~~~~~~~~~~~~~~~~ - -Fenced code block with fenced code block markers of different length in it: - -~~~~ -In code block -~~~ -Still in code block -~~~~~ -Still in code block -~~~~ - -Fenced code block with Markdown header and horizontal rule: - -~~~ -#test ---- -~~~ - -Fenced code block with link definitions, footnote definition and -abbreviation definitions: - -~~~ -[example]: http://example.com/ - -[^1]: Footnote def - -*[HTML]: HyperText Markup Language -~~~ - -``` -[example]: http://backticks.com/ - -[^1]: Footnote def - -*[HTML]: HyperText Markup Language -``` - -````` -testing tildes in backticks - -~~~ -````` - -~~~ -testing backticks in tildes - -``` -~~~ -- cgit v1.2.3 From 4c7c189ae3d32f0cc947c78c1b116539b2ca0bf6 Mon Sep 17 00:00:00 2001 From: Daniel Gottlieb Date: Tue, 27 Dec 2011 16:47:40 -0500 Subject: also undo changes to the test.cfg --- tests/extensions/test.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg index c271b02..c25bdfb 100644 --- a/tests/extensions/test.cfg +++ b/tests/extensions/test.cfg @@ -20,7 +20,3 @@ extensions=toc [wikilinks] extensions=wikilinks - -[fenced_code_blocks] -extensions=fenced_code -normalize=1 -- cgit v1.2.3