mercurial/minirst.py
changeset 31317 0bd32d7c9002
parent 31132 bbdd712e9adb
child 31318 1c3352d7eaf2
equal deleted inserted replaced
31316:70bc35df3e54 31317:0bd32d7c9002
    62     utext = text.decode(encoding.encoding)
    62     utext = text.decode(encoding.encoding)
    63     for f, t in substs:
    63     for f, t in substs:
    64         utext = utext.replace(f.decode("ascii"), t.decode("ascii"))
    64         utext = utext.replace(f.decode("ascii"), t.decode("ascii"))
    65     return utext.encode(encoding.encoding)
    65     return utext.encode(encoding.encoding)
    66 
    66 
    67 _blockre = re.compile(r"\n(?:\s*\n)+")
    67 _blockre = re.compile(br"\n(?:\s*\n)+")
    68 
    68 
    69 def findblocks(text):
    69 def findblocks(text):
    70     """Find continuous blocks of lines in text.
    70     """Find continuous blocks of lines in text.
    71 
    71 
    72     Returns a list of dictionaries representing the blocks. Each block
    72     Returns a list of dictionaries representing the blocks. Each block
   136                 blocks[i + 1]['indent'] -= adjustment
   136                 blocks[i + 1]['indent'] -= adjustment
   137                 i += 1
   137                 i += 1
   138         i += 1
   138         i += 1
   139     return blocks
   139     return blocks
   140 
   140 
   141 _bulletre = re.compile(r'(\*|-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)|\|) ')
   141 _bulletre = re.compile(br'(\*|-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)|\|) ')
   142 _optionre = re.compile(r'^(-([a-zA-Z0-9]), )?(--[a-z0-9-]+)'
   142 _optionre = re.compile(br'^(-([a-zA-Z0-9]), )?(--[a-z0-9-]+)'
   143                        r'((.*)  +)(.*)$')
   143                        br'((.*)  +)(.*)$')
   144 _fieldre = re.compile(r':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
   144 _fieldre = re.compile(br':(?![: ])([^:]*)(?<! ):[ ]+(.*)')
   145 _definitionre = re.compile(r'[^ ]')
   145 _definitionre = re.compile(br'[^ ]')
   146 _tablere = re.compile(r'(=+\s+)*=+')
   146 _tablere = re.compile(br'(=+\s+)*=+')
   147 
   147 
   148 def splitparagraphs(blocks):
   148 def splitparagraphs(blocks):
   149     """Split paragraphs into lists."""
   149     """Split paragraphs into lists."""
   150     # Tuples with (list type, item regexp, single line items?). Order
   150     # Tuples with (list type, item regexp, single line items?). Order
   151     # matters: definition lists has the least specific regexp and must
   151     # matters: definition lists has the least specific regexp and must
   284                     blocks[j]['indent'] -= adjustment
   284                     blocks[j]['indent'] -= adjustment
   285                     j += 1
   285                     j += 1
   286         i += 1
   286         i += 1
   287     return blocks, pruned
   287     return blocks, pruned
   288 
   288 
   289 _sectionre = re.compile(r"""^([-=`:.'"~^_*+#])\1+$""")
   289 _sectionre = re.compile(br"""^([-=`:.'"~^_*+#])\1+$""")
   290 
   290 
   291 def findtables(blocks):
   291 def findtables(blocks):
   292     '''Find simple tables
   292     '''Find simple tables
   293 
   293 
   294        Only simple one-line table elements are supported
   294        Only simple one-line table elements are supported
   430     Makes the type of the block an admonition block if
   430     Makes the type of the block an admonition block if
   431     the first line is an admonition directive
   431     the first line is an admonition directive
   432     """
   432     """
   433     admonitions = admonitions or _admonitions
   433     admonitions = admonitions or _admonitions
   434 
   434 
   435     admonitionre = re.compile(r'\.\. (%s)::' % '|'.join(sorted(admonitions)),
   435     admonitionre = re.compile(br'\.\. (%s)::' % '|'.join(sorted(admonitions)),
   436                               flags=re.IGNORECASE)
   436                               flags=re.IGNORECASE)
   437 
   437 
   438     i = 0
   438     i = 0
   439     while i < len(blocks):
   439     while i < len(blocks):
   440         m = admonitionre.match(blocks[i]['lines'][0])
   440         m = admonitionre.match(blocks[i]['lines'][0])