分页: 1 / 1
html2wiki:让wiki使用语法高亮显示。
发表于 : 2007-03-29 14:50
由 eexpress
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的编辑里面。如下图
发表于 : 2007-03-29 21:30
由 roylez
很不错的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')
发表于 : 2007-04-04 9:01
由 eexpress
tab?我更新到了blog等地方。和googlepages的主页。用>
没事作py。还是shell方便。倒是以前不知道:TOhtml。:D
发表于 : 2007-04-04 9:11
由 eexpress
代码: 全选
$● 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
发表于 : 2007-04-10 10:14
由 roylez
我们好像都把问题搞复杂了。
今天看到有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
发表于 : 2007-04-16 15:47
由 eexpress
<<forEachTiddler where 'tiddler.tags.contains("Ubuntu")' sortBy 'tiddler.created' descending>>
我现在需要修改这个。。。。需要2列的输出。一列的太长篇幅了。不好看。估计要一个计数器,记录奇数/偶数,然后write("tiddler.topic....")。不知道怎么写了。
这个HTMLFormattingPlugin的,我没测试,不想加太多东西进去哦。而且不如你的vim那行方便啊。呵呵
Re: html2wiki:让wiki使用语法高亮显示。
发表于 : 2013-10-06 23:10
由 eagle5678