diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -497,6 +497,93 @@ def formatblock(block, width): initindent=indent, hangindent=subindent) + '\n' +def formathtml(blocks): + """Format RST blocks as HTML""" + + out = [] + headernest = '' + listnest = [] + + def openlist(start, level): + if not listnest or listnest[-1][0] != start: + listnest.append((start, level)) + out.append('<%s>\n' % start) + + blocks = [b for b in blocks if b['type'] != 'margin'] + + for pos, b in enumerate(blocks): + btype = b['type'] + level = b['indent'] + lines = b['lines'] + + if btype == 'admonition': + admonition = _admonitiontitles[b['admonitiontitle']] + text = ' '.join(map(str.strip, lines)) + out.append('
\n%s %s\n
\n' % (admonition, text)) + elif btype == 'paragraph': + out.append('\n%s\n
\n' % '\n'.join(lines)) + elif btype == 'margin': + pass + elif btype == 'literal': + out.append('\n%s\n\n' % '\n'.join(lines)) + elif btype == 'section': + i = b['underline'] + if i not in headernest: + headernest += i + level = headernest.index(i) + 1 + out.append('
+This is some text in the first paragraph. +
++A small indented paragraph. +It is followed by some lines +containing random whitespace. +
++The third and final paragraph. +
+ +---------------------------------------------------------------------- paragraphs formatted to fit within 30 characters: ---------------------------------------------------------------------- @@ -22,6 +35,19 @@ paragraph. The third and final paragraph. ---------------------------------------------------------------------- ++This is some text in the first paragraph. +
++A small indented paragraph. +It is followed by some lines +containing random whitespace. +
++The third and final paragraph. +
+ +---------------------------------------------------------------------- definitions formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -37,6 +63,16 @@ Another Term Definition. ---------------------------------------------------------------------- ++The fully minimized form is the most +convenient form: +
++Hello + literal + world ++
+In the partially minimized form a paragraph +simply ends with space-double-colon. +
++//////////////////////////////////////// +long un-wrapped line in a literal block +\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ++
+This literal block is started with '::', + the so-called expanded form. The paragraph + with '::' disappears in the final output. ++ +---------------------------------------------------------------------- literals formatted to fit within 30 characters: ---------------------------------------------------------------------- @@ -101,6 +172,31 @@ with space-double-colon. with '::' disappears in the final output. ---------------------------------------------------------------------- +
+The fully minimized form is the most +convenient form: +
++Hello + literal + world ++
+In the partially minimized form a paragraph +simply ends with space-double-colon. +
++//////////////////////////////////////// +long un-wrapped line in a literal block +\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ++
+This literal block is started with '::', + the so-called expanded form. The paragraph + with '::' disappears in the final output. ++ +---------------------------------------------------------------------- lists formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -137,6 +233,49 @@ This is the first line. The line continu This is the second line. ---------------------------------------------------------------------- +
+Second paragraph in the first list item. +
++We can have indented lists: +
++- A literal block in the middle + of an indented list. ++
+(The above is not a list item since we are in the literal block.) ++
+Literal block with no indentation (apart from +the two spaces added to all literal blocks). ++
+Line blocks are also a form of list: +
++Second paragraph in the first list item. +
++We can have indented lists: +
++- A literal block in the middle + of an indented list. ++
+(The above is not a list item since we are in the literal block.) ++
+Literal block with no indentation (apart from +the two spaces added to all literal blocks). ++
+Line blocks are also a form of list: +
++There is support for simple option lists, +but only with long options: +
++This is the second. Blank lines may be omitted between +options (as above) or left in (as here). +
++The next paragraph looks like an option list, but lacks the two-space +marker after the option. It is treated as a normal paragraph: +
++--foo bar baz +
+ +---------------------------------------------------------------------- options formatted to fit within 30 characters: ---------------------------------------------------------------------- @@ -283,6 +496,37 @@ normal paragraph: --foo bar baz ---------------------------------------------------------------------- ++There is support for simple option lists, +but only with long options: +
++This is the second. Blank lines may be omitted between +options (as above) or left in (as here). +
++The next paragraph looks like an option list, but lacks the two-space +marker after the option. It is treated as a normal paragraph: +
++--foo bar baz +
+ +---------------------------------------------------------------------- fields formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -298,6 +542,23 @@ much too large This key is big enough to get its own line. ---------------------------------------------------------------------- ++Next list: +
++Next list: +
++Normal output. +
+ +---------------------------------------------------------------------- containers (verbose) formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -334,6 +617,14 @@ Verbose output. ---------------------------------------------------------------------- ['debug', 'debug'] ---------------------------------------------------------------------- ++Normal output. +
++Verbose output. +
+ +---------------------------------------------------------------------- containers (debug) formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -344,6 +635,14 @@ Initial debug output. ---------------------------------------------------------------------- ['verbose'] ---------------------------------------------------------------------- ++Normal output. +
++Initial debug output. +
+ +---------------------------------------------------------------------- containers (verbose debug) formatted to fit within 60 characters: ---------------------------------------------------------------------- @@ -358,12 +657,31 @@ Debug output. ---------------------------------------------------------------------- [] ---------------------------------------------------------------------- ++Normal output. +
++Initial debug output. +
++Verbose output. +
++Debug output. +
+ +---------------------------------------------------------------------- roles formatted to fit within 60 characters: ---------------------------------------------------------------------- Please see "hg add". ---------------------------------------------------------------------- ++Please see "hg add". +
+ +---------------------------------------------------------------------- sections formatted to fit within 20 characters: ---------------------------------------------------------------------- @@ -380,6 +698,12 @@ Markup: "foo" and "hg help" --------------------------- ---------------------------------------------------------------------- ++Note: This is a note +
++Warning! This is a warning Second input line of warning +
++!Danger! This is danger +
+ +---------------------------------------------------------------------- comments formatted to fit within 30 characters: ---------------------------------------------------------------------- @@ -407,6 +746,17 @@ Some text. Empty comment above ---------------------------------------------------------------------- ++Some text. +
++Some indented text. +
++Empty comment above +
+ +---------------------------------------------------------------------- === === ======================================== a b c @@ -425,4 +775,11 @@ table formatted to fit within 30 charact man ---------------------------------------------------------------------- +a | b | c |
---|---|---|
1 | 2 | 3 |
foo | bar | baz this list is very very very long man |