-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create a PDF file from Markdown documents (md2pdf) #11257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
067a4d7
e7cfae3
3a442e2
6dfa925
8e634ac
2277b00
8a0660b
af60155
1388371
761b98e
7999636
d899873
b55aae5
0b7a4f6
7620508
63430b9
2e25572
00e087b
ce9fe32
97b9b8a
1e24baf
c27e3bb
c917f26
9dbb155
1bcca9e
5d28c9f
a9ee311
d94ea36
251d436
db6f2f5
f7a0667
0314c1e
ee68a15
fe6a1ed
67b6a8c
b8aab0b
81e7d81
4dfdc10
1ef4b83
15fb83b
0d7ef9c
5bf10b7
e75021d
e2ca8fe
5c6bac8
2b0fb76
bcec9f2
238f593
dbebfe4
4fd99b8
0e83880
779ffa5
ba9990d
ab6961a
451c352
b62f98c
18d267b
d43588b
d6f5b13
497b04f
2003757
2acb641
9822973
6383e62
c725883
45f1157
cca0aef
4681407
145899b
25ee815
8291e51
15d4ba1
3130926
ff5f7e9
414fd97
0e9b758
24cc317
9c85ebb
f9fc161
ca39802
15f7ae4
9ff0d4c
f8be8f2
5ac7adc
d15a234
9b85042
a1a5a0a
e38d4b7
8fe4593
77ea171
0ccbee8
c61b09b
825cfcc
804f005
d2be290
e7fe9eb
6d97268
7e0fe06
7d47860
b03a9a6
645a233
7cccddd
f4306e2
808b1a7
035e081
524b034
8e51561
eca1e51
73c8ea9
0e491f7
ece8b34
3776afb
aa0b9b4
4579509
a614d79
2322fe9
98c8977
d155c65
6d51056
4438273
ea79336
161cd41
0f33822
f27d3c9
ede1a50
3339c92
ca07eb3
ded06b0
02b86cc
53a5189
8a21460
d65b62c
fef312e
e1b045f
89585c9
2f29d69
6eb5f21
244e976
cd3dc3a
fcffed6
ed985ca
f4fa164
cc1892d
99223f4
a905547
4950820
c011ada
c95ee93
b06a689
52ddedb
f4ab2cf
511882e
f6902bb
235a364
01bc30c
9154836
eb2b1ad
93670ff
144100c
bebf97a
2b9311a
d976fe3
39094b1
8b28db5
888828c
bed2c9d
ba7f121
e510487
ab22bed
ec29ddf
2354dbc
7de8074
8a83a70
4f4598a
eda52b6
e8797ff
6efbda4
60af122
b7f64a9
67e85ae
0b53581
83e7ad9
4cd7159
3e7db05
5de9c72
d4e7651
959b112
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Pandoc | ||
|
||
on: | ||
push: | ||
branches: [scala3-pandoc] | ||
|
||
jobs: | ||
printenv: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Print Ubuntu environment | ||
run: | | ||
env | grep GIT | ||
env | grep HOME | ||
docker version --format '{{.Server.Version}}' | ||
#docker run pandoc/latex:latest --version | grep ^pandoc | ||
|
||
build: | ||
needs: printenv | ||
runs-on: ubuntu-latest | ||
container: | ||
image: pandoc/latex:latest | ||
#if: "( github.event_name == 'pull_request' | ||
# && !contains(github.event.pull_request.body, '[skip ci]') | ||
# && !contains(github.event.pull_request.body, '[skip docs]') | ||
# ) | ||
# || contains(github.event.ref, 'pandoc') | ||
# || contains(github.event.ref, 'master')" | ||
|
||
steps: | ||
- name: Git Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Print Pandoc environment | ||
run: | | ||
#env | grep TEX | ||
pandoc --version | grep ^pandoc | ||
|
||
- name: Install additional TeX fonts | ||
run: | | ||
find . -name install-tex-fonts | ||
chmod u+x ./pandoc/extras/install-tex-fonts | ||
DEBUG=1 & ./pandoc/extras/install-tex-fonts | ||
|
||
- name: Generate PDF reference documentation | ||
run: | | ||
find . -name md2pdf | ||
chmod u+x ./pandoc/md2pdf | ||
DEBUG=1 & ./pandoc/md2pdf reference |
+2 −1 | common/src/main/scala/TensorShapeDenotation.scala | |
+2 −1 | common/src/main/scala/io/kjaer/compiletime/Shape.scala | |
+1 −2 | core/src/main/scala/ONNX.scala |
+1 −1 | shared/src/main/scala/scala/concurrent/stm/ccstm/ViewOps.scala |
+1 −1 | utest/src-3/utest/asserts/Asserts.scala | |
+2 −2 | utest/test/src/test/utest/AssertsTests.scala |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
docs/ | ||
extras/ | ||
*.bat | ||
README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tmp/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## Created by mics (https://github.com/michelou/) on December 2020. | ||
|
||
FROM pandoc/ubuntu-latex:2.11.4 | ||
|
||
LABEL md2pdf.author="Stéphane Micheloud <stephane.micheloud@gmail.com>" | ||
LABEL md2pdf.description="Create PDF file for Scala 3 documentation" | ||
LABEL md2pdf.version=1.0 | ||
|
||
WORKDIR /dotty | ||
COPY ./tmp/docs ./docs/docs | ||
|
||
WORKDIR pandoc | ||
COPY ./data ./data | ||
COPY ./md2pdf . | ||
|
||
ENV TEXLIVE_HOME=/opt/texlive/texdir | ||
|
||
## See https://github.com/openjournals/whedon/blob/master/paperdraft.Dockerfile | ||
RUN tlmgr update --self | ||
|
||
## Install additional LaTeX packages | ||
## Already present: fancyvrb, fontspec, l3backend, l3kernel, l3packages, pgf, unicode-math, xcolor. | ||
RUN tlmgr install \ | ||
dejavu \ | ||
environ \ | ||
gnu-freefont \ | ||
selnolig \ | ||
tcolorbox \ | ||
trimspaces | ||
|
||
RUN echo "#!/bin/bash \n ./md2pdf \n ls /dotty/out/pandoc/" > ./entrypoint.sh | ||
RUN chmod +x ./entrypoint.sh | ||
|
||
ENTRYPOINT [ "./entrypoint.sh" ] | ||
CMD [ "reference" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# <span id="top">Creating PDF files for the Scala 3 documentation</span> | ||
<!-- created by mics (https://github.com/michelou/) on December 2020 --> | ||
|
||
This project is located at the root of the [`lampepfl/dotty`][github_dotty] repository, at the same level as the [`Scaladoc`][github_scala3doc] project. | ||
|
||
We aim to generate a *single* PDF file from a collection of [Markdown] documents, for instance for the [*Scala 3 reference*][scala3_reference] documentation. | ||
|
||
Our solution is built on [Pandoc]; it gets its inputs from two directories and generates a PDF file into the output directory: | ||
|
||
<table style="margin-top:-10px; max-width:650px;"> | ||
<tr> | ||
<td><b>Input directories</b></td> | ||
<td><code>docs/docs/<project>/</code><br/><code>pandoc/data/</code></td> | ||
<td><code>*.md</code> files<br/><a href="https://pandoc.org/">Pandoc</a> data files</td> | ||
</tr> | ||
<tr> | ||
<td><b>Output directory</b></td> | ||
<td><code>out/pandoc/</code></td> | ||
<td><code>scala3_<i><project></i>.pdf</code><sup>(*)</sup></td> | ||
</tr> | ||
</table> | ||
|
||
<span style="margin-left:10px;font-size:90%;"><sup>(*)</sup> *`<project>`* is one of [`contributing`](https://github.com/lampepfl/dotty/tree/master/docs/docs/contributing), [`internals`](https://github.com/lampepfl/dotty/tree/master/docs/docs/internals), [`reference`](https://github.com/lampepfl/dotty/tree/master/docs/docs/reference) or [`usage`](https://github.com/lampepfl/dotty/tree/master/docs/docs/usage).</span> | ||
|
||
The generated PDF file is more elaborated than its sibling HTML version; unlike the online [*Scala 3 reference*][scala3_reference] documentation available on the [Scala 3 documentation](https://docs.scala-lang.org/scala3/) webpage, the `scala3_reference.pdf` document : | ||
- starts with a *title page* directly followed by a *table of contents* and ends with an *appendix*. | ||
- gathers all the "*More details*" sections in the appendix. | ||
|
||
> See document [`PROJECT.md`](docs/PROJECT.md) for further information, e.g. project organisation. | ||
|
||
## <span id="dependencies">Project dependencies</span> | ||
|
||
This project depends on the following software : | ||
|
||
- [Pandoc 2](https://github.com/jgm/pandoc/releases) <sup id="anchor_01">[1](#footnote_01)</sup> *([release notes](https://pandoc.org/releases.html))* | ||
- [TeX Live 2021](https://tug.org/texlive/) <sup id="anchor_02">[2](#footnote_02)</sup> *([release notes](http://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-880009.2))* | ||
|
||
> See documents [`PANDOC.md`](docs/PANDOC.md) and [`TEXLIVE.md`](docs/TEXLIVE.md) for product specific information, e.g. software installation. | ||
|
||
One may also install the following software: | ||
|
||
- [Docker Desktop 3](https://docs.docker.com/get-docker/) <sup id="anchor_03">[3](#footnote_03)</sup> *([release notes](https://docs.docker.com/release-notes/))* | ||
|
||
> See document [`DOCKER.md`](docs/DOCKER.md) for further information, e.g. `Dockerfile` usage. | ||
|
||
## <span id="commands">Build commands</span> | ||
|
||
We provide two commands for MacOS/Ubuntu as well as their equivalents for MS Windows : | ||
- for *interactive users* :<br/>[`build {<option>|<subcommand>}`](./build) (resp. [`build.bat`](./build.bat) on MS Windows)<br/><span style="font-size:80%;">(option `-help` displays the available options/subcommands).</span> | ||
- for *automated tasks* (primarily, but not exclusively) :<br/>[`md2pdf [<project>]`](./md2pdf) (resp. [`md2pdf.bat`](./md2pdf.bat) on MS Windows)<br/><span style="font-size:80%;">(default value for `<project>` : `reference`).</span> | ||
|
||
We also provide support for cloud development/deployment : | ||
|
||
- with *Docker*<br/><a href="./Dockerfile"><code>Dockerfile</code></a>, a text document to create a Docker image featuring <a href="https://tug.org/texlive/">TeX Live</a>, <a href="https://pandoc.org/">Pandoc</a> and <a href="./md2pdf"><code>md2pdf</code></a>. | ||
- with *GitHub Actions* <b style="color:red;">WIP</b> :<br/><a href="../.github/workflows/pandoc.yaml"><code>pandoc.yaml</code></a>, a workflow file to run CI jobs with <a href="https://docs.github.com/en/actions">GitHub Actions</a>. | ||
|
||
> See document [`EXAMPLES.md`](docs/EXAMPLES.md) for usage examples in different environments. | ||
|
||
## <span id="footnotes">Footnotes</span> | ||
|
||
<span id="footnote_01">[1]</span> ***Pandoc software*** [↩](#anchor_01) | ||
|
||
<dl><dd> | ||
<a href="https://pandoc.org/">Pandoc</a> is both a library and a command line tool for converting files from one markup format into another. Through the command line option <a href="https://pandoc.org/MANUAL.html#option--pdf-engine"><code>--pdf-engine=<path></code></a> Pandoc supports many PDF engines, among others <a href="https://linux.die.net/man/1/pdflatex"><code>pdflatex</code></a>, <a href="http://www.luatex.org/"><code>lualatex</code></a> and <code>xelatex</code>. | ||
</dd></dl> | ||
|
||
<span id="footnote_02">[2]</span> ***MiKTeX software*** [↩](#anchor_02) | ||
|
||
<dl><dd> | ||
As an alternative to <a href="https://tug.org/texlive/">TeX Live 2020</a> one may also use the <a href="https://miktex.org/">MiKTeX</a> distribution <i>(<a href="https://miktex.org/announcement/miktex-20-12">release notes</a>)</i> which we have tested on both MS Windows 10 and <a href="https://www.msys2.org/">MSYS2</a>. | ||
</dd></dl> | ||
|
||
<span id="footnote_03">[3]</span> ***Docker software*** [↩](#anchor_03) | ||
|
||
<dl><dd> | ||
We run <a href="https://docs.docker.com/docker-for-windows/install/">Docker Desktop for Windows</a> on our development machine.<br/> | ||
Note that WSL 2 is required to interact with Docker on Windows from <a href="https://ubuntu.com/wsl">Ubuntu for WSL</a> (see documentation <a href="https://docs.docker.com/docker-for-windows/wsl/">Docker Desktop WSL 2 backend</a>). | ||
</dd></dl> | ||
|
||
*** | ||
|
||
*[mics](https://github.com/michelou/)/January 2022* [**▲**](#top "Back to top") | ||
<span id="bottom"> </span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While your comment is justified for people working with 20+ inch screens, I and others I guess are used to read online docs with a 5.8 inch cell phone, in which case this tiny button is very practical. I let you decide. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, it's fine to keep it. |
||
|
||
[github_dotty]: https://github.com/lampepfl/dotty/#dotty | ||
[github_scala3doc]: https://github.com/lampepfl/dotty/tree/master/scala3doc#scala3doc | ||
[markdown]: https://commonmark.org/ | ||
[pandoc]: https://pandoc.org/ "A universal document converter" | ||
[scala3_reference]: https://dotty.epfl.ch/docs/reference/overview.html | ||
[tex_live]: https://tug.org/texlive/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Created by mics (https://github.com/michelou/) on December 2020. | ||
|
||
############################################################################## | ||
## Subroutines | ||
|
||
getHome() { | ||
local source="${BASH_SOURCE[0]}" | ||
while [ -h "$source" ] ; do | ||
local linked="$(readlink "$source")" | ||
local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd )" | ||
source="$dir/$(basename "$linked")" | ||
done | ||
( cd -P "$(dirname "$source")" && pwd ) | ||
} | ||
|
||
getOS() { | ||
local os | ||
case "$(uname -s)" in | ||
Linux*) os=Linux;; | ||
Darwin*) os=Mac;; | ||
CYGWIN*) os=Win;; # os=Cygwin;; | ||
MINGW*) os=Win;; # os=MinGw;; | ||
*) os=Unknown | ||
esac | ||
echo $os | ||
} | ||
|
||
# use variables EXITCODE, TIMER_START | ||
cleanup() { | ||
[[ $1 =~ ^[0-1]$ ]] && EXITCODE=$1 | ||
|
||
if $TIMER; then | ||
local timer_end=$(date +'%s') | ||
local duration=$((timer_end - TIMER_START)) | ||
echo "Total elapsed time: $(date -d @$duration +'%H:%M:%S')" 1>&2 | ||
fi | ||
debug "EXITCODE=$EXITCODE" | ||
exit $EXITCODE | ||
} | ||
|
||
verbose() { | ||
$VERBOSE && echo "$1" 1>&2 | ||
} | ||
|
||
debug() { | ||
local debug_label="[46m[DEBUG][0m" | ||
$DEBUG && echo "$debug_label $1" 1>&2 | ||
} | ||
|
||
error() { | ||
local error_label="[91mError:[0m" | ||
echo "$error_label $1" 1>&2 | ||
} | ||
|
||
args() { | ||
PROJECT_NAME=$PROJECT_NAME_DEFAULT | ||
|
||
[[ $# -eq 0 ]] && HELP=true && return 1 | ||
|
||
for arg in "$@"; do | ||
case "$arg" in | ||
## options | ||
-debug) DEBUG=true ;; | ||
-help) HELP=true ;; | ||
-project:*) PROJECT_NAME="$(project_name ${arg:9})" ;; | ||
-timer) TIMER=true ;; | ||
-verbose) VERBOSE=true ;; | ||
-*) | ||
error "Unknown option $arg" | ||
EXITCODE=1 && return 0 | ||
;; | ||
## subcommands | ||
clean) CLEAN=true ;; | ||
compile) COMPILE=true ;; | ||
help) HELP=true ;; | ||
*) | ||
error "Error: Unknown subcommand $arg" | ||
EXITCODE=1 && return 0 | ||
;; | ||
esac | ||
done | ||
$CLEAN || $COMPILE || $HELP || HELP=true | ||
debug "Options : DEBUG=$DEBUG TIMER=$TIMER VERBOSE=$VERBOSE" | ||
debug "Subcommands: CLEAN=$CLEAN COMPILE=$COMPILE HELP=$HELP" | ||
debug "Variables : PANDOC_HOME=$PANDOC_HOME" | ||
debug "Variables : TEXLIVE_HOME=$TEXLIVE_HOME" | ||
debug "Variables : PROJECT_NAME=$PROJECT_NAME" | ||
# See http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/ | ||
$TIMER && TIMER_START=$(date +"%s") | ||
} | ||
|
||
help() { | ||
cat << EOS | ||
Usage: $BASENAME { <option> | <subcommand> } | ||
|
||
Options: | ||
-debug show commands executed by this script | ||
-help display this help message | ||
-project:<name> project name (default: $PROJECT_NAME_DEFAULT) | ||
-timer display total elapsed time | ||
-verbose display progress messages | ||
|
||
Subcommands: | ||
clean delete generated files | ||
help display this help message | ||
compile compile source files | ||
EOS | ||
} | ||
|
||
project_name() { | ||
local name="" | ||
case "$1" in | ||
internals) name="internals" ;; | ||
reference) name="reference" ;; | ||
usage) name="usage" ;; | ||
*) error "Invalid project name $1" | ||
esac | ||
$name | ||
} | ||
|
||
clean() { | ||
if [ -d "$TARGET_DIR" ]; then | ||
debug "rm -rf $TARGET_DIR" | ||
verbose "Delete directory $TARGET_DIR" | ||
rm -rf "$TARGET_DIR" | ||
[[ $? -eq 0 ]] || ( EXITCODE=1 & return 0 ) | ||
fi | ||
} | ||
|
||
compile() { | ||
[ -d "$TARGET_DIR" ] || mkdir -p "$TARGET_DIR" | ||
|
||
debug "$MD2PDF_CMD $PROJECT_NAME" | ||
verbose "$MD2PDF_CMD $PROJECT_NAME" | ||
$MD2PDF_CMD $PROJECT_NAME | ||
[[ $? -eq 0 ]] || ( EXITCODE=1 & return 0 ) | ||
} | ||
|
||
############################################################################## | ||
## Environment setup | ||
|
||
BASENAME=$(basename "${BASH_SOURCE[0]}") | ||
|
||
EXITCODE=0 | ||
|
||
PROG_HOME="$(getHome)" | ||
|
||
OS="$(getOS)" | ||
[ $OS == "Unknown" ] && error "Unsupported OS" | ||
[ $OS == "Win" ] && EXT=".exe" || EXT="" | ||
|
||
MD2PDF_CMD=$PROG_HOME/md2pdf | ||
[ -x "$MD2PDF_CMD" ] || error "md2pdf script not found" | ||
|
||
PROJECT_NAME_DEFAULT=reference | ||
|
||
CLEAN=false | ||
COMPILE=false | ||
DEBUG=false | ||
HELP=false | ||
TIMER=false | ||
VERBOSE=false | ||
|
||
TARGET_DIR=$(dirname "$PROG_HOME")/out/pandoc | ||
|
||
args "$@" | ||
[[ $EXITCODE -eq 0 ]] || cleanup 1 | ||
|
||
############################################################################## | ||
## Main | ||
|
||
$HELP && help && cleanup | ||
|
||
if $CLEAN; then | ||
clean || cleanup 1 | ||
fi | ||
if $COMPILE; then | ||
compile || cleanup 1 | ||
fi | ||
|
||
cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've wondering, instead of having two commands
build
andmd2pdf
, can we have the same command for both local machines and cloud CI, assuming that both will use a published docker image?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion is right.
The existence of both commands
build
andmd2pdf
stems in part from my own background as a long-standing developer. Let me try to advocate the case (for fun) :build
is a user-friendly wrapper script; it callsmd2pdf
but it also-verbose
and-debug
) and some subcommands (e.g.clean
andview
on MS Windows); I typically run commandbuild -timer -verbose clean view
to generate filescala3_reference.pdf
on my Win10 laptop.scala3_reference.pdf
) is generated depending on input file timestamps.md2pdf
is the minimal script for runningpandoc
with the appropriate settings.In the context of the Dotty project, we can indeed have only one shell script :
md2pdf
(and may bemd2pdf.bat
).NB. I could even omit several
type checksenvironment checks inmd2pdf
assuming users can help themselves in case of errors.