BBRuby 技术文档
2024-12-23 13:23:19作者:咎竹峻Karen
本文档将详细介绍如何安装、使用及API调用BBRuby项目,帮助用户更好地理解和应用该Ruby实现的BBCode转换功能。
1. 安装指南
BBRuby可以通过Ruby的Gem包管理器进行安装。在终端中运行以下命令:
gem install bb-ruby
2. 项目使用说明
BBRuby是一个将BBCode标记转换为HTML的Ruby实现。以下是基本的使用方法:
首先,需要引入BBRuby库:
require 'bb-ruby'
BBRuby已经直接集成到String类中,可以直接在任何字符串对象上使用:
text = "[b]Here is some bold text[/b] followed by some [u]underlined text[/u]"
output = text.bbcode_to_html
BBRuby会自动转义HTML标签。如果不希望进行转义,可以传递false作为第二个参数:
output = text.bbcode_to_html({}, false)
如果只想允许某些标签,可以通过第三个参数进行设置:
output = text.bbcode_to_html({}, true, :enable, :image, :bold, :quote)
也可以禁用某些标签:
output = text.bbcode_to_html({}, true, :disable, :image, :bold, :quote)
还可以直接使用BBRuby类进行转换:
output = BBRuby.to_html(bbcode_markup)
自定义转换规则可以通过以下方式实现:
my_blockquote = {
'Quote' => [
/\[quote(:.*)?=(.*?)\](.*?)\[\/quote\1?\]/mi,
'<div class="quote"><p><cite>\2</cite></p><blockquote>\3</blockquote></div>',
'Quote with citation',
'[quote=mike]please quote me[/quote]',
:quote
],
}
text.bbcode_to_html(my_blockquote)
如果需要,也可以使用Proc作为替换:
module BBRuby
@@tags = @@tags.merge({
'File' => [
/\[file(:.*)?=(.*?)\](.*?)\[\/file\1?\]/mi,
lambda{ |e| "<div class=\"file\"><p><cite>#{e[3]}</cite></p><blockquote>#{file_read_method(e[2])}</blockquote></div>"},
'File content with citation',
'[file=script.rb]Script Caption[/file]',
:file
],
})
end
使用simple_format方法可以格式化输出:
output = text.bbcode_to_html_with_formatting
output = text.bbcode_to_html_with_formatting!
3. 项目API使用文档
以下是BBRuby处理BBCode标签的列表及其对应的符号,用于启用或禁用:
[b]:bold[i]:italics[u]:underline[s]:strikeout[del]:delete[ins]:insert[code]:code[size]:size[color]:color[ol]:orderedlist[ul]:unorderedlist[li]:listitem[*]:listitem[list]:listitem[list=1]:listitem[list=a]:listitem[dl]:definelist[dt]:defineterm[dd]:definition[quote]:quote[quote=source]:quote[url=link]:link[url]:link[img size=]:image[img align=]:image[img=]:image[img]:image[youtube]:video[gvideo]:video[vimeo]:video[email]:email[align]:align[left]:left[center]:center[right]:right[br]:br
4. 项目安装方式
项目的安装方式已在安装指南中详细说明,即通过Ruby的Gem包管理器进行安装。
登录后查看全文
热门项目推荐
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0220
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0140
uni-appA cross-platform framework using Vue.jsJavaScript09
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
SwanLab⚡️SwanLab - an open-source, modern-design AI training tracking and visualization tool. Supports Cloud / Self-hosted use. Integrated with PyTorch / Transformers / LLaMA Factory / veRL/ Swift / Ultralytics / MMEngine / Keras etc.Python00
tiny-universe《大模型白盒子构建指南》:一个全手搓的Tiny-UniverseJupyter Notebook03
项目优选
收起
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
471
466
deepin linux kernel
C
32
16
暂无描述
Dockerfile
780
5.08 K
Ascend Extension for PyTorch
Python
759
969
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
700
1.4 K
Claude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed.
Get Started
Rust
2.1 K
220
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
880
2.02 K
本仓库是 Flutter SDK 与 Flutter Engine 的 OpenHarmony 适配版本,由 CPF-Flutter 团队维护。开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,3.35.7 及以后的适配版本可基于本仓库源码构建支持 OpenHarmony 的 Flutter Engine。
Dart
1.04 K
272
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。
C
461
5.45 K
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
1.1 K
1.15 K