Skip to content

Bash script that uses pandoc document converter to convert folders and files from .md to .html

License

Notifications You must be signed in to change notification settings

mtichavsky/pandoc-md

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

About

This script converts .md files to .html files through utility called pandoc (which has to be installed on the machine). It lets you specify an array of directories or files in arguments, so you don't have to convert them manually one by one. Script also checks for existing html files and if they are up to date (based on modification date difference between .md and .html) they don't get recompiled to prevent unnecessary writes.

Also contains a bonus: there's a section on converting markdown to PDF (not part of the script), which I use extensively for school projects.

Usage

    pandoc-md [options] [paths]
  • -h show help

SWITCH OPTIONS (one of these is mandatory)

  • -d convert specified directories
  • -i convert specified files
  • -t convert this (local) folder

OPTIONAL OPTIONS

  • -s choose stylesheet to be linked to the resulting .html files
  • -f force option - skips the check if files are up to date
  • -r recursively convert folders (convert files in the working directory and in all containing directories)

If you keep using the same style file for the most of your html files, you can set an environment variable PANDOC_MD_STYLE to contain a path to that script. The path in PANDOC_MD_STYLE will be used by default (that is when you don't use -s option).

Other unrealated notes on similar topic

Markdown to PDF

Unrelated to this script, more like a note to self, this is how I convert .md files to PDF:

# pandoc and LaTeX needs to be installed 
pandoc README.md --pdf-engine=xelatex --metadata-file pandoc-metadata.yml \
  -s -o readme.pdf

Note that it references one more file, pandoc-metadata.yml, which I created specificaly for styling my document. Example contents of this file:

--
# https://pandoc.org/MANUAL.html#variables-for-latex
# A list of LaTeX packages I install on Fedora:
#   - texlive-latex
#   - texlive-babel-czech
#   - texlive-collection-latexrecommended
#   - texlive-adjustbox
author:
- Milan Tichavský
geometry:
  - top=30mm
  - left=20mm
  - right=20mm
  - bottom=30mm
mainfont: "DejaVu Sans"
colorlinks: true
linkcolor: blue
urlcolor: blue
filecolor: magenta
citecolor: green
links-as-notes: true
urlstyle: tt

Of course, you can ignore this option if you're happy with the default style.

Jupyter notebooks to PDF

To be able to convert Jupyter notebooks to PDFs on Fedora, you need additional LaTeX packages (additional to the ones mentioned in YAML file in the previous section):

  • texlive-eurosym # Jupyter
  • texlive-tcolorbox # Jupyter
  • texlive-upquote # Jupyter
  • texlive-titling # Jupyter
  • texlive-ulem # Jupyter
  • texlive-soul # Jupyter

About

Bash script that uses pandoc document converter to convert folders and files from .md to .html

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages