bgneal@356: """ bgneal@356: A python-markdown extension to treat newlines as hard breaks; like bgneal@356: StackOverflow and GitHub flavored Markdown do. bgneal@356: bgneal@356: """ bgneal@356: import markdown bgneal@356: bgneal@356: bgneal@356: BR_RE = r'\n' bgneal@356: bgneal@356: class Nl2BrExtension(markdown.Extension): bgneal@356: bgneal@356: def extendMarkdown(self, md, md_globals): bgneal@356: br_tag = markdown.inlinepatterns.SubstituteTagPattern(BR_RE, 'br') bgneal@356: md.inlinePatterns.add('nl', br_tag, '_end') bgneal@356: bgneal@356: bgneal@356: def makeExtension(configs=None): bgneal@356: return Nl2BrExtension(configs)