Last active
July 16, 2017 23:35
-
-
Save bryanchow/2b0fa0cc99c2582e5bb65b9f1088473f to your computer and use it in GitHub Desktop.
Revisions
-
bryanchow revised this gist
Jul 16, 2017 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,8 @@ def ulize(text): like Markdown or Textile but without the other junk. Expects each list item to be prefixed by zero or more spaces, a dash, and a single space. https://gist.github.com/bryanchow/2b0fa0cc99c2582e5bb65b9f1088473f >>> ulize( ... "Here is a list of items:\n" ... "- Item one\n" @@ -31,4 +33,4 @@ def ulize(text): if __name__ == "__main__": import doctest doctest.testmod() -
bryanchow revised this gist
Jul 16, 2017 . No changes.There are no files selected for viewing
-
bryanchow created this gist
Jul 16, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import re def ulize(text): r""" Convert lists embedded in plain text to HTML unordered lists. Yes, kinda like Markdown or Textile but without the other junk. Expects each list item to be prefixed by zero or more spaces, a dash, and a single space. >>> ulize( ... "Here is a list of items:\n" ... "- Item one\n" ... "- Item two\n" ... ) 'Here is a list of items:<ul><li>Item one</li><li>Item two</li></ul>' >>> ulize( ... "Another\n" ... "list:\n" ... " - One\n" ... " - Two\n" ... " Not-an-item\n" ... ) 'Another\nlist:<ul><li>One</li><li>Two</li></ul> Not-an-item\n' """ return re.sub( r"\s*- (.*)\n*", r"<li>\1</li>", re.sub(r"((\s*- [^\n]*(\n|$))+)", r"<ul>\n\1\n</ul>", text) ) if __name__ == "__main__": import doctest doctest.testmod()