=================4月13日更新=====================

添加引用的好方法,源码来自漠北这篇日志

1
2
3
<blockquote style="width:600px; padding: 5px; background: rgb(69, 86, 68) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(255, 255, 255);">
老师说:计算机人,讲究的是精确。
</blockquote>

使用方法同下面说的贴程序代码类似,将上面源码中的“老师说。。。”替换成想引用的内容,显示效果还是比较不错的:

老师说:计算机人,讲究的是精确。

=====================================================

在日志里头贴代码应该说是比较大众的需求,可是一直以来百度HI对程序代码的支持一点都不友好。
这几天在做网页的正文提取时对HTML标签有了一点了解,于是仿照着其他代码友好型博客的HTML源码,搞了一个所谓的模板。

1
2
3
4
5
6
7
8
9
<pre style="border: 1px solid rgb(128, 128, 128); padding: 5px; overflow: auto; min-height: 40px; width: 650px; background-color: rgb(192, 192, 192);">
<pre style="margin: 0em; font-size: 12px; width: 100%; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(192, 192, 192);">
#include <stdio.h>
 
int main()
{
    printf("Hello, BaiDu!");
    return 0;
}

把上面模板中的C语言程序替换成想要的程序代码就OK了。第一行<pre>中的rgb(128, 128, 128)是边框的颜色,width指定了边框的宽度;第二行<pre>中的font-size指定了程序代码的字体大小,background-color是代码框的背景色。显示的效果如下:

#include <stdio.h>

int main()
{
    printf("Hello, BaiDu!");
    return 0;
}

接下来的问题是让程序代码高亮显示。我一般是先将代码交到某支持代码高亮的OJ(比如HDOJ),得到高亮后的网页。将其中程序代码部分的HTML源代码复制过来,嵌入到“模板”中即可。

最后就是将程序插入到百度HI日志中。方法也很简单:将嵌入了代码的模板的内容保存到a.txt中,重命名为b.html。然后在浏览器中打开b.html,全选复制,在百度HI写日志的状态下Ctrl+V粘贴。



共有9条评论

  1. 这个不错,收藏啦

  2. 回复ByteChen:

  3. 貌似知道的晚了点儿。。

  4. 回复rt77789:不晚不晚。bye the way,好久没见师兄了。

  5. ybbaigo | #5

    #include<iostream>

    int main()

    {

           printf("very good!!!\n");

           return 0;

    }

  6. 回复tgh728:哈哈,今天看到了~ :)

  7. 不错 赞一个!

  8. 回复相守鼎:偷偷使用了你文章中的内容,希望没有侵权。呵呵

  9. 转过去了,谢谢

Leave a Reply

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).