Skip to content

Instantly share code, notes, and snippets.

@ozmos
Last active July 3, 2023 04:12
Show Gist options
  • Save ozmos/f47471ee990d34affdedf76f169d2037 to your computer and use it in GitHub Desktop.
Save ozmos/f47471ee990d34affdedf76f169d2037 to your computer and use it in GitHub Desktop.
Simple Markdown to HTML Shell Script
#! /bin/bash
# Simple script to convert markdown to html and apply some basic styles to headings and code snippets
# Written for PopOs and other Linux distros using dpkg as package manager
# Used for styling Moodle posts written in markdown
# pandoc must be installed for this script to work.
# first check if pandoc is installed
if dpkg -s pandoc | grep -q "install ok installed"
then
pandoc $1 -f markdown-auto_identifiers -t html -o $2
sed --in-place 's/<h2>/<h2 style="font-size:22px; color: #000; font-weight:600">/' $2
sed --in-place 's/<h3>/<h3 style="font-size:20px; color: #111; font-weight:600">/' $2
sed --in-place 's/<h4>/<h4 style="font-size:18px; color: #222; font-weight:600">/' $2
sed --in-place 's/<h5>/<h5 style="font-size:16px; color: #333; font-weight:600">/' $2
sed --in-place 's/<pre /<pre style="padding: 8px 16px; color:#f5d67b; background:#1b1b1b; white-space: pre-wrap;" /' $2
sed --in-place 's/<th>/<th style="padding: 8px; border: black solid 1px">/' $2
sed --in-place 's/<td>/<td style="padding: 8px; border: black solid 1px">/' $2
# center reference header
sed --in-place 's/<p><strong>References<\/strong><\/p>/<p style\="text-align\:center"><strong>References<\/strong><\/p>/' $2
if grep -q \#\# $2
then echo "Markdown may not be formatted correctly"
fi
else
echo "Please install pandoc"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment