From 1c5f97d4cee6e959284efc787f0a6ff0a34693ca Mon Sep 17 00:00:00 2001 From: Amber Date: Wed, 2 Mar 2022 20:40:58 -0600 Subject: [PATCH] added markdown->html --- .gitignore | 1 + main.py | 7 +- markdown.sh | 368 --------------------------------------------------- outline | 11 +- readFile.py | 28 ++-- requirements | 2 + 6 files changed, 29 insertions(+), 388 deletions(-) delete mode 100755 markdown.sh diff --git a/.gitignore b/.gitignore index eee16ae..7828afa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ workdir outdir indir sample.md +__pycache__/ diff --git a/main.py b/main.py index c74f3fa..907c813 100755 --- a/main.py +++ b/main.py @@ -29,4 +29,9 @@ def css(): print("placeholder") def main(): - print("placeholder") \ No newline at end of file + print("placeholder") + +def test(): + print(readFile.readMarkdown("/home/amber/website.sh/sample.md")) + +#test() \ No newline at end of file diff --git a/markdown.sh b/markdown.sh deleted file mode 100755 index f310895..0000000 --- a/markdown.sh +++ /dev/null @@ -1,368 +0,0 @@ -#!/bin/bash - -< "$temp_file" - -# All of this below business is for reference-style links and images -# We need to loop across newlines and not spaces -IFS=' -' -refs=$(sed -nr "/^\[.+\]: +/p" "$@") -for ref in $refs -do - ref_id=$(echo -n "$ref" | sed -nr "s/^\[(.+)\]: .*/\1/p" | tr -d '\n') - ref_url=$(echo -n "$ref" | sed -nr "s/^\[.+\]: (.+)/\1/p" | cut -d' ' -f1 | tr -d '\n') - ref_title=$(echo -n "$ref" | sed -nr "s/^\[.+\]: (.+) \"(.+)\"/\2/p" | sed 's@|@!@g' | tr -d '\n') - - # reference-style image using the label - sed -ri "s|!\[([^]]+)\]\[($ref_id)\]|\"\1\"|gI" "$temp_file" - # reference-style link using the label - sed -ri "s|\[([^]]+)\]\[($ref_id)\]|\1|gI" "$temp_file" - - # implicit reference-style - sed -ri "s|!\[($ref_id)\]\[\]|\"\1\"|gI" "$temp_file" - # implicit reference-style - sed -ri "s|\[($ref_id)\]\[\]|\1|gI" "$temp_file" -done - -# delete the reference lines -sed -ri "/^\[.+\]: +/d" "$temp_file" - -# blockquotes -# use grep to find all the nested blockquotes -while grep '^> ' "$temp_file" >/dev/null -do - sed -nri ' -/^$/b blockquote - -H -$ b blockquote -b - -:blockquote -x -s/(\n+)(> .*)/\1
\n\2\n<\/blockquote>/ # wrap the tags in a blockquote -p -' "$temp_file" - - sed -i '1 d' "$temp_file" # cleanup superfluous first line - - # cleanup blank lines and remove subsequent blockquote characters - sed -ri ' -/^> /s/^> (.*)/\1/ -' "$temp_file" -done - -# Setext-style headers -sed -nri ' -# Setext-style headers need to be wrapped around newlines -/^$/ b print - -# else, append to holding area -H -$ b print -b - -:print -x -/=+$/{ -s/\n(.*)\n=+$/\n

\1<\/h1>/ -p -b -} -/\-+$/{ -s/\n(.*)\n\-+$/\n

\1<\/h2>/ -p -b -} -p -' "$temp_file" - -sed -i '1 d' "$temp_file" # cleanup superfluous first line - -# atx-style headers and other block styles -sed -ri ' -/^#+ /s/ #+$// # kill all ending header characters -/^# /s/# ([A-Za-z0-9 ]*)(.*)/

\1\2<\/h1>/g # H1 -/^#{2} /s/#{2} ([A-Za-z0-9 ]*)(.*)/

\1\2<\/h2>/g # H2 -/^#{3} /s/#{3} ([A-Za-z0-9 ]*)(.*)/

\1\2<\/h3>/g # H3 -/^#{4} /s/#{4} ([A-Za-z0-9 ]*)(.*)/

\1\2<\/h4>/g # H4 -/^#{5} /s/#{5} ([A-Za-z0-9 ]*)(.*)/

\1\2<\/h5>/g # H5 -/^#{6} /s/#{6} ([A-Za-z0-9 ]*)(.*)/
\1\2<\/h6>/g # H6 - -/^\*\*\*+$/s/\*\*\*+/
/ # hr with * -/^---+$/s/---+/
/ # hr with - -/^___+$/s/___+/
/ # hr with _ - -' "$temp_file" - -# unordered lists -# use grep to find all the nested lists -while grep '^[\*\+\-] ' "$temp_file" >/dev/null -do -sed -nri ' -# wrap the list -/^$/b list - -# wrap the li tags then add to the hold buffer -# use uli instead of li to avoid collisions when processing nested lists -/^[\*\+\-] /s/[\*\+\-] (.*)/<\/uli>\n\n\1/ - -H -$ b list # if at end of file, check for the end of a list -b # else, branch to the end of the script - -# this is where a list is checked for the pattern -:list -# exchange the hold space into the pattern space -x -# look for the list items, if there wrap the ul tags -//{ -s/(.*)/\n