pandoc

2021-08-12 09:35:58 浏览数 (2)

前言

Pandoc 是一个开源的文档转换工具

If you need to convert files from one markup format into another, pandoc is your swiss-army knife

Pandoc 可以很方便地将文档在主流的文档格式间转化

下面分享一下 Pandoc 的基础安装操作

参考 Installing pandoc

Tip: 当前版本 pandoc 2.1

环境

代码语言:javascript复制
[root@C7-x64 ~]# hostnamectl
   Static hostname: C7-x64
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 29c0bd00e83945a782b7fd29e243bb04
           Boot ID: 515b4fd00d824c5f911d8f8c9c3fbbd0
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-514.el7.x86_64
      Architecture: x86-64
[root@C7-x64 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b5:c1:f7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.85.135/24 brd 192.168.85.255 scope global dynamic ens33
       valid_lft 1527sec preferred_lft 1527sec
    inet6 fe80::a47d:a3e4:aa89:329c/64 scope link
       valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b5:c1:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.193.150/24 brd 192.168.193.255 scope global ens34
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb5:c101/64 scope link
       valid_lft forever preferred_lft forever
[root@C7-x64 ~]#

下载软件包

代码语言:javascript复制
[root@C7-x64 ~]# wget https://github.com/jgm/pandoc/releases/download/2.1/pandoc-2.1-linux.tar.gz
--2017-11-08 06:23:48--  https://github.com/jgm/pandoc/releases/download/2.1/pandoc-2.1-linux.tar.gz
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/571770/76f86130-f3f9-11e7-95b8-f1699da5c622?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A/20180112/us-east-1/s3/aws4_request&X-Amz-Date=20180112T053251Z&X-Amz-Expires=300&X-Amz-Signature=7ea237d8d777354b495e3df0578e16da6aa3f588d0d984a3244b189537343602&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment; filename=pandoc-2.1-linux.tar.gz&response-content-type=application/octet-stream [following]
--2017-11-08 06:23:49--  https://github-production-release-asset-2e65be.s3.amazonaws.com/571770/76f86130-f3f9-11e7-95b8-f1699da5c622?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A/20180112/us-east-1/s3/aws4_request&X-Amz-Date=20180112T053251Z&X-Amz-Expires=300&X-Amz-Signature=7ea237d8d777354b495e3df0578e16da6aa3f588d0d984a3244b189537343602&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment; filename=pandoc-2.1-linux.tar.gz&response-content-type=application/octet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.224.80
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.224.80|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26076325 (25M) [application/octet-stream]
Saving to: ‘pandoc-2.1-linux.tar.gz’

100%[======================================>] 26,076,325   228KB/s   in 2m 8s  

2017-11-08 06:25:58 (199 KB/s) - ‘pandoc-2.1-linux.tar.gz’ saved [26076325/26076325]

[root@C7-x64 ~]# ls
anaconda-ks.cfg  pandoc-2.1-linux.tar.gz
[root@C7-x64 ~]# du -sh pandoc-2.1-linux.tar.gz
25M     pandoc-2.1-linux.tar.gz
[root@C7-x64 ~]# md5sum  pandoc-2.1-linux.tar.gz
f41c9eed50afdbac31eec3a8d36d1b8a  pandoc-2.1-linux.tar.gz
[root@C7-x64 ~]#

其它系统可以参考 官方安装文档

解压就可以直接使用

代码语言:javascript复制
[root@C7-x64 ~]# tar -zxvf pandoc-2.1-linux.tar.gz
pandoc-2.1/
pandoc-2.1/bin/
pandoc-2.1/bin/pandoc
tar: pandoc-2.1/bin/pandoc: time stamp 2018-01-08 00:56:09 is 5250186.51259372 s in the future
pandoc-2.1/bin/pandoc-citeproc
tar: pandoc-2.1/bin/pandoc-citeproc: time stamp 2018-01-08 00:56:10 is 5250186.205655332 s in the future
pandoc-2.1/share/
tar: pandoc-2.1/bin: time stamp 2018-01-08 00:56:10 is 5250186.205582786 s in the future
pandoc-2.1/share/man/
pandoc-2.1/share/man/man1/
pandoc-2.1/share/man/man1/pandoc-citeproc.1.gz
tar: pandoc-2.1/share/man/man1/pandoc-citeproc.1.gz: time stamp 2018-01-08 00:56:10 is 5250186.204954061 s in the future
pandoc-2.1/share/man/man1/pandoc.1.gz
tar: pandoc-2.1/share/man/man1/pandoc.1.gz: time stamp 2018-01-08 00:56:10 is 5250186.203777874 s in the future
tar: pandoc-2.1/share/man/man1: time stamp 2018-01-08 00:56:10 is 5250186.203713964 s in the future
tar: pandoc-2.1/share/man: time stamp 2018-01-08 00:56:08 is 5250184.2037013 s in the future
tar: pandoc-2.1/share: time stamp 2018-01-08 00:56:08 is 5250184.203692436 s in the future
tar: pandoc-2.1: time stamp 2018-01-08 00:56:08 is 5250184.203684527 s in the future
[root@C7-x64 ~]#
[root@C7-x64 ~]# tree pandoc-2.1
pandoc-2.1
├── bin
│   ├── pandoc
│   └── pandoc-citeproc
└── share
    └── man
        └── man1
            ├── pandoc.1.gz
            └── pandoc-citeproc.1.gz

4 directories, 4 files
[root@C7-x64 ~]#

参数列表

代码语言:javascript复制
[root@C7-x64 ~]# ./pandoc-2.1/bin/pandoc -h
pandoc [OPTIONS] [FILES]
  -f FORMAT, -r FORMAT  --from=FORMAT, --read=FORMAT                    
  -t FORMAT, -w FORMAT  --to=FORMAT, --write=FORMAT                     
  -o FILE               --output=FILE                                   
                        --data-dir=DIRECTORY                            
                        --base-header-level=NUMBER                      
                        --strip-empty-paragraphs                        
                        --indented-code-classes=STRING                  
  -F PROGRAM            --filter=PROGRAM                                
                        --lua-filter=SCRIPTPATH                         
  -p                    --preserve-tabs                                 
                        --tab-stop=NUMBER                               
                        --track-changes=accept|reject|all               
                        --file-scope                                    
                        --extract-media=PATH                            
  -s                    --standalone                                    
                        --template=FILE                                 
  -M KEY[:VALUE]        --metadata=KEY[:VALUE]                          
  -V KEY[:VALUE]        --variable=KEY[:VALUE]                          
  -D FORMAT             --print-default-template=FORMAT                 
                        --print-default-data-file=FILE                  
                        --print-highlight-style=STYLE|FILE              
                        --dpi=NUMBER                                    
                        --eol=crlf|lf|native                            
                        --wrap=auto|none|preserve                       
                        --columns=NUMBER                                
                        --strip-comments                                
                        --toc, --table-of-contents                      
                        --toc-depth=NUMBER                              
                        --no-highlight                                  
                        --highlight-style=STYLE|FILE                    
                        --syntax-definition=FILE                        
  -H FILE               --include-in-header=FILE                        
  -B FILE               --include-before-body=FILE                      
  -A FILE               --include-after-body=FILE                       
                        --resource-path=SEARCHPATH                      
                        --request-header=NAME:VALUE                     
                        --self-contained                                
                        --html-q-tags                                   
                        --ascii                                         
                        --reference-links                               
                        --reference-location=block|section|document     
                        --atx-headers                                   
                        --top-level-division=section|chapter|part       
  -N                    --number-sections                               
                        --number-offset=NUMBERS                         
                        --listings                                      
  -i                    --incremental                                   
                        --slide-level=NUMBER                            
                        --section-divs                                  
                        --default-image-extension=extension             
                        --email-obfuscation=none|javascript|references  
                        --id-prefix=STRING                              
  -T STRING             --title-prefix=STRING                           
  -c URL                --css=URL                                       
                        --reference-doc=FILE                            
                        --epub-subdirectory=DIRNAME                     
                        --epub-cover-image=FILE                         
                        --epub-metadata=FILE                            
                        --epub-embed-font=FILE                          
                        --epub-chapter-level=NUMBER                     
                        --pdf-engine=PROGRAM                            
                        --pdf-engine-opt=STRING                         
                        --bibliography=FILE                             
                        --csl=FILE                                      
                        --citation-abbreviations=FILE                   
                        --natbib                                        
                        --biblatex                                      
                        --mathml                                        
                        --webtex[=URL]                                  
                        --mathjax[=URL]                                 
                        --katex[=URL]                                   
  -m[URL]               --latexmathml[=URL], --asciimathml[=URL]        
                        --mimetex[=URL]                                 
                        --jsmath[=URL]                                  
                        --gladtex                                       
                        --abbreviations=FILE                            
                        --trace                                         
                        --dump-args                                     
                        --ignore-args                                   
                        --verbose                                       
                        --quiet                                         
                        --fail-if-warnings                              
                        --log=FILE                                      
                        --bash-completion                               
                        --list-input-formats                            
                        --list-output-formats                           
                        --list-extensions[=FORMAT]                      
                        --list-highlight-languages                      
                        --list-highlight-styles                         
  -v                    --version                                       
  -h                    --help                                          
[root@C7-x64 ~]#
[root@C7-x64 ~]# ./pandoc-2.1/bin/pandoc --version
pandoc 2.1
Compiled with pandoc-types 1.17.3, texmath 0.10.1, skylighting 0.5.1
Default user data directory: /root/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web:  http://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.
[root@C7-x64 ~]#

使用

代码语言:javascript复制
[root@C7-x64 markdown]# ls
pandoc.md
[root@C7-x64 markdown]# ../pandoc-2.1/bin/pandoc -s -f markdown -t docx pandoc.md -o pandoc.docx
[root@C7-x64 markdown]# ls
pandoc.docx  pandoc.md
[root@C7-x64 markdown]#

其它Demo

其它使用方式可以参考 Pandoc官方示例

0 人点赞