Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 58ffd8b

Browse files
committed
Breaking: Stdin, parameters and docs
1 parent 1208019 commit 58ffd8b

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Its a part of the Docker Command series
88

99
Execute the following within your repository folder:
1010

11-
- Using Bash: `entrypoint.sh source.md > target.html` or `cat target.HTML | entrypoint.sh > target.html`
11+
- Using Bash: `entrypoint.sh source.md > target.html` or `cat target.HTML | entrypoint.sh - > target.html`
1212
- Using Docker: `docker run --rmi -v $(pwd):/workspace kairops/dc-md2html source.md > target.html`
1313
- Using docker-command-launcher: `kd md2html source.md > target.html`
1414

@@ -20,4 +20,4 @@ This function uses the `markdown` package. You could install with:
2020
- Linux DEB package: `apt-get install markdown`
2121
- Linux RPM package: `yum install epel-release` + `yum install discount` (`markdown` command)
2222

23-
You can use either `cat source.md | kd md2html > target.html` or `kd md2html source.md > target.html` format
23+
You can use either `cat source.md | kd md2html - > target.html` or `kd md2html source.md > target.html` format. If you use `-` as parameter the standard input will be processed.

entrypoint.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
5+
function echo_err () {
6+
echo >&2 -e "$@"
7+
}
8+
9+
# Parameter check
10+
if [ $# -eq 0 ]; then
11+
echo_err ">>>>>> md2html: You should use [filename] as parameter or '-' to read from stdin."
12+
exit 1
13+
fi
14+
315
# markdown command check
416
markdownCMD="$(which markdown)"
517
if [ "$markdownCMD" == "" ]; then
6-
echo "Missing 'markdown' command. Abort"
18+
echo ">>>>>> md2html: Missing 'markdown' command. Abort"
719
exit 1
820
fi
921

1022
# Generate HTML from Markdown file if we have it as parameter
11-
if [ "$1" != "" ]; then
23+
echo $1
24+
if [ "$1" != "-" ]; then
1225
if [ -f $1 ]; then
1326
$markdownCMD $1
1427
exit 0
1528
else
16-
echo "File $1 does not exist. Abort"
29+
echo_err ">>>>>> md2html: File $1 does not exist. Abort"
1730
exit 1
1831
fi
1932
fi
2033

21-
# Generate HTML from standard input
22-
(while read -t 5 line; do
23-
echo $line
34+
# Generate HTML from stdin
35+
(while IFS= read -r line; do
36+
printf '%s\n' "$line"
2437
done)|$markdownCMD

0 commit comments

Comments
 (0)