Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tissue Research JKU
Tissue Research Doc
Commits
7de06b95
Commit
7de06b95
authored
Dec 03, 2021
by
Sabina Köfler
Browse files
Complete script
parent
c0695e8c
Changes
1
Hide whitespace changes
Inline
Side-by-side
quick-start-guides/convert_to_pdf.sh
View file @
7de06b95
...
@@ -7,7 +7,6 @@ replace_whitespaces() {
...
@@ -7,7 +7,6 @@ replace_whitespaces() {
done
done
}
}
# Create array to store all md files for later
# Create array to store all md files for later
# readarray -d '' array < <(find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown")
# readarray -d '' array < <(find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown")
create_filearray
()
{
create_filearray
()
{
...
@@ -54,11 +53,14 @@ select_latex_engine() {
...
@@ -54,11 +53,14 @@ select_latex_engine() {
echo
echo
}
}
ex
tr
a
ct_filename
()
{
cons
tr
u
ct_filename
()
{
y
=
"
$file
"
# ./FILENAME.EXTENSION
y
=
"
$file
"
# ./FILENAME.EXTENSION
x
=
"
${
y
%.*
}
"
# ./FILENAME
x
=
"
${
y
%.*
}
"
# ./FILENAME
z
=
"
${
x
##*/
}
"
# FILENAME
z
=
"
${
x
##*/
}
"
# FILENAME
# echo "Extracted filename: ${z}"
pdf_filename
=
"
${
z
}
.pdf"
pdf_path
=
"./
${
pdf_dir
}
/
${
pdf_filename
}
"
# bak_pdf_filename="${z}_${file_date}-${file_time}.pdf"
# bak_pdf_path="./${pdf_dir}/${bak_pdf_filename}"
}
}
create_date_string
()
{
create_date_string
()
{
...
@@ -67,16 +69,10 @@ create_date_string() {
...
@@ -67,16 +69,10 @@ create_date_string() {
file_date
=
"
$a
"
# the first part is the date
file_date
=
"
$a
"
# the first part is the date
ftime
=
"
${
b
%.*
}
"
# the second part is the time (but its too exact, so strip everything after the .)
ftime
=
"
${
b
%.*
}
"
# the second part is the time (but its too exact, so strip everything after the .)
file_time
=
${
ftime
//
:
}
# remove the colons from the time stamp
file_time
=
${
ftime
//
:
}
# remove the colons from the time stamp
#
echo "Constructed date string: $file_date and time string: $file_time"
echo
"Constructed date string:
$file_date
and time string:
$file_time
"
}
}
construct_bak_path
()
{
construct_pdf_path
()
{
bak_pdf_filename
=
"
${
z
}
_
${
file_date
}
-
${
file_time
}
.pdf"
pdf_filename
=
"
${
z
}
.pdf"
pdf_path
=
"./
${
pdf_dir
}
/
${
pdf_filename
}
"
}
construct_bak_pdf_path
()
{
bak_pdf_filename
=
"
${
z
}
_
${
file_date
}
-
${
file_time
}
.pdf"
# create new filename
bak_pdf_path
=
"./
${
pdf_dir
}
/
${
bak_pdf_filename
}
"
bak_pdf_path
=
"./
${
pdf_dir
}
/
${
bak_pdf_filename
}
"
}
}
# END functions #
# END functions #
...
@@ -87,6 +83,9 @@ replace_whitespaces
...
@@ -87,6 +83,9 @@ replace_whitespaces
create_filearray
create_filearray
find_markdown
find_markdown
create_outdir_if_not_exists
create_outdir_if_not_exists
# exit
select_latex_engine
select_latex_engine
# # Allow user to add custom LaTeX variables
# # Allow user to add custom LaTeX variables
...
@@ -96,31 +95,37 @@ select_latex_engine
...
@@ -96,31 +95,37 @@ select_latex_engine
# Compile documents
# Compile documents
echo
-e
"
\n
Beginning conversion...
\n
"
echo
-e
"
\n
Beginning conversion...
\n
"
search
=
"
\[\[
_TOC_
\]\]
"
search1
=
"
\[\[
_TOC_
\]\]
"
search2
=
"## Inhalt"
# find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown" | while read -r file; do # find -iname finds <pattern> case insensitive
# find . -iname "*.md" -o -iname "*.mdown" -o -iname "*.markdown" | while read -r file; do # find -iname finds <pattern> case insensitive
for
file
in
"
${
files
[@]
}
"
;
do
for
file
in
"
${
files
[@]
}
"
;
do
# echo "File:" ${file}
echo
"File:"
${
file
}
extract_filename
# construct_filename $file
construct_pdf_path
# remove the line that renders the table of contents in markdown and copy file to /PDFs
construct_bak_pdf_path
if
!
grep
-q
"
$search1
"
$file
;
then
# echo "PDF Path: $pdf_path"
continue
else
echo
-e
"Found search string in
$file
\n
Will make a copy"
sed
"/
$search1
/d;/
$search2
/d"
$file
>
./
$pdf_dir
/
$file
fi
done
find ./
$pdf_dir
-iname
"*.md"
|
while
read
-r
file
;
do
echo
-e
"
\n
Found files to convert
$file
"
construct_filename
#$file
if
[
-f
"
$pdf_path
"
]
;
then
if
[
-f
"
$pdf_path
"
]
;
then
#
echo "File $file was already converted."
echo
-e
"File
$file
was already converted
to
$pdf_path
."
create_date_string
create_date_string
# echo "Bak file name: $bak_pdf_filename"
construct_bak_path
echo
"Constructing back up path:
$bak_pdf_path
"
mv
$pdf_path
$bak_pdf_path
mv
$pdf_path
$bak_pdf_path
echo
-e
"
\n
Existing file was moved to
${
bak_pdf_path
}
\n
"
echo
-e
"
\n
Existing file was moved to
${
bak_pdf_path
}
\n
"
fi
# remove the line that renders the table of contents in markdown
if
[
"
$search
"
]
;
then
# TODO - should files be copied if search string is found?
echo
"Nothing to replace"
else
else
echo
"I am replacing"
echo
-e
"File
$file
not the same as
$pdf_path
."
# sed -i "/$search/d" $file
fi
fi
#
echo -e "Continuing with new file creation\n"
echo
-e
"Continuing with new file creation
\n
"
#
pandoc -s --toc --template=my.latex -f gfm "$file" --pdf-engine=$option -o "$pdf_path" # could add --variable font-family:sans-serif $variable
pandoc
-s
--toc
--template
=
my.latex
-f
gfm
"
$file
"
--pdf-engine
=
$option
-o
"
$pdf_path
"
# could add --variable font-family:sans-serif $variable
#
echo -e "File created\n"
echo
-e
"File created
\n
"
done
done
echo
-e
"
\n
All files complete!"
echo
-e
"
\n
All files complete!"
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment