From: Bernardo Innocenti Date: Tue, 12 Feb 2008 07:54:07 +0000 (+1000) Subject: Use abridged headings for anchors X-Git-Tag: v3.0~31 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=4418a51a22439df095133aef170814fabc597c55;p=geekigeeki.git Use abridged headings for anchors --- diff --git a/geekigeeki.py b/geekigeeki.py index a6158a3..0a441bf 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -339,7 +339,7 @@ class PageFormatter: self.in_pre = self.in_table = False self.in_header = True self.list_indents = [] - self.tr_cnt = self.h_cnt = 0 + self.tr_cnt = 0 self.styles = { #wiki html enabled? "//": ["em", False], @@ -364,9 +364,8 @@ class PageFormatter: self.h_level = 0 else: self.h_level = len(word) - 1 - self.h_cnt += 1 - #abridged = re.sub('[^a-z_]', '', word.lower().replace(' ', '_')) - result = '¶ ' % (self.h_level, self.h_cnt, self.h_cnt) + abridged = re.sub('[^A-Za-z0-9_]', '', self.line).lower() + result = '¶ ' % (self.h_level, abridged, abridged) return result def _br_repl(self, word): @@ -524,26 +523,26 @@ class PageFormatter: indent_re = re.compile(r"^\s*") tr_re = re.compile(r"^\s*\|\|") eol_re = re.compile(r"\r?\n") - for line in eol_re.split(self.raw.expandtabs()): + for self.line in eol_re.split(self.raw.expandtabs()): # Skip ACLs if self.in_header: - if line.startswith('#'): + if self.line.startswith('#'): continue self.in_header = False if self.in_pre: - print re.sub(pre_re, self.replace, line) + print re.sub(pre_re, self.replace, self.line) else: - if self.in_table and not tr_re.match(line): + if self.in_table and not tr_re.match(self.line): self.in_table = False print '

' - if blank_re.match(line): + if blank_re.match(self.line): print '

' else: - indent = indent_re.match(line) + indent = indent_re.match(self.line) print self._indent_to(len(indent.group(0))) - print re.sub(scan_re, self.replace, line) + print re.sub(scan_re, self.replace, self.line) if self.in_pre: print '' if self.in_table: print '

'