项目技术文档——Acts as Markup
2024-12-23 05:28:47作者:姚月梅Lane
1. 安装指南
首先,你需要将 acts_as_markup 添加到你的 Gemfile 中:
gem "acts_as_markup"
然后,运行以下命令进行安装:
bundle install
确保你已经安装了以下库,因为它们是项目所必需的:
- RedCloth:用于处理 Textile 文本。
- BlueCloth、RDiscount、Ruby PEG、Maruku 或 Redcarpet:作为 Markdown 处理器。
2. 项目的使用说明
本项目允许你在 ActiveRecord 模型中指定包含 Markdown、Textile 和 RDoc 的列。你可以使用 to_s 方法获取原始标记文本,或使用 to_html 方法获取格式化后的 HTML。
此外,你可以有一个模型,其中包含一个列,它包含一个标记文本的列,另一个列定义了要处理它的语言。如果字段被列为 "markdown"、"textile" 或 "rdoc"(不区分大小写),它将以此处理,对于标记语言的任何其他值,将作为普通字符串传递。
此 AR 扩展可以使用五种不同的 Markdown 处理后端:BlueCloth、RDiscount、Ruby PEG、Redcarpet 或 Maruku。你可以在环境配置文件(environment.rb)中设置一个配置值来指定你想使用的库:
ActsAsMarkup.markdown_library = :bluecloth
默认情况下将使用 RDiscount。
3. 项目API使用文档
以下是一些示例用法:
使用 acts_as_markdown
class Post < ActiveRecord
acts_as_markdown :body
end
@post = Post.find(:first)
@post.body.to_s # => "## Markdown Headline"
@post.body.to_html # => "<h2> Markdown Headline</h2>"
使用 acts_as_textile
class Post < ActiveRecord
acts_as_textile :body
end
@post = Post.find(:first)
@post.body.to_s # => "h2. Textile Headline"
@post.body.to_html # => "<h2>Textile Headline</h2>"
使用 acts_as_rdoc
class Post < ActiveRecord
acts_as_rdoc :body
end
@post = Post.find(:first)
@post.body.to_s # => "== RDoc Headline"
@post.body.to_html # => "<h2>RDoc Headline</h2>"
使用 acts_as_markup
class Post < ActiveRecord
acts_as_markup :language => :markdown, :columns => [:body]
end
@post = Post.find(:first)
@post.body.to_s # => "## Markdown Headline"
@post.body.to_html # => "<h2> Markdown Headline</h2>"
使用带 :variable 语言的 acts_as_markup
class Post < ActiveRecord
acts_as_markup :language => :variable, :columns => [:body]
end
@post = Post.find(:first)
@post.markup_language # => "markdown"
@post.body.to_s # => "## Markdown Headline"
@post.body.to_html # => "<h2> Markdown Headline</h2>"
使用选项
class Post < ActiveRecord
acts_as_markdown :body, :markdown_options => [ :filter_html ]
end
class Post < ActiveRecord
acts_as_textile :body, :textile_options => [ [ :filter_html ] ]
end
4. 项目安装方式
请遵循上述安装指南。简要概括如下:
- 将
acts_as_markup添加到 Gemfile 中。 - 运行
bundle install。 - 根据需要配置 Markdown 库。
确保所有必需的依赖项都已正确安装。
登录后查看全文
热门项目推荐
GLM-5智谱 AI 正式发布 GLM-5,旨在应对复杂系统工程和长时域智能体任务。Jinja00
GLM-5-w4a8GLM-5-w4a8基于混合专家架构,专为复杂系统工程与长周期智能体任务设计。支持单/多节点部署,适配Atlas 800T A3,采用w4a8量化技术,结合vLLM推理优化,高效平衡性能与精度,助力智能应用开发Jinja00
jiuwenclawJiuwenClaw 是一款基于openJiuwen开发的智能AI Agent,它能够将大语言模型的强大能力,通过你日常使用的各类通讯应用,直接延伸至你的指尖。Python0205- QQwen3.5-397B-A17BQwen3.5 实现了重大飞跃,整合了多模态学习、架构效率、强化学习规模以及全球可访问性等方面的突破性进展,旨在为开发者和企业赋予前所未有的能力与效率。Jinja00
AtomGit城市坐标计划AtomGit 城市坐标计划开启!让开源有坐标,让城市有星火。致力于与城市合伙人共同构建并长期运营一个健康、活跃的本地开发者生态。01
MarkFlowy一款 AI Markdown 编辑器TSX01
热门内容推荐
最新内容推荐
项目优选
收起
deepin linux kernel
C
27
12
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
610
4.06 K
Ascend Extension for PyTorch
Python
451
537
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
924
778
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.47 K
831
暂无简介
Dart
857
205
React Native鸿蒙化仓库
JavaScript
322
377
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Java
69
21
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
374
254
昇腾LLM分布式训练框架
Python
132
159