作者都是各自领域经过审查的专家,并撰写他们有经验的主题. 我们所有的内容都经过同行评审,并由同一领域的Toptal专家验证.
菲利普·爱德华兹
验证专家 在工程

前大学讲师, Phillip has extensive experience in all aspects of software development, 具有Java方面的专业知识.

专业知识

以前在

Okta
分享

今天,我们将进一步了解专业人士如何获得 P和oc to create a robust 和 easy-to-implement publication chain. P和oc是一个非常简单但功能强大的工具,允许用户将文档转换为各种格式, 取决于他们的需求.

It can greatly simplify documentation 和 publication, or even open up a few new automation possibilities. 最重要的是, P和oc依赖于git友好的减价, 这意味着您还可以在没有任何额外麻烦的情况下为文档实现版本控制系统.

说到麻烦, 我们将依靠码头工人镜像来安装P和oc和乳胶. Installing software can be time-consuming, 当开始一个新项目时,从头开始建立一个工作的软件环境几乎没有生产力. 码头工人通过允许用户在几分钟内设置所有内容来帮助缓解这些问题, 不管平台是什么.

另外, 雇主要求你提供自己的电脑硬件是很常见的. This is often referred to as Bring Your Own Device (BYOD), 和 let’s not forget that the COVID-19 p和emic has made 在家工作越来越普遍. 没有像码头工人这样的解决方案, 它将很难支持运行在不同硬件和操作系统(如Windows)上的应用程序, macOS, 和Linux.

在继续学习P和oc之前,让我们先仔细看看码头工人容器和映像.

救援码头工人

使用码头工人容器可以消除在新机器上安装多个软件应用程序的需要. 预构建的码头工人映像可在 码头工人中心 用于大量的应用程序. 领先的云提供商(如AWS、Azure和Google)都提供容器注册表. 的re are many other third-party registries including GitLab红帽OpenShift.

It is likely that an 图像 will be available for most (if not all) applications. 这意味着没有必要安装大多数应用程序及其依赖项. 的 application can simply be run in a 码头工人 container. 这方便地消除了与团队成员在不同硬件和不同操作系统上运行应用程序相关的问题. 的 same 图像 can be used to run containers on any system that can run them, 和 码头工人专家 can make this process extremely fast 和 efficient.

P和oc用例:文档

Documentation may be required in several different formats. 同一文档可能需要以不同的格式提供,例如演示文稿使用HTML格式,讲义使用PDF格式. Converting between file formats can be tedious 和 require a lot of time. A good solution is to have a publication chain with a single source of truth. All documents should be written in the same language. 它应该是一种基于文本的语言,因为它更容易版本化和存储在Git存储库中.

减价 is a good choice for creating a single source of truth. 可以将减价文档转换为各种其他格式的软件很容易获得,而且往往是可靠的.

减价可以很容易地转换成一系列不同的格式,用于各种用途

P和oc

P和oc is a software package that can convert documents into different formats. 特别是,它可以将减价转换为HTML、PDF和其他广泛使用的格式. 可以使用减价源中的模板和元数据自定义转换过程.

P和oc需要 乳胶 安装以创建PDF文件. Installing P和oc 和 乳胶 is quite time-consuming. Fortunately, there is a 码头工人 图像 called pandoc /乳胶, which eliminates the need to install anything other than 码头工人.

码头工人的命令

需要找到或创建一个包含必要软件的合适的码头工人映像. 建议将映像拉到本地注册表,因为下载可能需要一些时间.

码头工人拉pandoc /乳胶

要在码头工人容器中运行命令,需要一个包装器来运行码头工人容器并在容器中执行命令. 一个好的解决方案是在macOS或UNIX/Linux系统上编写shell函数. 的 function can be put in any login scripts or in a separate file such as $ HOME /.功能. It is also possible to write a script or an alias with the same functionality.

函数pandoc {
   Echo pandoc $@
   docker run -it --rm - v $ PWD: /工作 - w /工作 pandoc /乳胶 pandoc“$ @”
}

这个函数的作用如下:

  • 它将命令打印到屏幕上.
  • 对象运行码头工人容器 pandoc /乳胶 图像.
  • -it 选项创建一个交互式终端会话,并使命令的输出可见.
  • --rm option deletes the container once the comm和 has terminated.
  • - v $ PWD: /工作 option mounts the current directory on the host to the directory /工作 在容器里.
  • - w /工作 使 /工作 directory 在容器里 the working directory.
  • 最后一个 pandoc“$ @” 运行 pandoc 命令在容器中传递传递给该函数的所有命令行选项.

A shell or a script needs to load the function into 内存.

. $ HOME /.功能

的 function is now a comm和 in its own right 和 behaves the same way as if the pandoc 二进制文件在本地安装. This approach can be used for any comm和 available in a 码头工人 图像.

降低到HTML

要将减价转换为HTML,最好在减价中使用模板和元数据.

降低到HTML

减价的元数据

的 减价 source can have a header section that can have arbitrary metadata. 的 metadata takes the form of key-value pairs. 的 values can be substituted in the HTML template.

---
title:文件标题
链接:
  上一页:指数
  下一个:page002
...

的 header starts with a line containing only three dashes ---. It is terminated with a line containing only three dots .... Keys are single words followed by a colon 和 its value. 键可以嵌套. 的 example shows the definition of keys called 标题、链接.上一页链接.下一个.

This approach uses a separate file for each page. 在本例中,前一页为 指数.md,当前页面为 page001.md,下一页是 page002.md. 在实践中, 将使用更有意义的文件名,以便更容易重新排序和插入页面.

HTML模板

HTML模板就是一个HTML文件. 元数据替换和简单的控制结构可以在美元符号之间添加. Here is a simple example of an HTML template for P和oc:


    
        
        
        $title$
        
    
    

$title$

身体美元

该示例显示了 template. 的 身体美元 gets replaced with the 减价 text converted to HTML. 只有当元数据在减价标头中定义时,条件语句才会生成HTML链接.

从减价生成HTML

P和oc只需要被告知输入和输出文件的名称以及任何模板文件. 默认的输入文件格式为 减价. It can infer the output file format from the specified output file extension.

的 comm和s to generate outputs can be a script or a makefile.

dir =项目
对于${dir}/*中的input_file.md
do
    output_file = HTML / $ {input_file %.md}.html
    如果[[${input_file} -nt ${output_file}]]
    然后
        pandoc——data-dir . ——模板演示.HTML -t HTML \
                ${output_file} ${input_file}
    fi
完成

对于每一个 .md 存档于 项目 目录下,它创建一个对应的 .html 存档于 HTML /项目 directory if the output file is older than the input file or doesn’t exist.

从减价生成激光PDF

Beamer is a 乳胶 package for producing presentations. 输出是一个PDF幻灯片.

从减价生成激光PDF

的 same 减价 source files can be used to generate the beamer PDF.

pandoc - t投影机 -o PDF/项目.pdf -V theme:Boadilla -V colortheme:whale 项目/index.医学博士项目/ page000.md

命令的详细信息如下:

  • - t投影机 option says use 乳胶 和 beamer to generate the PDF.
  • -o 选项指定输出文件.
  • -V options select the beamer theme 和 color theme.
  • 该命令以减价文件列表结束,这些文件将按照给定的顺序连接起来.

All of the processing is performed inside a 码头工人 container.

降价至PDF格式

Converting a 减价 document to a PDF document is also quite simple. PDF is always generated by first converting the 减价 to 乳胶. 可以将元数据添加到减价标头中以自定义输出,例如设置纸张大小和边距大小.

---
title:文件的标题
papersize: a4
几何:
-利润= 20毫米
...

从减价生成PDF

的 comm和 to convert the 降价至PDF格式 is simple:

pandoc -s项目/大纲.md -o PDF/项目Outline.pdf

的 -s option creates a st和alone document.

结论

It is no longer necessary to spend many days installing software. 简单地在码头工人容器中运行命令就不需要安装了. Many applications have suitable 码头工人 图像s on 码头工人中心. If the software needs updating, simply pull the latest 码头工人 图像.

Setting up a new computer is just a matter of installing 码头工人, 提取必要的图像, 并创建一些脚本.

It is no longer necessary to create documents in different formats. A single format such as 减价 can be used for all documents. 然后,像P和oc这样的工具可以从减价生成大量不同格式的文档.

由于减价是一个文本文件,当签入Git存储库时,可以获得完整的版本历史记录. Git存储库也会自动呈现减价,并允许人们对更改进行注释,而不必在文档文件本身中使用混乱的更改历史.

了解基本知识

  • 码头工人是什么?它的用途是什么?

    码头工人实现了轻量级虚拟化,允许应用程序及其依赖关系在称为容器的隔离环境中运行.

  • 码头工人是如何工作的?

    码头工人 creates containers from a subset of available CPUs, 内存, 和其他资源,并执行单个应用程序,该应用程序与其依赖项一起存储在称为映像的精简Linux文件系统上.

  • 潘多克是什么?

    P和oc is open-source software that can convert documents, 通常用减价写, into a wide range of other document formats including HTML 和 PDF.

  • 如何使用P和oc?

    P和oc是一个命令行工具,它将输入文件及其文档类型作为参数, the required output file 和 its document type, 和 optionally a template file defining the output file format.

  • 什么是P和oc 减价?

    P和oc 减价是减价的一个稍微修改的版本,减价是一种轻量级的纯文本标记语言,通常用于格式化自述文件和在线消息发布.

聘请Toptal这方面的专家.
现在雇佣
菲利普·爱德华兹

菲利普·爱德华兹

验证专家 在工程

Marseillan、法国

2018年10月10日成为会员

作者简介

前大学讲师, Phillip has extensive experience in all aspects of software development, 具有Java方面的专业知识.

作者都是各自领域经过审查的专家,并撰写他们有经验的主题. 我们所有的内容都经过同行评审,并由同一领域的Toptal专家验证.

专业知识

以前在

Okta

世界级的文章,每周发一次.

By entering your email, you are agreeing to our 隐私政策.

世界级的文章,每周发一次.

By entering your email, you are agreeing to our 隐私政策.

Toptal开发者

加入总冠军® 社区.