Tumblr不呈现HTML

时间:2014-01-05 12:43:12

标签: html tumblr

我有一个HTML代码可以在我的Tumblr博客中发布。它是

<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="background:#ffffff;color:#008000">// server to POST to</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> url = </span><span style="background:#ffffff;color:#a31515">&quot;myserver.com/path/to/my/post&quot;</span><span style="background:#ffffff;color:#000000">;</span></li>
<li><span style="background:#ffffff;color:#008000">// HTTP web request</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);</span></li>
<li><span style="background:#ffffff;color:#000000">httpWebRequest.ContentType = </span><span style="background:#ffffff;color:#a31515">&quot;text/plain; charset=utf-8&quot;</span><span style="background:#ffffff;color:#000000">;</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">httpWebRequest.Method = </span><span style="background:#ffffff;color:#a31515">&quot;POST&quot;</span><span style="background:#ffffff;color:#000000">;</span></li>
<li><span style="background:#ffffff;color:#008000">// Write the request Asynchronously</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#0000ff">using</span><span style="background:#ffffff;color:#000000"> (var stream = await Task.Factory.FromAsync(httpWebRequest.BeginGetRequestStream, httpWebRequest.EndGetRequestStream, </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">))</span></li>
<li><span style="background:#ffffff;color:#000000">{</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#008000">//create some json string</span></li>
<li><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> json = </span><span style="background:#ffffff;color:#a31515">&quot;{ &#92;&quot;my&#92;&quot; : &#92;&quot;json&#92;&quot; }&quot;</span><span style="background:#ffffff;color:#000000">;&gt;</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#008000">// convert json to byte array</span></li>
<li><span style="background:#ffffff;color:#0000ff">byte</span><span style="background:#ffffff;color:#000000">[] jsonAsBytes = Encoding.UTF8.GetBytes(json);</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#008000">// Write the bytes to the stream</span></li>
<li><span style="background:#ffffff;color:#000000">await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);</span></li>
<li style="background: #f3f3f3"><span style="background:#ffffff;color:#000000">}</span></li>
</ol>
</div>
</div>

但是当我将这个HTML代码放在我的博客中时,它呈现为

<div>
<div>Code Snippet</div>
<div><ol start="1">
<li><span>// server to POST to</span></li>
<li><span>string</span><span> url = </span><span>"myserver.com/path/to/my/post"</span><span>;</span></li>
<li><span>// HTTP web request</span></li>
<li><span>var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);</span></li>
<li><span>httpWebRequest.ContentType = </span><span>"text/plain; charset=utf-8"</span><span>;</span></li>
<li><span>httpWebRequest.Method = </span><span>"POST"</span><span>;</span></li>
<li><span>// Write the request Asynchronously</span></li>
<li><span>using</span><span> (var stream = await Task.Factory.FromAsync(httpWebRequest.BeginGetRequestStream, httpWebRequest.EndGetRequestStream, </span><span>null</span><span>))</span></li>
<li><span>{</span></li>
<li><span>//create some json string</span></li>
<li><span>string</span><span> json = </span><span>"{ \"my\" : \"json\" }"</span><span>;&gt;</span></li>
<li><span>// convert json to byte array</span></li>
<li><span>byte</span><span>[] jsonAsBytes = Encoding.UTF8.GetBytes(json);</span></li>
<li><span>// Write the bytes to the stream</span></li>
<li><span>await stream.WriteAsync(jsonAsBytes, 0, jsonAsBytes.Length);</span></li>
<li><span>}</span></li>
</ol></div>
</div>

如何摆脱这个......

1 个答案:

答案 0 :(得分:0)

有一个解决方案,但它非常难看。

您必须删除所有内联样式并将您的html id和类剪切并粘贴到博客文章中(确保在编辑器选项中选择HTML)。

在主html文档的头部,你现在需要设置你添加到html博客帖子的类和id的样式。转到自定义&gt;编辑HTML。

这很痛苦,但如果您打算再次发布类似的样式内容,这种方法就可以了。

我保留了tumblr html的工作副本,因此我可以轻松地离线编辑它,只需将新的html剪切并粘贴到编辑器中,当我更新它时。

希望这会有所帮助。