I never figured out why Sphinx wasn't recognizing the newline characters 
"\n", but I solved my problem by reworking my python output (in my conf.py) 
so that it was a list of lists, and after I use the tabulate function, I 
split the output on "\n" as such: 
headers = ['Column Name', 'Data Type', 'Length', 'Precision', 'Scale', 
'Description']
tabulate_columns = tabulate(this_table_columns, tablefmt='rst', headers = 
headers)
tabulate_split = [x.split(',')for x in tabulate_columns.split('\n')]
table_dict_tabulate["table_columns"] = tabulate_split

Then I read the output in my tables.rst file as such:
{% for item in table_dict_tabulate  %}

**Table Name:** {% filter upper %} **{{ item.table_nam }}** {% endfilter %}
**Description: {{ item.table_comment }}**

{% for table in item.table_columns %}{%  for column in table %}{{ column 
}}{% endfor %}
{% endfor %}
{% endfor %}

And it looked great.



On Tuesday, April 10, 2018 at 10:20:14 PM UTC+12, Jan wrote:
>
> I'm generating some rst tables in python using the python-tabulate module:
>
> headers = ["Column Name", "Data Type", "Length", "Precision", "Scale", 
> "Description"]
> tabulate_col = tabulate(this_table_columns, tablefmt='rst', headers = 
> headers)
>
> The "this_table_columns" variable is a python list containing lists of 
> column data.
> I then add this rst table as an object to an existing python dictionary as 
> the table_columns value, and in python the output (if printed) looks like 
> this:
>
> [
> {'table_nam': 'Table1',
> 'table_comment': 'Table 1 comments.', 
> 'table_columns': u'
> ==================  ===========  ========  ===========  =======  
> ===================================\n
> Column Name         Data Type    Length    Precision    Scale    
> Description\n
> ==================  ===========  ========  ===========  =======  
> ===================================\n
> Column 1            integer                32           0         \n
> Column 2            varchar      40                              The stage 
> of a buildings lifecycle.\n
> ==================  ===========  ========  ===========  =======  
> ==================================='
> }, 
> {'table_nam': 'Table2', etc.....
>
>
> As you can see, tabulate puts the whole contents of the rst output as 
> unicode with the "u".
>
> However, when I try and load this data into a sphinx rst template in 
> ReadTheDocs as such:
>
> {% for item in schema_tab  %}
> Table Name: {% filter upper %} {{ item.table_nam }} {% endfilter %}
> Description: {{ item.table_comment }}
>
> {{ item.table_columns }}
> {% endfor %}
>
> Sphinx seems to ignore the trailing newline character "\n" and doesn't 
> format the table correctly:
>
> Table Name: Table1
> Description: Table 1 comments.
>
> Column Name Data Type Length Precision Scale Description 
> ================== =========== ======== =========== ======= 
> =================================== Column 1 integer 32 0 _1 Column 2 
> varchar 40 The stage of a buildings lifecycle. ================== 
> =========== ======== =========== ======= ===================================
>
> Table Name: Table2
>
> Description: Table 2 comments.
>
> Column Name Data Type Length Precision Scale Description ============= 
> =========== ======== =========== ======= 
> ======================================================= Column 1 32 0  
> Column 2 varchar 40 The value for column 2. ============= =========== 
> ======== =========== ======= 
> =======================================================
> etc.....
>
> Why does sphinx ignore the newline character? This seems to prevent me 
> from using the nice tabulate module ability to generate ReST tables easily.
> Any ideas on how to prevent ReadTheDocs/Sphinx from ignoring trailing 
> newlines? I don't see any configuration options in ReadTheDocs settings 
> related to this.
>
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sphinx-users+unsubscr...@googlegroups.com.
To post to this group, send email to sphinx-users@googlegroups.com.
Visit this group at https://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to