docs/test2rst.py
changeset 2959 ef361938dfa1
parent 2958 1cb715257130
child 2960 1a4f26eec0af
--- a/docs/test2rst.py	Thu Sep 21 10:45:06 2017 +0200
+++ b/docs/test2rst.py	Thu Sep 21 10:45:27 2017 +0200
@@ -17,25 +17,38 @@
     newlines = []
 
     code_block_mode = False
+    sphinx_directive_mode = False
 
     for line in orig.splitlines():
 
         # Emtpy lines doesn't change output
         if not line:
             newlines.append(line)
+            code_block_mode = False
+            sphinx_directive_mode = False
+            continue
 
         # Ignore line
         if line.endswith('#rest-ignore'):
             continue
 
+        # Sphinx directives mode
+        if line.startswith('  .. '):
+
+            # Insert a empty line to makes sphinx happy
+            newlines.append("")
+
+            # And unindent the directive
+            line = line[2:]
+            sphinx_directive_mode = True
+
+        # Code mode
         codeline = line.startswith('  ')
-        if codeline:
+        if codeline and not sphinx_directive_mode:
             if code_block_mode is False:
                 newlines.extend(['::', ''])
 
             code_block_mode = True
-        else:
-            code_block_mode = False
 
         newlines.append(line)