From b806c1cf93524adeb39cf425d5a2109a1f3d37e5 Mon Sep 17 00:00:00 2001
From: Roman Tolchenov <roman.tolchenov@stfc.ac.uk>
Date: Mon, 9 Jun 2014 10:58:08 +0100
Subject: [PATCH] Re #9579. Added Usage section to SaveCSV.

Added a correction to the mantid docs sphinx extension to deal with nonprintable characters in algorithm properties.
---
 .../docs/source/algorithms/SaveCSV-v1.rst     | 40 ++++++++++++++-----
 .../mantiddoc/directives/properties.py        |  5 +++
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/Code/Mantid/docs/source/algorithms/SaveCSV-v1.rst b/Code/Mantid/docs/source/algorithms/SaveCSV-v1.rst
index e9285359a36..75fc7a219c2 100644
--- a/Code/Mantid/docs/source/algorithms/SaveCSV-v1.rst
+++ b/Code/Mantid/docs/source/algorithms/SaveCSV-v1.rst
@@ -11,20 +11,20 @@ Description
 
 The format of the saved ascii CSV file for a 1D worksspace consists of
 three columns where the numbers of each row are seperated by the
-Seperator and each line by the LineSeperator.
+Separator and each line by the LineSeparator.
 
-The format of the saved CSV file for a 2D workspace is as follows:
+The format of the saved CSV file for a 2D workspace is as follows::
 
-| ``   A      0, 200, 400, 600, ..., 50000 ``
-| ``    0     10,   4, 234,  35, ...,    32 ``
-| ``    1      4, 234,   4,   9, ...,    12 ``
-| ``    A      0, 100, 200, 300, ..., 25000 ``
-| ``    2     34,   0,   0,   0, ...,    23``
+    A      0, 200, 400, 600, ..., 50000
+    0     10,   4, 234,  35, ...,    32
+    1      4, 234,   4,   9, ...,    12
+    A      0, 100, 200, 300, ..., 25000
+    2     34,   0,   0,   0, ...,    23
 
-| ``   ERRORS``
-| ``    0    0.1, 3.4, 2.4, 3.5, ...,     2 ``
-| ``    1    3.1, 3.3, 2.5, 3.5, ...,     2 ``
-| ``    2    1.1, 3.3, 2.4,   5, ...,   2.4``
+   ERRORS
+    0    0.1, 3.4, 2.4, 3.5, ...,     2
+    1    3.1, 3.3, 2.5, 3.5, ...,     2
+    2    1.1, 3.3, 2.4,   5, ...,   2.4
 
 where for the matrix above the ERRORS line the first column shows the
 content of the numbers on the of the same line; i.e. 'A' is followed by
@@ -37,4 +37,22 @@ the same x-axis but the third histogram has a different x-axis.
 The matrix following the ERRORS line lists the errors as recorded for
 each histogram.
 
+Usage
+-----
+
+.. testcode::
+
+  import os
+  # Create a file path in the user home directory
+  filePath = os.path.expanduser('~/SavedCSVFile.csv')
+
+  # Create a workspace
+  ws=CreateSampleWorkspace()
+  # Save it in Nexus format
+  SaveCSV(ws,filePath)
+
+.. testcleanup::
+
+  os.remove(filePath)
+
 .. categories::
diff --git a/Code/Mantid/docs/sphinxext/mantiddoc/directives/properties.py b/Code/Mantid/docs/sphinxext/mantiddoc/directives/properties.py
index 469da90563c..c8883ffcbcc 100644
--- a/Code/Mantid/docs/sphinxext/mantiddoc/directives/properties.py
+++ b/Code/Mantid/docs/sphinxext/mantiddoc/directives/properties.py
@@ -140,6 +140,11 @@ class PropertiesDirective(BaseDirective):
                 # Fall-back default for anything
                 defaultstr = str(default)
 
+        # replace nonprintable characters with their printable
+        # representations, such as \n, \t, ...
+        defaultstr = repr(defaultstr)[1:-1]
+        defaultstr = defaultstr.replace('\\','\\\\')
+
         # Replace the ugly default values with "Optional"
         if (defaultstr == "8.9884656743115785e+307") or \
            (defaultstr == "1.7976931348623157e+308") or \
-- 
GitLab