Compare commits

...

10 Commits

Author SHA1 Message Date
Amber 04e9d83cdc added basic page generation 2022-03-03 20:41:35 -06:00
Amber 85ed6f60a1 Updated TODO, started working on metadata. 2022-03-02 22:57:39 -06:00
Amber a5850ba2ec readfile.py works now 2022-03-02 21:59:46 -06:00
Amber 1c5f97d4ce added markdown->html 2022-03-02 20:42:17 -06:00
Amber b00f2892d4 gitignore 2022-03-02 20:14:56 -06:00
Amber 25fa034cc6 be gay. do code. 2022-03-02 20:00:20 -06:00
Amber 9b21f09de8 Train good. Car bad. 2022-03-02 18:47:10 -06:00
Amber 35606fa1be i'm hungry 2022-03-02 18:41:53 -06:00
Amber 57b92bea46 gitignore 2022-03-02 18:26:31 -06:00
Amber 896d384ed9 On branch dev
Your branch is up to date with 'origin/dev'.
	new file:   header.py
	new file:   main.py
2022-03-01 23:32:31 -06:00
9 changed files with 138 additions and 380 deletions

4
.gitignore vendored
View File

@ -1,4 +1,6 @@
.git
workdir
outdir
indir
sample.md
__pycache__/

7
TODO
View File

@ -1,3 +1,6 @@
Multiple template files
Windows compatability
Eventually convert to pure python
Nice HTML tabs
Don't hard-code timezone
Build system
Take input file as a command-line arguement
Figure out licencing

2
header.py Executable file
View File

@ -0,0 +1,2 @@
#!/usr/bin/python

9
htmlTemplate/header.html Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>TITLE</title>
<meta name="generator" content="BadGenerator"/>
<meta name="created" content="CREATEDATE"/>
<meta name="changed" content="MODDATE"/>
</head>

77
main.py Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/python
import readFile
import datetime
#outFile = outFile + ".html"
timeCreate = ""
timeMod = ""
m2h = "" # markdown 2 html
headerStr = ""
footStr = "\n</html>"
def printHtml(head, body, foot, outFile):
print("placeholder")
file = open(outFile, 'w')
file.write(str(head + body + foot))
file.close()
def parseMd(inFile):
global m2h
m2h = str(readFile.readMarkdown(inFile))
return(m2h)
def metadata(inFile):
# Read metadata from possible file
## Pretend there's code here
# Generate metadata
getTime = datetime.datetime.now()
timeMod = str(getTime.strftime("%A, %B %d, %Y at %X UTC06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing
timeCreate = timeMod
title = inFile.split(".")
title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename
# Take title as optional command-line arguement
# Generate html
global headerStr
headerStr = """\
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>"""
headerStr1 = """</title>
<meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/>
<meta name="created" content=" """
headerStr2 = """"/>
<meta name="changed" content=" """
headerStr3 = """"/>
</head>
"""
headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3
return(str(headerStr))
def css():
print("placeholder")
def main():
metadata("sample.md")
parseMd("sample.md")
printHtml(headerStr, m2h, footStr, "outdir/index.html")
def test():
#print(readFile.readMarkdown("/home/amber/website.sh/sample.md"))
print(parseMd("sample.md"))
metadata("sample.md")
main()

View File

@ -1,368 +0,0 @@
#!/bin/bash
<<LICENSE
MIT License
Copyright (c) 2016 Chad Braun-Duin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
LICENSE
# uncomment the following two lines if you have both BSD sed and GNU sed installed
# this script is only tested to work with GNU sed which may have the command gsed
# shopt -s expand_aliases
# alias sed=gsed
# move the original text to a temp file that can be progressively modified
temp_file="/tmp/markdown.$$"
cat "$@" > "$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)\]|<img src=\"$ref_url\" title=\"$ref_title\" alt=\"\1\" />|gI" "$temp_file"
# reference-style link using the label
sed -ri "s|\[([^]]+)\]\[($ref_id)\]|<a href=\"$ref_url\" title=\"$ref_title\">\1</a>|gI" "$temp_file"
# implicit reference-style
sed -ri "s|!\[($ref_id)\]\[\]|<img src=\"$ref_url\" title=\"$ref_title\" alt=\"\1\" />|gI" "$temp_file"
# implicit reference-style
sed -ri "s|\[($ref_id)\]\[\]|<a href=\"$ref_url\" title=\"$ref_title\">\1</a>|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<blockquote>\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<h1>\1<\/h1>/
p
b
}
/\-+$/{
s/\n(.*)\n\-+$/\n<h2>\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 ]*)(.*)/<h1 id="\1">\1\2<\/h1>/g # H1
/^#{2} /s/#{2} ([A-Za-z0-9 ]*)(.*)/<h2 id="\1">\1\2<\/h2>/g # H2
/^#{3} /s/#{3} ([A-Za-z0-9 ]*)(.*)/<h3 id="\1">\1\2<\/h3>/g # H3
/^#{4} /s/#{4} ([A-Za-z0-9 ]*)(.*)/<h4 id="\1">\1\2<\/h4>/g # H4
/^#{5} /s/#{5} ([A-Za-z0-9 ]*)(.*)/<h5 id="\1">\1\2<\/h5>/g # H5
/^#{6} /s/#{6} ([A-Za-z0-9 ]*)(.*)/<h6 id="\1">\1\2<\/h6>/g # H6
/^\*\*\*+$/s/\*\*\*+/<hr \/>/ # hr with *
/^---+$/s/---+/<hr \/>/ # hr with -
/^___+$/s/___+/<hr \/>/ # 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<uli>\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
/<uli>/{
s/(.*)/\n<ul>\1\n<\/uli>\n<\/ul>/ # close the ul tags
s/\n<\/uli>// # kill the first superfluous closing tag
p
b
}
p
' "$temp_file"
sed -i '1 d' "$temp_file" # cleanup superfluous first line
# convert to the proper li to avoid collisions with nested lists
sed -i 's/uli>/li>/g' "$temp_file"
# prepare any nested lists
sed -ri '/^[\*\+\-] /s/(.*)/\n\1\n/' "$temp_file"
done
# ordered lists
# use grep to find all the nested lists
while grep -E '^[1-9]+\. ' "$temp_file" >/dev/null
do
sed -nri '
# wrap the list
/^$/b list
# wrap the li tags then add to the hold buffer
# use oli instead of li to avoid collisions when processing nested lists
/^[1-9]+\. /s/[1-9]+\. (.*)/<\/oli>\n<oli>\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
:list
# exchange the hold space into the pattern space
x
# look for the list items, if there wrap the ol tags
/<oli>/{
s/(.*)/\n<ol>\1\n<\/oli>\n<\/ol>/ # close the ol tags
s/\n<\/oli>// # kill the first superfluous closing tag
p
b
}
p
' "$temp_file"
sed -i '1 d' "$temp_file" # cleanup superfluous first line
# convert list items into proper list items to avoid collisions with nested lists
sed -i 's/oli>/li>/g' "$temp_file"
# prepare any nested lists
sed -ri '/^[1-9]+\. /s/(.*)/\n\1\n/' "$temp_file"
done
# make escaped periods literal
sed -ri '/^[1-9]+\\. /s/([1-9]+)\\. /\1\. /' "$temp_file"
# code blocks
sed -nri '
# if at end of file, append the current line to the hold buffer and print it
${
H
b code
}
# wrap the code block on any non code block lines
/^\t| {4}/!b code
# else, append to the holding buffer and do nothing
H
b # else, branch to the end of the script
:code
# exchange the hold space with the pattern space
x
# look for the code items, if there wrap the pre-code tags
/\t| {4}/{
s/(\t| {4})(.*)/<pre><code>\n\1\2\n<\/code><\/pre>/ # wrap the ending tags
p
b
}
p
' "$temp_file"
sed -i '1 d' "$temp_file" # cleanup superfluous first line
# convert html characters inside pre-code tags into printable representations
sed -ri '
# get inside pre-code tags
/^<pre><code>/{
:inside
n
# if you found the end tags, branch out
/^<\/code><\/pre>/!{
s/&/\&amp;/g # ampersand
s/</\&lt;/g # less than
s/>/\&gt;/g # greater than
b inside
}
}
' "$temp_file"
# remove the first tab (or 4 spaces) from the code lines
sed -ri 's/^\t| {4}(.*)/\1/' "$temp_file"
# br tags
sed -ri '
# if an empty line, append it to the next line, then check on whether there is two in a row
/^$/ {
N
N
/^\n{2}/s/(.*)/\n<br \/>\1/
}
' "$temp_file"
# emphasis and strong emphasis and strikethrough
sed -nri '
# batch up the entire stream of text until a line break in the action
/^$/b emphasis
H
$ b emphasis
b
:emphasis
x
s/\*\*(.+)\*\*/<strong>\1<\/strong>/g
s/__([^_]+)__/<strong>\1<\/strong>/g
s/\*([^\*]+)\*/<em>\1<\/em>/g
s/([^\\])_([^_]+)_/\1<em>\2<\/em>/g
s/\~\~(.+)\~\~/<strike>\1<\/strike>/g
p
' "$temp_file"
sed -i '1 d' "$temp_file" # cleanup superfluous first line
# paragraphs
sed -nri '
# if an empty line, check the paragraph
/^$/ b para
# else append it to the hold buffer
H
# at end of file, check paragraph
$ b para
# now branch to end of script
b
# this is where a paragraph is checked for the pattern
:para
# return the entire paragraph into the pattern space
x
# look for non block-level elements, if there - print the p tags
/\n<(div|table|pre|p|[ou]l|h[1-6]|[bh]r|blockquote|li)/!{
s/(\n+)(.*)/\1<p>\n\2\n<\/p>/
p
b
}
p
' "$temp_file"
sed -i '1 d' "$temp_file" # cleanup superfluous first line
# cleanup area where P tags have broken nesting
sed -nri '
# if the line looks like like an end tag
/^<\/(div|table|pre|p|[ou]l|h[1-6]|[bh]r|blockquote)>/{
h
# if EOF, print the line
$ {
x
b done
}
# fetch the next line and check on whether or not it is a P tag
n
/^<\/p>/{
G
b done
}
# else, append the line to the previous line and print them both
H
x
}
:done
p
' "$temp_file"
# inline styles and special characters
sed -ri '
s/<(http[s]?:\/\/.*)>/<a href=\"\1\">\1<\/a>/g # automatic links
s/<(.*@.*\..*)>/<a href=\"mailto:\1\">\1<\/a>/g # automatic email address links
# inline code
s/([^\\])``+ *([^ ]*) *``+/\1<code>\2<\/code>/g
s/([^\\])`([^`]*)`/\1<code>\2<\/code>/g
s/!\[(.*)\]\((.*) \"(.*)\"\)/<img alt=\"\1\" src=\"\2\" title=\"\3\" \/>/g # inline image with title
s/!\[(.*)\]\((.*)\)/<img alt=\"\1\" src=\"\2\" \/>/g # inline image without title
s/\[(.*)]\((.*) "(.*)"\)/<a href=\"\2\" title=\"\3\">\1<\/a>/g # inline link with title
s/\[(.*)]\((.*)\)/<a href=\"\2\">\1<\/a>/g # inline link
# special characters
/&.+;/!s/&/\&amp;/g # ampersand
/<[\/a-zA-Z]/!s/</\&lt;/g# less than bracket
# backslash escapes for literal characters
s/\\\*/\*/g # asterisk
s/\\_/_/g # underscore
s/\\`/`/g # underscore
s/\\#/#/g # pound or hash
s/\\\+/\+/g # plus
s/\\\-/\-/g # minus
s/\\\\/\\/g # backslash
' "$temp_file"
# display and cleanup
cat "$temp_file" && rm "$temp_file"

16
outline
View File

@ -1,12 +1,18 @@
Prompt for title
generate html headers
$(date); os, software; xml parsers to see if updating existing page?
store in variable; use sed and newline delimiters if needed
metadata
date, os, time, time modified
get from seperate file?
title from file name?
prompt for body
vipe; probably markdown
fuck it, sed NO BAD
prompt for body; done
write navbar, sidebar with already-made files
edit navbar based on url
css
Stick it all together
write headers, side/navbars, body, and css
build script to make one binary

29
readFile.py Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python
import markdown
# Only do the <body> tag
class readMarkdown():
outStr = ""
mdFile = ""
def __init__(self, mdFile):
self.outStr = ""
self.mdFile = mdFile
def markdown(self, mdFile):
print("placeholder")
file = open(self.mdFile, 'r')
#middleVar = file.read()
self.outStr = str(markdown.markdown(file.read())) #TODO: I really want nice tab indentations
file.close()
return(self.outStr)
def __str__(self):
return(str(self.markdown(self.mdFile)))
# might want to find a way to diff html from a file and readMarkdown()'s output if I want to update pages
# Edit: just keep the original markdown files dumbass

View File

@ -1,4 +1,2 @@
coreutils
markdown.sh #https://github.com/chadbraunduin/markdown.bash, included in repo as markdown.sh
moreutils # For text editor support
python
python-markdown https://python-markdown.github.io/