How to stop WordPress.com from removing spaces when copy-paste?

I am stucked in trying to publish my post on WordPress.com.

I want to include an R console output in the post. The output is of the following form:

Read More
age weight height      bmi waist_circ hip_circ waist_hip_ratio glucose cholesterol_total triglycerides hdl ldl insulin      homa ldl_by_hdl fat_pct
1  30     65    163 24.46460         80      100       0.8000000      70               198            66  58 127     4.9 0.8469136  2.1896552    28.6
2  29     54    165 19.83471         69       98       0.7040816      94               223            69  60 149     4.7 1.0908642  2.4833333    27.7
3  29     66    163 24.84098         83      100       0.8300000      79               130            61  60  58     4.1 0.7997531  0.9666667    34.7
4  29     55    163 20.70082         68      104       0.6538462      71               155            36  83  65     7.8 1.3674074  0.7831325    28.1
5  29     63    167 22.58955         70       98       0.7142857      79               183            63  52 118     5.4 1.0533333  2.2692308    29.2
6  27     63    172 21.29529         75      103       0.7281553      74               172            85  64  91     4.2 0.7674074  1.4218750    24.3

I am working on OS X. When I copy the content above into a TextEdit application, I can see clearly that there are multiple spaces between some values so as to make this table look as column-adjusted, exactly as in the snippet above. (For example, there are 7 spaces between 69 and 98) in the second row.)

When I make simple copy-paste (command+c, command+v) into WordPress.com Edit post section, it keeps reducing the multiple spaces into 1 space (unwanted), dependless whether I am pasting into paragraph or code area. This makes the output look NON-adjuested, e.g.:

 age weight height bmi waist_circ hip_circ waist_hip_ratio glucose cholesterol_total triglycerides hdl ldl insulin homa ldl_by_hdl fat_pct
1 30 65 163 24.46460 80 100 0.8000000 70 198 66 58 127 4.9 0.8469136 2.1896552 28.6
2 29 54 165 19.83471 69 98 0.7040816 94 223 69 60 149 4.7 1.0908642 2.4833333 27.7
3 29 66 163 24.84098 83 100 0.8300000 79 130 61 60 58 4.1 0.7997531 0.9666667 34.7
4 29 55 163 20.70082 68 104 0.6538462 71 155 36 83 65 7.8 1.3674074 0.7831325 28.1
5 29 63 167 22.58955 70 98 0.7142857 79 183 63 52 118 5.4 1.0533333 2.2692308 29.2
6 27 63 172 21.29529 75 103 0.7281553 74 172 85 64 91 4.2 0.7674074 1.4218750 24.3

Q: How can I prevent WordPress.com from removing these spaces?

Related posts

2 comments

  1. You can use the shortcodes WP.com offers, in this case [code] or [sourcecode].

    It’s important to paste the code in HTML editing mode:

    [code language="r"]
    age weight height      bmi waist_circ hip_circ waist_hip_ratio glucose cholesterol_total triglycerides hdl ldl insulin      homa ldl_by_hdl fat_pct
    1  30     65    163 24.46460         80      100       0.8000000      70               198            66  58 127     4.9 0.8469136  2.1896552    28.6
    2  29     54    165 19.83471         69       98       0.7040816      94               223            69  60 149     4.7 1.0908642  2.4833333    27.7
    3  29     66    163 24.84098         83      100       0.8300000      79               130            61  60  58     4.1 0.7997531  0.9666667    34.7
    4  29     55    163 20.70082         68      104       0.6538462      71               155            36  83  65     7.8 1.3674074  0.7831325    28.1
    5  29     63    167 22.58955         70       98       0.7142857      79               183            63  52 118     5.4 1.0533333  2.2692308    29.2
    6  27     63    172 21.29529         75      103       0.7281553      74               172            85  64  91     4.2 0.7674074  1.4218750    24.3
    [/code]
    

    Results in:


  2. One option would be to replace every space occurring in your R table output with  , which is the HTML symbol representing a non-breaking space, and then paste this content in WordPress HTML mode.

    WordPress should not alter the   symbol, leaving your output looking the way it did upon export from R.

    If you don’t want the hassle of replacing the whitespace, you could also adding some CSS to the same effect. Create a new class for the <div> tag which sets the CSS property white-space:

    <html>
    <head>
    <style>
    div.rdata {
        white-space: pre;
    } 
    </style>
    </head>
    

    Then use this class in a <div> which will contain your raw table output from R:

    <div class="rdata">
        age weight height      bmi waist_circ hip_circ waist_hip_ratio glucose cholesterol_total triglycerides hdl ldl insulin      homa ldl_by_hdl fat_pct
        1  30     65    163 24.46460         80      100       0.8000000      70               198            66  58 127     4.9 0.8469136  2.1896552    28.6
        ...
    
    </div>
    

    Keep in mind that with either method, you will also likely have to use a monospaced font like Courier if you want the table format to appear correct.

Comments are closed.