-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-syntax-highlight-as-rtf-via-pygmentize
More file actions
executable file
·55 lines (47 loc) · 1.73 KB
/
gen-syntax-highlight-as-rtf-via-pygmentize
File metadata and controls
executable file
·55 lines (47 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# Author: Goldie Lin
# Description: Convert source code to RTF with syntax highlighting.
# Requirements:
# * pygmentize (python script)
# * python-pygments (python library)
# * libreoffice (optional)
# * abiword (optional)
# Usage:
# $ gen-syntax-highlight-as-rtf-via-pygmentize <file>
# It'll generated a new <file.rtf> with syntax highlighting of the input
# source code. Then, you can use LibreOffice or AbiWord to open this
# <file.rtf>, and copy contain to other program. (e.g., LibreOffice
# Impress, LibreOffice Writter, or another AbiWord.)
# $ pygmentize -L styles
# Show more avaiable styles supported by pygments.
# References:
# * https://blog.gslin.org/archives/2016/10/22/6930/%E5%B0%8D%E6%8A%95%E5%BD%B1%E7%89%87%E7%9A%84%E7%A8%8B%E5%BC%8F%E7%A2%BC%E5%8A%A0%E4%B8%8A%E8%89%B2%E5%BD%A9/
# * https://evertpot.com/syntax-highlighting-in-presentations/
# * http://pygments.org/docs/cmdline/
set -euo pipefail
# Variable definitions
# ====================
# Light themes:
# default, paraiso-light, xcode, vs, autumn, colorful, emacs, tango,
# friendly, manni, pastie, perldoc.
# Dark themes:
# native, paraiso-dark, vim, monokai, fruity, igor, rrt.
pygments_opt="style=default" # styles I preferred are: default, native, vim, xcode, emacs.
# Function definitions
# ====================
main() {
local -r input="$(readlink -f "$1")"
local -r rtf="${input}.rtf"
if [[ ! -f "${input}" ]]; then
echo "Usage: $0 <file>"
else
# pass the rest of arguments to pygmentize.
shift
if (( $# )); then
pygmentize "$@" -O "${pygments_opt}" -f "rtf" -o "${rtf}" "${input}"
else
pygmentize -O "${pygments_opt}" -f "rtf" -o "${rtf}" "${input}"
fi
fi
}
main "$@"