首页
/ WikiCloth 技术文档

WikiCloth 技术文档

2024-12-20 16:11:56作者:吴年前Myrtle

1. 安装指南

安装步骤

  1. 克隆项目仓库:

    git clone git://github.com/nricciar/wikicloth.git
    
  2. 切换到项目目录:

    cd wikicloth/
    
  3. 执行安装命令:

    rake install
    

2. 项目使用说明

基础使用

创建一个 WikiCloth::Parser 对象,并传入相应的数据:

@wiki = WikiCloth::Parser.new({
  :data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
  :params => { "test" => "World" }
})

然后使用 to_html 方法转换数据为 HTML:

@wiki.to_html # => "<p>&#123;&#123;test&#125;&#125;  <i>Hello World!</i></p>"

高级使用

你可以通过继承 WikiCloth::Parser 类并重写相应方法来自定义解析行为:

class WikiParser < WikiCloth::Parser

  url_for do |page|
    "javascript:alert('You clicked on: #{page}');"
  end

  link_attributes_for do |page|
    { :href => url_for(page) }
  end

  template do |template|
    "Hello {{{1}}}" if template == "hello"
  end

  external_link do |url,text|
    "<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
  end
end

@wiki = WikiParser.new({
  :params => { "PAGENAME" => "Testing123" }, 
  :data => "{{hello|world}} From {{ PAGENAME }} -- [www.google.com]"
})

@wiki.to_html =>
"<p>
Hello world From Testing123 -- <a href=\"http://www.google.com\" target=\"_blank\" class=\"exlink\">http://www.google.com</a>
</p>"

3. 项目API使用文档

目前项目没有提供详细的API文档,但可以通过查看源代码和项目wiki了解各个类和方法的使用方式。

4. 项目安装方式

如安装指南所述,项目通过以下步骤进行安装:

  1. 克隆项目仓库。
  2. 切换到项目目录。
  3. 使用 rake install 命令安装。

以上步骤将确保项目正确安装并可用于进一步的开发和使用。

登录后查看全文
热门项目推荐