Patchwork [1,of,8] minirst: do not interpret a directive as a literal block

login
register
mail settings
Submitter Simon Heimberg
Date Nov. 2, 2013, 11:36 a.m.
Message ID <b1cb8e807eb0a5b5a53e.1383392161@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/2839/
State Superseded, archived
Headers show

Comments

Simon Heimberg - Nov. 2, 2013, 11:36 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1383387952 -3600
#      Sat Nov 02 11:25:52 2013 +0100
# Branch stable
# Node ID b1cb8e807eb0a5b5a53ed4c4c36bf3d91eaeaa6e
# Parent  e0a554964fd56741cf3ea5e688932a990b9529a0
minirst: do not interpret a directive as a literal block

When a directive was on its own line, it was interpreted as a literal block.

Example of problematic input:

.. note::

    a note text

Patch

diff -r e0a554964fd5 -r b1cb8e807eb0 mercurial/minirst.py
--- a/mercurial/minirst.py	Sat Nov 02 11:25:33 2013 +0100
+++ b/mercurial/minirst.py	Sat Nov 02 11:25:52 2013 +0100
@@ -106,6 +106,12 @@ 
                 # Partially minimized form: remove space and both
                 # colons.
                 blocks[i]['lines'][-1] = blocks[i]['lines'][-1][:-3]
+            elif len(blocks[i]['lines']) == 1 and \
+                 blocks[i]['lines'][0].lstrip(' ').startswith('.. ') and \
+                 blocks[i]['lines'][0].find(' ', 3) == -1:
+                # directive on its onw line, not a literal block
+                i += 1
+                continue
             else:
                 # Fully minimized form: remove just one colon.
                 blocks[i]['lines'][-1] = blocks[i]['lines'][-1][:-1]