如何在复制粘贴时阻止 Wordpress.com 删除空格?

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

我一直在尝试在 Wordpress.com 上发布我的 post。

我想在 post 中包含一个 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

我正在研究OS X。当我将上面的内容复制到TextEdit应用程序中时,我可以清楚地看到某些值之间有多个space,从而使这个table 看起来像列调整一样,与上面的代码片段完全一样。 (比如第二行6998之间有7个space)

当我将(command+ccommand+v)简单复制粘贴到Wordpress.com编辑post部分时, 它不断将多个 space 减少为 1 space (不需要),这取决于我是粘贴到段落还是代码区域。这使得输出看起来未经调整,例如:

 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

问: 如何防止 Wordpress.com 删除这些 space?

一个选项是用   替换 R table 输出中出现的每个 space,这是代表 non-breaking 的 HTML 符号space,然后在Wordpress HTML模式下粘贴此内容。

Wordpress 不应更改   符号,使您的输出看起来与从 R 导出时一样。

如果您不想更换白色的麻烦space,您也可以添加一些 CSS 来达到同样的效果。为设置 CSS 属性 white-space:

<div> 标签创建一个新的 class
<html>
<head>
<style>
div.rdata {
    white-space: pre;
} 
</style>
</head>

然后在 <div> 中使用这个 class,它将包含来自 R:

的原始 table 输出
<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>

请记住,无论使用哪种方法,如果您希望 table 格式显示正确,您可能还必须使用像 Courier 这样的单色spaced 字体。

可以使用shortcodes WP.com offers, in this case [code] or [sourcecode]

请务必将代码粘贴到 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]

结果: