html2wiki:让wiki使用语法高亮显示。

上网、浏览、聊天、下载等
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

html2wiki:让wiki使用语法高亮显示。

#1

帖子 eexpress » 2007-03-29 14:50

eexpress, 29 三 2007 (创建于 29 三 2007)

* 标签:
* vim
* html
* wiki
* sed

保留颜色语法高亮是最重要的。要不vim的html输出就没意义了。

代码: 全选

:source $VIMRUNTIME/syntax/2html.vim
:write __xxx__.html
先建立一个html2wiki.sed

代码: 全选

s/<a href="/[[/g
s/">http/|http/g
s/<\/a>/]]/g

s/<font /@@/g
s/color="/color(/g
s/">/):/g
s/<\/font>/@@/g


/<pre>/ d
/<body>/ d
/<html>/ d
/<head>/ d
/<title>/ d
/<meta/ d
/<body/ d
/<\/pre>/ d
/<\/body>/ d
/<\/html>/ d
/<\/head>/ d

s/\/\//\/ \//g
然后,这样运行

代码: 全选

$●  sed -f html2wiki.sed fetch_web_pic.bash.html >fetch_web_pic.bash.html.wiki
得到的wiki文件,可以直接粘贴到tiddlywiki的编辑里面。如下图
附件
html2wiki.png
● 鸣学
头像
roylez
帖子: 1928
注册时间: 2005-10-04 10:59
来自: 上海

#2

帖子 roylez » 2007-03-29 21:30

很不错的idea。

我写了个python脚本,直接以要转成tiddlywiki格式的源文件为命令行参数,一次性把你上面说的工作都做完。调用vim的时候让它使用浅色背景的morning配色方案,颜色稍微好看点。可惜的是这个脚本生成的tiddlywiki代码无法保留源文件里面的indent,还有就是像python里面的三重引号跟tiddlywiki的markup有冲突,不知道怎么解决。

代码: 全选

#!/usr/bin/env python
import os, sys

def source2html(filename):
    '''Use vim to dump syntax and indent to a html file'''
    cmd = 'vim -c ":syntax on|:colorscheme morning|:TOhtml" -c ":wq!|:q!" %s' %(filename)
    os.system(cmd)

def html2wiki(filename):
    '''Use sed command to convert html syntax to tiddlywiki syntax'''
    sedcmd = '''s/<a href="/[[/g;
    s/">http/|http/g;
    s/<\/a>/]]/g;
    s/<font /@@/g;
    s/color="/color(/g;
    s/<span[^>]*>//g;
    s/<\/span>//g;
    s/">/):/g;
    s/<\/font>/@@/g;
    
    /<pre>/ d;
    /<body>/ d;
    /<html>/ d;
    /<head>/ d;
    /<title>/ d;
    /<meta/ d;
    /<body/ d;
    /<\/pre>/ d;
    /<\/body>/ d;
    /<\/html>/ d;
    /<\/head>/ d;

    s/\/\//\/ \//g'''
    cmd = "sed -e '%s' %s > %s" %(sedcmd, filename, filename+'.wiki')
    os.system(cmd)

if __name__=='__main__':
    for file in sys.argv[1:]:
        #Step 1, source to html
        source2html(file)
        #Step 2, html to tiddlywiki
        html2wiki(file+'.html')
        #Step 3, remove useless html files
        os.remove(file+'.html')
弄个dropbox空间来备份文件或者做私人代码服务器
配置:[url]git://github.com/roylez/dotfiles.git[/url]
主页:http://roylez.heroku.com
各种稀奇玩意儿:http://dooloo.info
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#3

帖子 eexpress » 2007-04-04 9:01

tab?我更新到了blog等地方。和googlepages的主页。用>
● 鸣学
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

没事作py。还是shell方便。倒是以前不知道:TOhtml。:D

#4

帖子 eexpress » 2007-04-04 9:11

代码: 全选

$●  cat '/home/exp/应用/脚本/html2wiki.bash' 
#!/bin/bash

vim -c ":syntax on|:colorscheme morning|:TOhtml" -c ":w|:qa" $1

file $1.html|grep HTML
[ $? != 0 ] && exit;
sed -f ~/应用/脚本/html2wiki.sed $1.html>$1.wiki
● 鸣学
头像
roylez
帖子: 1928
注册时间: 2005-10-04 10:59
来自: 上海

#5

帖子 roylez » 2007-04-10 10:14

我们好像都把问题搞复杂了。

今天看到有plugin的介绍里面提到
When HTML formatting syntax is embedded within a tiddler (in between <html> and </html> markers) TiddlyWiki passes this content to the browser for processing as 'native' HTML. However, TiddlyWiki does not also process the HTML source content for any embedded wiki-formatting syntax it may contain. This means that while you can use HTML formatted content, you cannot mix wiki-formatted content within the HTML formatting.
http://www.tiddlytools.com/#HTMLFormattingPlugin

所以,我们需要做的,只不过是生成html文件,然后把源代码拷贝到tiddler里面就行了。我试过了,确实好使……

看我的效果
http://web.hku.hk/~lzuo/tiddly.html#Vim ... 3%E5%87%BA
弄个dropbox空间来备份文件或者做私人代码服务器
配置:[url]git://github.com/roylez/dotfiles.git[/url]
主页:http://roylez.heroku.com
各种稀奇玩意儿:http://dooloo.info
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#6

帖子 eexpress » 2007-04-16 15:47

<<forEachTiddler where 'tiddler.tags.contains("Ubuntu")' sortBy 'tiddler.created' descending>>
我现在需要修改这个。。。。需要2列的输出。一列的太长篇幅了。不好看。估计要一个计数器,记录奇数/偶数,然后write("tiddler.topic....")。不知道怎么写了。

这个HTMLFormattingPlugin的,我没测试,不想加太多东西进去哦。而且不如你的vim那行方便啊。呵呵
● 鸣学
头像
eagle5678
帖子: 1865
注册时间: 2006-07-08 14:07

Re: html2wiki:让wiki使用语法高亮显示。

#7

帖子 eagle5678 » 2013-10-06 23:10

:em04
回复