Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

FYI: another extra for managing headers #70

Closed
wants to merge 1 commit into from

1 participant

@mbreese

In a project I'm working on, I wanted to be able to capture twitter-style hash tags, but still have markdown format. However, if the #tag was the first thing on a line, it would match the header regex, which wasn't what I wanted. So, now when the extra 'tag-friendly-headers' is passed, whitespace is now required between the opening # and the rest of the header. Otherwise, the #tag is left as-is.

Example 1:
#tag
standard code:

tag


w/ my extra: #tag

Example 2:

header

standard code:

header


w/ my extra:

header

Interestingly, this change doesn't break any of the tests... nor is it explicitly dealt with in Gruber's syntax sheets (that I know of).

Feel free to accept or reject the pull as you'd like.

Commit text

Requires white-space between "#" and the header in order to qualify as a ""

This lets us include hash-tags (#tagname) as the first item on a line and have it not converted to a

@mbreese mbreese Added extra "tag-friendly-headers"
Requires white-space between "#" and the header in order to qualify as a "<h?>"

This lets us include hash-tags (#tagname) as the first item on a line and have it *not* converted to a <h?>
c306f76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2011
  1. @mbreese

    Added extra "tag-friendly-headers"

    mbreese authored
    Requires white-space between "#" and the header in order to qualify as a "<h?>"
    
    This lets us include hash-tags (#tagname) as the first item on a line and have it *not* converted to a <h?>
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 9 deletions.
  1. +30 −9 lib/markdown2.py
View
39 lib/markdown2.py
@@ -221,6 +221,27 @@ def __init__(self, html4tags=False, tab_width=4, safe_mode=None,
self._escape_table['"'] = _hash_ascii('"')
self._escape_table["'"] = _hash_ascii("'")
+ if 'tag-friendly-headers' in self.extras:
+ self._atx_h_re = re.compile(r'''
+ ^(\#{1,6}) # \1 = string of #'s
+ [ \t]+
+ (.+?) # \2 = Header text
+ [ \t]*
+ (?<!\\) # ensure not an escaped trailing '#'
+ \#* # optional closing #'s (not counted)
+ \n+
+ ''', re.X | re.M)
+ else:
+ self._atx_h_re = re.compile(r'''
+ ^(\#{1,6}) # \1 = string of #'s
+ [ \t]*
+ (.+?) # \2 = Header text
+ [ \t]*
+ (?<!\\) # ensure not an escaped trailing '#'
+ \#* # optional closing #'s (not counted)
+ \n+
+ ''', re.X | re.M)
+
def reset(self):
self.urls = {}
self.titles = {}
@@ -1187,15 +1208,15 @@ def _setext_h_sub(self, match):
self._toc_add_entry(n, header_id, html)
return "<h%d%s>%s</h%d>\n\n" % (n, header_id_attr, html, n)
- _atx_h_re = re.compile(r'''
- ^(\#{1,6}) # \1 = string of #'s
- [ \t]*
- (.+?) # \2 = Header text
- [ \t]*
- (?<!\\) # ensure not an escaped trailing '#'
- \#* # optional closing #'s (not counted)
- \n+
- ''', re.X | re.M)
+ # _atx_h_re = re.compile(r'''
+ # ^(\#{1,6}) # \1 = string of #'s
+ # [ \t]*
+ # (.+?) # \2 = Header text
+ # [ \t]*
+ # (?<!\\) # ensure not an escaped trailing '#'
+ # \#* # optional closing #'s (not counted)
+ # \n+
+ # ''', re.X | re.M)
def _atx_h_sub(self, match):
n = len(match.group(1))
demote_headers = self.extras.get("demote-headers")
Something went wrong with that request. Please try again.