@@ -308,17 +308,29 @@ def render_paragraph(paragraph, meta_variables):
308308 return "**%s**" % paragraph
309309 # Reformat shell transcripts into code blocks.
310310 if re .match (r'^\s*\$\s+\S' , paragraph ):
311- lines = [' %s' % line for line in paragraph .splitlines ()]
311+ # Split the paragraph into lines.
312+ lines = paragraph .splitlines ()
313+ # Check if the paragraph is already indented.
314+ if not paragraph [0 ].isspace ():
315+ # If the paragraph isn't already indented we'll indent it now.
316+ lines = [' %s' % line for line in lines ]
312317 lines .insert (0 , '.. code-block:: sh' )
313318 lines .insert (1 , '' )
314319 return "\n " .join (lines )
315- # Change `quoting' so it doesn't trip up DocUtils.
316- paragraph = re .sub ("`(.+?)'" , r'"\1"' , paragraph )
317- # Escape asterisks.
318- paragraph = paragraph .replace ('*' , r'\*' )
319- # Reformat inline tokens.
320- return replace_special_tokens (paragraph , meta_variables ,
321- lambda token : '``%s``' % token )
320+ # The following reformatting applies only to paragraphs which are not
321+ # indented. Yes this is a hack - for now we assume that indented paragraphs
322+ # are code blocks, even though this assumption can be wrong.
323+ if not paragraph [0 ].isspace ():
324+ # Change UNIX style `quoting' so it doesn't trip up DocUtils.
325+ paragraph = re .sub ("`(.+?)'" , r'"\1"' , paragraph )
326+ # Escape asterisks.
327+ paragraph = paragraph .replace ('*' , r'\*' )
328+ # Reformat inline tokens.
329+ paragraph = replace_special_tokens (
330+ paragraph , meta_variables ,
331+ lambda token : '``%s``' % token ,
332+ )
333+ return paragraph
322334
323335
324336def replace_special_tokens (text , meta_variables , replace_fn ):
0 commit comments