首页
/ PandocRuby 技术文档

PandocRuby 技术文档

2024-12-23 10:15:06作者:卓炯娓

1. 安装指南

1.1 安装 Pandoc

首先,您需要安装 Pandoc。Pandoc 是一个用于将一种标记格式转换为另一种格式的 Haskell 库和命令行工具。您可以通过以下链接获取安装指南:

Pandoc 安装指南

1.2 安装 PandocRuby

PandocRuby 是一个 Ruby 封装库,用于调用 Pandoc 进行文档格式转换。您可以通过 RubyGems 安装 PandocRuby:

gem install pandoc-ruby

如果您使用 Bundler 进行依赖管理,可以在 Gemfile 中添加以下内容:

gem 'pandoc-ruby'

然后运行 bundle install 进行安装。

2. 项目的使用说明

2.1 基本用法

PandocRuby 提供了简单易用的接口来调用 Pandoc 进行文档格式转换。以下是一个基本的示例,将 Markdown 格式的字符串转换为 reStructuredText 格式:

require 'pandoc-ruby'
@converter = PandocRuby.new('# Markdown Title', from: :markdown, to: :rst)
puts @converter.convert

2.2 使用 #convert 类方法

您也可以直接使用 #convert 类方法进行转换:

puts PandocRuby.convert('# Markdown Title', from: :markdown, to: :html)

2.3 其他参数

PandocRuby 支持将其他参数转换为命令行选项,符号和字符串用于选项,哈希用于带参数的选项。例如:

PandocRuby.convert('# Markdown Title', :s, {f: :markdown, to: :rst}, '--wrap=none', :table_of_contents)

等同于:

echo "# Markdown Title" | pandoc -s -f markdown --to=rst --wrap=none --table-of-contents

2.4 使用 #to_[writer] 方法

PandocRuby 还提供了 #to_[writer] 实例方法,用于直接转换为特定格式。例如:

PandocRuby.new('# Example').to_html(:ascii)
# => "<h1 id="example">Example</h1>"

2.5 转换文件

PandocRuby 支持将一个或多个文件路径作为输入,文件内容将被连接并转换:

# 单个文件路径
PandocRuby.new(['/path/to/file1.docx'], from: 'docx').to_html
# 多个文件路径
PandocRuby.new(['/path/to/file1.docx', '/path/to/file1.docx'], from: 'docx').to_html

3. 项目API使用文档

3.1 类方法

  • PandocRuby.convert(input, *options): 将输入内容转换为目标格式。
  • PandocRuby.new(input, *options): 创建一个 PandocRuby 实例。

3.2 实例方法

  • #convert: 将输入内容转换为目标格式。
  • #to_[writer]: 将输入内容转换为特定格式。

3.3 可用的读取器和写入器

  • PandocRuby::READERS: 可用的读取器列表。
  • PandocRuby::STRING_WRITERS: 可用的字符串写入器列表。
  • PandocRuby::BINARY_WRITERS: 可用的二进制写入器列表。
  • PandocRuby::WRITERS: 所有可用的写入器列表。

4. 项目安装方式

4.1 通过 RubyGems 安装

gem install pandoc-ruby

4.2 通过 Bundler 安装

在 Gemfile 中添加:

gem 'pandoc-ruby'

然后运行 bundle install

4.3 设置 Pandoc 路径

如果您需要指定 Pandoc 可执行文件的路径,可以使用以下方法:

PandocRuby.pandoc_path = '/path/to/pandoc'

通过以上步骤,您可以顺利安装并使用 PandocRuby 进行文档格式转换。

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

项目优选

收起
kernelkernel
deepin linux kernel
C
27
11
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
466
3.47 K
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
10
1
leetcodeleetcode
🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解
Java
65
19
flutter_flutterflutter_flutter
暂无简介
Dart
715
172
giteagitea
喝着茶写代码!最易用的自托管一站式代码托管平台,包含Git托管,代码审查,团队协作,软件包和CI/CD。
Go
23
0
kernelkernel
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
203
82
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.27 K
695
rainbondrainbond
无需学习 Kubernetes 的容器平台,在 Kubernetes 上构建、部署、组装和管理应用,无需 K8s 专业知识,全流程图形化管理
Go
15
1
apintoapinto
基于golang开发的网关。具有各种插件,可以自行扩展,即插即用。此外,它可以快速帮助企业管理API服务,提高API服务的稳定性和安全性。
Go
22
1