Pandoc – matoken's blog https://matoken.org/blog Is there no plan B? Wed, 10 Dec 2025 10:23:34 +0000 ja hourly 1 https://wordpress.org/?v=7.0.1 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg Pandoc – matoken's blog https://matoken.org/blog 32 32 Pandoc 3.8.3 でasciidoc 入力に対応 https://matoken.org/blog/2025/12/01/pandoc-3-8-3-now-supports-asciidoc-input/ https://matoken.org/blog/2025/12/01/pandoc-3-8-3-now-supports-asciidoc-input/#respond Mon, 01 Dec 2025 14:20:48 +0000 https://matoken.org/blog/?p=4747

たくさんの文章形式に対応した文章変換ツールのPandoc のバージョン3.8.3 がリリースされました.
個人的にはasciidoc 形式の入力対応が嬉しいです.

Add asciidoc as an input format (#1456).

個人的にasciidoc 形式は好きなのですが,これまでPandoc ではasciidoc への変換は出来てもasciidoc からの変換が出来ないという一方通行でしたがこれで相互変換できそうです.

これまでのpandoc のasciidoc 対応状況
$ pandoc --version
pandoc 3.1.11.1
Features: -server +lua
Scripting engine: Lua 5.4
User data directory: /home/matoken/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://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.
$ pandoc --list-input-formats | grep -i asciidoc
$ pandoc --list-output-formats | grep -i asciidoc
asciidoc
asciidoc_legacy
asciidoctor

早速pandoc 3.8.3 を試します.
とりあえずGitHub Releases の.deb を’もらってきて導入.

$ wget -c https://github.com/jgm/pandoc/releases/download/3.8.3/pandoc-3.8.3-1-amd64.deb (1)
$ sha256sum pandoc-3.8.3-1-amd64.deb  (2)
d7fac78b58b8c8da39254955eff321233ab97d74e8b2d461c0f0719a1fb5f357  pandoc-3.8.3-1-amd64.deb
$ sudo apt install ./pandoc-3.8.3-1-amd64.deb (3)
$ which pandoc
/usr/bin/pandoc
$ pandoc -v (4)
pandoc 3.8.3
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/matoken/.local/share/pandoc
Copyright (C) 2006-2025 John MacFarlane. Web:  https://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.
$ pandoc --list-input-formats | grep -i asciidoc (5)
asciidoc
$ pandoc --list-output-formats | grep -i asciidoc
asciidoc
asciidoc_legacy
asciidoctor
$ pandoc slide/slide.adoc -o /tmp/out.pdf -f asciidoc -t pdf --pdf-engine=weasyprint (6)
  1. pandoc debian amd64 package を入手

  2. hash 確認

  3. system に導入

  4. バージョン確認

  5. 入力フォーマットにasciidoc があるのを確認

  6. 適当なasciidoc をpdf に変換してみる

asciidoc からpdf への変換が出来ました.

pandoc 3.8.3 adoc2pdf

ちなみに現時点での対応フォーマットは入力51,出力75 のようです.この中にはhtml/html4/html5 のようなバージョン違いのようなものも含まれます.

$ pandoc --list-input-formats | wc -l
51
$ pandoc --list-output-formats | wc -l
75

ということでこれまでも便利だったPandoc ですがasciidoc 入力対応でまた一つ便利になりました.

環境
$ pandoc -v
pandoc 3.8.3
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/matoken/.local/share/pandoc
Copyright (C) 2006-2025 John MacFarlane. Web:  https://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.
$ dpkg-query -W pandoc
pandoc  3.8.3-1
$ lsb_release -dr
Description:    Debian GNU/Linux forky/sid
Release:        n/a
$ arch
x86_64
]]>
https://matoken.org/blog/2025/12/01/pandoc-3-8-3-now-supports-asciidoc-input/feed/ 0
LibreOffice Writerの文章を保存時にtextlintして校正する https://matoken.org/blog/2024/11/11/textlint-libreoffice-writer-text-when-saving/ https://matoken.org/blog/2024/11/11/textlint-libreoffice-writer-text-when-saving/#respond Sun, 10 Nov 2024 22:18:38 +0000 https://matoken.org/blog/?p=4223

LibreOfficeというオープンソースのオフィススイートがあります.オフィススイートを使いたいときにはこれを使うことが多いです.
今回LibreOffice Writerでtextlintを使って日本語文章を校正したいなと思って少し試してみました.

まずLibreOffice Writerからtextlintを呼び出せないか調べましたが方法が見つかりません.
仕方がないのでリアルタイムプレビューは諦めてLibreOffice Writerの文章をプレーンテキストに変換してtextlintにかけることにしました.

LibreOffice Writerのファイルをプレーンテキストに変換

はじめLibreOffice同梱の soffice コマンドを試しましたがSTDOUTに出力する方法がわかりませんでした.

$ soffice --headless --convert-to "txt:Text (encoded):UTF8" ./test.odt
$ cat test.txt
Github,youtubeとか
食べれますか?

次にPandocを試しました.STDOUTに出力してくれました.こちらのほうがリソースも少なくて済むでしょうしこちらのほうが良さそうです.

$ pandoc test.odt -t plain
Github,youtubeとか

食べれますか?

標準入力からtextlint

Pandocからの出力を直にtextlintに渡してみます.いい感じそうです.


$ pandoc test.odt -t plain | textlint --color --stdin --stdin-filename text.txt

text.txt
  1:1   error  Github, => GitHub,                              prh
  1:7   error  全角のピリオドとカンマは使用しません。            jtf-style/1.2.2.ピリオド(.)とカンマ(,)
  1:8   error  youtube => YouTube                                prh
  1:16  error    文末が"。"で終わっていません。                    ja-technical-writing/ja-no-mixed-period
  3:3   error    ら抜き言葉を使用しています。                      no-dropping-the-ra
  3:7   error    Disallow to use "?"                               ja-technical-writing/no-exclamation-question-mark
  3:7   error  疑問符(?)を使用する場合は「全角」で表記します。  jtf-style/4.2.2.疑問符(?)

✖ 7 problems (7 errors, 0 warnings)
✓ 4 fixable problems.
Try to run: $ textlint --fix [file]

保存したときに実行する

inotifywaitでLibreOfficeのファイルを監視して保存時に自動的にtextlintが走るようにします.
LibreOfficeの上で編集を行い, Ctrl+s で保存するとinotifywaitが反応して後ろの処理が走りプレーンテキストに変換,textlintでチェックまで動くようになりました.


$ inotifywait test.odt && pandoc test.odt -t plain | textlint --color --stdin --stdin-filename text.txt | aha | xsel -b
Setting up watches.
Watches established.
test.odt OPEN

text.txt
  1:1   error  Github, => GitHub,                              prh
  1:7   error  全角のピリオドとカンマは使用しません。            jtf-style/1.2.2.ピリオド(.)とカンマ(,)
  1:8   error  youtube => YouTube                                prh
  1:16  error    文末が"。"で終わっていません。                    ja-technical-writing/ja-no-mixed-period
  3:3   error    ら抜き言葉を使用しています。                      no-dropping-the-ra
  3:7   error    Disallow to use "?"                               ja-technical-writing/no-exclamation-question-mark
  3:7   error  疑問符(?)を使用する場合は「全角」で表記します。  jtf-style/4.2.2.疑問符(?)

✖ 7 problems (7 errors, 0 warnings)
✓ 4 fixable problems.
Try to run: $ textlint --fix [file]

無限ループ

無限ループの中に入れて保存のたびに走るようにしました.

$ while true; do inotifywait test.odt && pandoc test.odt -t plain | textlint --color --stdin --stdin-filename text.txt; done

LibO textlint

shell script化

一応shell scriptにしておきます.

#!/bin/sh

file="$1"
if [ ! -r "$file" ]; then
  echo "file open error."
  exit 1
fi
textfile=$(basename "${file}" .odt)
dir=$(dirname "${file}")
textfile=${dir}/${textfile}.txt

while true
  do
    inotifywait "${file}" && pandoc "${file}" -t plain | textlint --color --stdin --stdin-filename "${textfile}"
done
環境
$ dpkg-query -W libreoffice-writer pandoc
libreoffice-writer      4:24.8.2-2
pandoc  3.1.11.1+ds-2
$ textlint -v
v14.2.1
$ lsb_release -dr
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
$ arch
x86_64
]]>
https://matoken.org/blog/2024/11/11/textlint-libreoffice-writer-text-when-saving/feed/ 0
Pandoc 3.0 で pandoc-server を少し試す https://matoken.org/blog/2023/01/21/try-pandoc-server/ https://matoken.org/blog/2023/01/21/try-pandoc-server/#respond Fri, 20 Jan 2023 20:51:26 +0000 https://matoken.org/blog/?p=3822

各種ファイル変換をしてくれるPandoc が久々にメジャーバージョンアップして 3.0 になりました.

手元の端末に入れて少し触ってみました.

ディストリビューションパッケージのPandoc をアンインストール
$ sudo apt remove pandoc pandoc-data
GitHub のRelease からPandoc 3.0の amd64 の.deb を入手してインストール
$ wget https://github.com/jgm/pandoc/releases/download/3.0/pandoc-3.0-1-amd64.deb
$ sudo apt install ./pandoc-3.0-1-amd64.deb
$ $ apt show pandoc -a
Package: pandoc
Version: 3.0-1
Status: install ok installed
Priority: optional
Section: text
Maintainer: John MacFarlane <jgm@berkeley.edu>
Installed-Size: 129 MB
Depends: libc6 (>= 2.13), libgmp10, zlib1g (>= 1:1.1.4)
Suggests: texlive-latex-recommended, texlive-xetex, texlive-fonts-recommended
Replaces: pandoc-data
Download-Size: 不明
APT-Manual-Installed: yes
APT-Sources: /var/lib/dpkg/status
Description: general markup converter
  Pandoc is a Haskell library for converting from one markup format
  to another, and a command-line tool that uses this library. The
  formats it can handle include light markup formats (many variants
  of Markdown, reStructuredText, AsciiDoc, Org-mode, Muse, Textile,
  txt2tags), HTML formats (HTML 4 and 5), ebook formats (EPUB v2
  and v3, FB2), Documentation formats (GNU TexInfo, Haddock),
  Roff formats (man, ms), TeX formats (LaTeX, ConTeXt), XML
  formats (DocBook 4 and 5, JATS, TEI Simple, OpenDocument),
  outline formats (OPML), bibliography formats (BibTeX, BibLaTeX,
  CSL JSON, CSL YAML, RIS), word processor formats (Docx, RTF,
  ODT), interactive notebook formats (Jupyter notebook
  ipynb), page layout formats (InDesign ICML), wiki markup
  formats (MediaWiki, DokuWiki, TikiWiki, TWiki, Vimwiki,
  XWiki, ZimWiki, Jira wiki, Creole), slide show formats
  (LaTeX Beamer, PowerPoint, Slidy, reveal.js, Slideous, S5,
  DZSlides), data formats (CSV and TSV tables), and PDF (via
  external programs such as pdflatex or wkhtmltopdf).

Package: pandoc
Version: 2.17.1.1-1.1
Priority: optional
Section: text
Maintainer: Debian Haskell Group <debian-haskell@lists.debian.org>
Installed-Size: 172 MB
Provides: pandoc-abi (= 1.22.2.1-1)
Depends: libc6 (>= 2.34), libffi8 (>= 3.4), libgmp10 (>= 2:6.2.1+dfsg1), liblua5.3-0, libyaml-0-2, zlib1g (>= 1:1.1.4), pandoc-data (>= 2.17.1.1-1.1), pandoc-data (<< 2.17.1.1-1.1.~)
Suggests: texlive-latex-recommended, texlive-xetex, texlive-luatex, pandoc-citeproc, texlive-latex-extra, context, wkhtmltopdf, librsvg2-bin, groff, ghc, nodejs, php, perl, python, ruby, r-base-core, libjs-mathjax, libjs-katex, citation-style-language-styles
Homepage: https://pandoc.org/
Tag: devel::doc, implemented-in::haskell, interface::commandline,
 role::documentation, role::program, use::converting,
 works-with-format::bib, works-with-format::docbook,
 works-with-format::html, works-with-format::json,
 works-with-format::man, works-with-format::odf,
 works-with-format::plaintext, works-with-format::tex,
 works-with-format::xml, works-with::text
Download-Size: 21.3 MB
APT-Sources: http://deb.debian.org/debian bookworm/main amd64 Packages
Description: general markup converter
 Pandoc is a Haskell library for converting
 from one markup format to another,
 and a command-line tool that uses this library.
 The formats it can handle include
  * light markup formats
    (many variants of Markdown, reStructuredText, AsciiDoc,
     Org-mode, Muse, Textile, txt2tags)
  * HTML formats (HTML 4 and 5)
  * Ebook formats (EPUB v2 and v3, FB2)
  * Documentation formats (GNU TexInfo, Haddock)
  * Roff formats (man, ms)
  * TeX formats (LaTeX, ConTeXt)
  * XML formats
    (DocBook 4 and 5, JATS, TEI Simple, OpenDocument)
  * Outline formats (OPML)
  * Bibliography formats (BibTeX, BibLaTeX, CSL JSON, CSL YAML)
  * Word processor formats (Docx, RTF, ODT)
  * Interactive notebook formats (Jupyter notebook ipynb)
  * Page layout formats (InDesign ICML)
  * Wiki markup formats
    (MediaWiki, DokuWiki, TikiWiki, TWiki,
     Vimwiki, XWiki, ZimWiki, Jira wiki, Creole)
  * Slide show formats
    (LaTeX Beamer, PowerPoint, Slidy,
     reveal.js, Slideous, S5, DZSlides)
  * Data formats (CSV tables)
  * PDF (via external programs such as pdflatex or wkhtmltopdf)
 .
 Pandoc can convert mathematical content in documents
 between TeX, MathML, Word equations, roff eqn, and plain text.
 It includes a powerful system
 for automatic citations and bibliographies,
 and it can be customized extensively using templates, filters,
 and custom readers and writers written in Lua.
 .
 This package contains the pandoc tool.
 .
 Some uses of Pandoc require additional packages:
  * SVG content in PDF output requires librsvg2-bin.
  * YAML metadata in TeX-related output requires texlive-latex-extra.
  * *.hs filters not set executable requires ghc.
  * *.js filters not set executable requires nodejs.
  * *.php filters not set executable requires php.
  * *.pl filters not set executable requires perl.
  * *.py filters not set executable requires python.
  * *.rb filters not set executable requires ruby.
  * *.r filters not set executable requires r-base-core.
  * LaTeX output, and PDF output via PDFLaTeX,
    require texlive-latex-recommended.
  * XeLaTeX output, and PDF output via XeLaTeX, require texlive-xetex.
  * LuaTeX output, and PDF output via LuaTeX, require texlive-luatex.
  * ConTeXt output, and PDF output via ConTeXt, require context.
  * PDF output via wkhtmltopdf requires wkhtmltopdf.
  * Roff man and roff ms output, and PDF output via roff ms,
    require groff.
  * MathJax-rendered equations require libjs-mathjax.
  * KaTeX-rendered equations require node-katex.
  * option --csl may use styles in citation-style-language-styles.
$ dpkg -L pandoc
/.
/usr
/usr/bin
/usr/bin/pandoc
/usr/share
/usr/share/doc
/usr/share/doc/pandoc
/usr/share/doc/pandoc/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/pandoc-lua.1.gz
/usr/share/man/man1/pandoc-server.1.gz
/usr/share/man/man1/pandoc.1.gz
/usr/bin/pandoc-lua
/usr/bin/pandoc-server
$ pandoc-server -v
pandoc-server 3.0
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/matoken/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web:  https://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.
$ ls -l /bin/pandoc*
-rwxr-xr-x 1 root root 128885952  1月 19 06:00 /bin/pandoc
lrwxrwxrwx 1 root root         6  1月 19 06:00 /bin/pandoc-lua -> pandoc
lrwxrwxrwx 1 root root         6  1月 19 06:00 /bin/pandoc-server -> pandoc
対応フォーマットの数
$ pandoc --list-input-formats | wc -l
42
$ pandoc --list-output-formats | wc -l
63

Pandoc Server を少し試す

Pandocサーバ起動
$ pandoc-server
Starting server on port 3030...
Pandocサーババージョン確認
$ http http://localhost:3030/version
HTTP/1.1 200 OK
Content-Type: text/plain;charset=utf-8
Date: Fri, 20 Jan 2023 13:24:51 GMT
Server: Warp/3.3.23
Transfer-Encoding: chunked

3.0
絵文字をPandocサーバでhtmlに変換
$ http POST http://localhost:3030/ text=:+1: from=markdown+emoji to=html4 Accept:text/plain
HTTP/1.1 200 OK
Content-Type: text/plain;charset=utf-8
Date: Fri, 20 Jan 2023 20:40:17 GMT
Server: Warp/3.3.23
Transfer-Encoding: chunked

<p><span class="emoji" data-emoji="+1">👍</span></p>
MarkdownファイルをPandocサーバでhtmlに変換
$ head ~/src/tilck/README.md (1)
<p align="center">
   <img src="http://vvaltchev.github.io/tilck_imgs/v2/tilck-logo-v5.png" alt="Tilck - A Tiny Linux-Compatible Kernel">
</p>

[![Build Status](https://vkvaltchev.visualstudio.com/Tilck/_apis/build/status/Tilck?branchName=master)](https://vkvaltchev.visualstudio.com/Tilck/_build/latest?definitionId=1&branchName=master)
[![codecov](https://codecov.io/gh/vvaltchev/tilck/branch/master/graph/badge.svg)](https://codecov.io/gh/vvaltchev/tilck)
[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)

<a href="https://youtu.be/Ce1pMlZO_mI">
   <img
$ http POST http://localhost:3030/ text=@~/src/tilck/README.md from=markdown+emoji to=html4 Accept:text/plain | head (2)
<p align="center">
<img src="http://vvaltchev.github.io/tilck_imgs/v2/tilck-logo-v5.png" alt="Tilck - A Tiny Linux-Compatible Kernel">
</p>
<p><a
href="https://vkvaltchev.visualstudio.com/Tilck/_build/latest?definitionId=1&amp;branchName=master"><img
src="https://vkvaltchev.visualstudio.com/Tilck/_apis/build/status/Tilck?branchName=master"
alt="Build Status" /></a> <a
href="https://codecov.io/gh/vvaltchev/tilck"><img
src="https://codecov.io/gh/vvaltchev/tilck/branch/master/graph/badge.svg"
alt="codecov" /></a> <a
$ http POST http://localhost:3030/ text=@~/src/tilck/README.md from=markdown+emoji to=html4 Accept:text/plain | w3m -T text/html -dump | head (3)
                    Tilck - A Tiny Linux-Compatible Kernel

Build Status codecov License

Tilck

Contents

  • Overview
      □ What is Tilck?
  1. Markdownファイル確認
  2. htmlに変換
  3. Markdownをhtmlに変換してw3mでレンダリング
環境
$ dpkg-query -W pandoc httpie w3m
httpie  3.2.1-1
pandoc  3.0-1
w3m     0.5.3+git20220429-1+b1
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux bookworm/sid
Release:        n/a
Codename:       bookworm
$ arch
x86_64
]]>
https://matoken.org/blog/2023/01/21/try-pandoc-server/feed/ 0