Attachment 'nice_headings-1.7.diff'

Download

   1 # HG changeset patch
   2 # User anarcat@titine.anarcat.ath.cx
   3 # Date 1190262113 14400
   4 # Node ID 3fcaf6561a8915f4eb83f5737fe258c6888509a9
   5 # Parent  93be75db205186c2932e6512b9a9c803aba83da1
   6 make nicer headings for latin1 charsets
   7 
   8 we use a trivial heuristic to guess if our nicer heading is really nicer. the converted string is accepted if:
   9 
  10  * it's longer than 1 characters
  11  * it's longer than half the length of the original string
  12 
  13 diff -r 93be75db2051 -r 3fcaf6561a89 MoinMoin/wikiutil.py
  14 --- a/MoinMoin/wikiutil.py	Wed Sep 19 21:39:48 2007 +0200
  15 +++ b/MoinMoin/wikiutil.py	Thu Sep 20 00:21:53 2007 -0400
  16 @@ -2154,8 +2154,16 @@ def anchor_name_from_text(text):
  17      Generate an anchor name from the given text
  18      This function generates valid HTML IDs.
  19      '''
  20 -    quoted = urllib.quote_plus(text.encode('utf-7'))
  21 -    res = quoted.replace('%', '.').replace('+', '').replace('_', '')
  22 +    import unicodedata
  23 +    if not isinstance(text, unicode):
  24 +        text = unicode(text, 'utf8')
  25 +    res = re.sub('[^-A-Za-z0-9_:.]+', '-', unicodedata.normalize('NFKD', text).encode('ascii', 'ignore'))
  26 +    # Heuristic to guess if we made a good job at interpreting the string, if:
  27 +    # the resulted string is too small OR
  28 +    # the resulting string is more that 50% smaller 
  29 +    # then we consider that we failed and revert to a systematic utf7 encoding
  30 +    if len(res) <= 1 or len(res) <= (len(text) / 2):
  31 +        res = urllib.quote_plus(text.encode('utf-7')).replace('%', '.').replace('+', '').replace('_', '')
  32      if not res[:1].isalpha():
  33          return 'A%s' % res
  34      return res

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-05-11 00:38:08, 6.3 KB) [[attachment:nice_headings-1.6.diff]]
  • [get | view] (2007-09-20 04:24:08, 1.6 KB) [[attachment:nice_headings-1.7.diff]]
  • [get | view] (2007-05-10 22:53:28, 5.6 KB) [[attachment:nice_headings.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.