forked from crowdin/crowdin-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-docs.sh
executable file
·89 lines (66 loc) · 3.72 KB
/
prepare-docs.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
printf "[INFO] Prepare docs start...\n"
printf "\n[INFO] Gradle build...\n"
./gradlew build
printf "\n[INFO] Generating manpages...\n"
./gradlew generateManpageAsciiDoc
cd website/generated-picocli-docs || exit
printf "\n[INFO] Wrapping the Synopsis section with code block...\n"
sed -i.bak -e 's/Synopsis/Synopsis\n\n----/g' -- *.adoc
sed -i.bak -e 's/\/\/ end::picocli-generated-man-section-synopsis/----\n\n\/\/ end::picocli-generated-man-section-synopsis/g' -- *.adoc
printf "\n[INFO] Converting adoc -> md...\n"
cd ../mantemplates || exit
# Convert adoc to xml and then xml to md
# https://pandoc.org/MANUAL.html
asciidoctor -b docbook5 -d article -- *.adoc
if [ $? -ne 0 ]; then
echo "[Error] asciidoctor converting failed!"
exit 1
fi
find ./ -iname "*.xml" -type f -exec sh -c 'pandoc -f docbook -t markdown_strict --fail-if-warnings --markdown-headings=atx "${0}" -o "../docs/commands/$(basename ${0%.xml}.md)"' {} \;
if [ $? -ne 0 ]; then
echo "[Error] pandoc converting failed!"
exit 1
fi
sed -i.bak -e 's/\x1B//g' -- *.xml # remove invisible ESC character from synopsis
rm -- *.xml
rm -- *.xml.bak
printf "\n[INFO] Prettifying content...\n"
cd ../docs/commands || exit
# Synopsis formatting
sed -i.bak -e 's/\[39m//g' -e 's/\[32m//g' -e 's/\[0m//g' -- *.md # remove style
sed -i.bak -e 's/\x1B//g' -- *.md # remove invisible ESC character
sed -i.bak -e 's/\xe2\x80\x8b//g' -- *.md # remove zero-width space
sed -i.bak -e 's/\\\[/\[/g' -e 's/\\\]/\]/g' -- *.md # remove brackets escape
# Content formatting
sed -i.bak -e 's/\*CONFIG OPTIONS\*\:/Config Options/g' -- *.md # CONFIG OPTIONS: -> Config Options
sed -i.bak -e 's/™/(TM)/g' -- *.md
sed -i.bak -e 's/crowdin.yml/`crowdin.yml`/g' -e 's/crowdin.yaml/`crowdin.yaml`/g' -- *.md
sed -i.bak -e 's/\*CONFIG OPTIONS\*\:/Config Options/g' -- *.md # CONFIG OPTIONS: -> Config Options
sed -i.bak -e 's/\*\*--\([[:alnum:]_\-]*\)\*\*/`--\1`/g' -- *.md # **--config** -> `--config`
sed -i.bak -e 's/\*\*-\([[:alnum:]_\-]*\)\*\*/`-\1`/g' -- *.md # **-c** -> `-c`
sed -i.bak -e 's/.xml)/)/g' -- *.md # fix links
# Set headings level 2
sed -i.bak -e 's/# Description$/## Description/g' -- *.md
sed -i.bak -e 's/# Synopsis$/## Synopsis/g' -- *.md
sed -i.bak -e 's/# Commands$/## Commands/g' -- *.md
sed -i.bak -e 's/# Options$/## Options/g' -- *.md
sed -i.bak -e 's/# Arguments$/## Arguments/g' -- *.md
sed -i.bak -e 's/# Config Options/## Config Options/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]hidden\*\*/`--\[no-]hidden`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]duplicate-translations\*\*/`--[no-]duplicate-translations`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]translate-untranslated-only\*\*/`--[no-]translate-untranslated-only`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]translate-with-perfect-match-only\*\*/`--[no-]translate-with-perfect-match-only`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]skip-assigned-strings\*\*/`--[no-]skip-assigned-strings`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]skip-untranslated-strings\*\*/`--[no-]skip-untranslated-strings`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]include-pre-translated-strings-only\*\*/`--[no-]include-pre-translated-strings-only`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]auto-update\*\*/`--[no-]auto-update`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]auto-approve-imported\*\*/`--[no-]auto-approve-imported`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]import-eq-suggestions\*\*/`--[no-]import-eq-suggestions`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]translate-hidden\*\*/`--[no-]translate-hidden`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]preserve-hierarchy\*\*/`--[no-]preserve-hierarchy`/g' -- *.md
sed -i.bak -e 's/\*\*--\[no-\]auto-tag\*\*/`--[no-]auto-tag`/g' -- *.md
rm -- *.md.bak
printf "\n[INFO] Content list:\n"
ls -l
printf "\n[INFO] Finish!" || exit