|
@ -1,6 +1,6 @@ |
|
|
import os |
|
|
import os |
|
|
import json |
|
|
import json |
|
|
from flask import Flask, request, render_template, redirect, url_for |
|
|
from flask import Flask, request, render_template, render_template_string, redirect, url_for |
|
|
from urllib.request import urlopen |
|
|
from urllib.request import urlopen |
|
|
from urllib.parse import urlencode, urlparse |
|
|
from urllib.parse import urlencode, urlparse |
|
|
import subprocess |
|
|
import subprocess |
|
@ -63,8 +63,10 @@ def create_pad_on_first_run(name, ext): |
|
|
default_template = 'templates/default.md' |
|
|
default_template = 'templates/default.md' |
|
|
elif 'css' in ext: |
|
|
elif 'css' in ext: |
|
|
default_template = 'templates/default.css' |
|
|
default_template = 'templates/default.css' |
|
|
elif 'template' in ext: |
|
|
elif 'pandoc-template' in ext: |
|
|
default_template = 'templates/default.template.html' |
|
|
default_template = 'templates/default.pandoc-template.html' |
|
|
|
|
|
elif 'wildcard-template' in ext: |
|
|
|
|
|
default_template = 'templates/default.wildcard-template.html' |
|
|
default_template = open(default_template).read() |
|
|
default_template = open(default_template).read() |
|
|
|
|
|
|
|
|
# Create pad and add the default template |
|
|
# Create pad and add the default template |
|
@ -79,20 +81,22 @@ def create_pad_on_first_run(name, ext): |
|
|
def md_to_html(md_pad_content, name): |
|
|
def md_to_html(md_pad_content, name): |
|
|
# Convert Markdown to HTML, using the pandoc template from the NAME.template.html pad |
|
|
# Convert Markdown to HTML, using the pandoc template from the NAME.template.html pad |
|
|
# ---------------------------------------------------------------------------------- |
|
|
# ---------------------------------------------------------------------------------- |
|
|
app_hostname = get_app_hostname() |
|
|
#app_hostname = get_app_hostname() |
|
|
app_root = get_app_root() |
|
|
#app_root = get_app_root() |
|
|
template_url = f"{ app_hostname }{ app_root }/{ name }/template.html" |
|
|
#template_url = f"{ app_hostname }{ app_root }/{ name }/template.html" |
|
|
md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md" |
|
|
#template_url = "http://127.0.0.1:5555/octomode/techno/template.html" |
|
|
APP.logger.info("template_url", template_url) |
|
|
#md_url = f"{ app_hostname }{ app_root }/{ name }/pad.md" |
|
|
APP.logger.info("md_url", md_url) |
|
|
#md_url = "http://127.0.0.1:5555/octomode/techno/pad.md" |
|
|
result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) |
|
|
#APP.logger.info("template_url", template_url) |
|
|
html = result.stdout |
|
|
#APP.logger.info("md_url", md_url) |
|
|
APP.logger.info("html", html) |
|
|
#result = subprocess.run(["pandoc", "--from", "markdown", "--to", "html", "--template", f"{ template_url }", md_url], capture_output=True, text=True) |
|
|
APP.logger.info("result.stderr", result.stderr) |
|
|
#html = result.stdout |
|
|
|
|
|
#APP.logger.info("html", html) |
|
|
|
|
|
#APP.logger.info("result.stderr", result.stderr) |
|
|
|
|
|
|
|
|
# Convert Markdown to HTML, using the default pandoc template |
|
|
# Convert Markdown to HTML, using the default pandoc template |
|
|
# ---------------------------------------------------------------------------------- |
|
|
# ---------------------------------------------------------------------------------- |
|
|
# html = pypandoc.convert_text(md_pad_content, 'html', format='md') |
|
|
html = pypandoc.convert_text(md_pad_content, 'html', format='md') |
|
|
|
|
|
|
|
|
# Sanitize the Markdown |
|
|
# Sanitize the Markdown |
|
|
# html = bleach.clean(html) |
|
|
# html = bleach.clean(html) |
|
@ -145,7 +149,7 @@ def index(): |
|
|
if name: |
|
|
if name: |
|
|
# This is when the environment is "created" |
|
|
# This is when the environment is "created" |
|
|
# The pads are filled with the default templates (pad, stylesheet, template) |
|
|
# The pads are filled with the default templates (pad, stylesheet, template) |
|
|
exts = ['.md', '.css', '.template.html'] |
|
|
exts = ['.md', '.css', '.pandoc-template.html', '.wildcard-template.html'] |
|
|
for ext in exts: |
|
|
for ext in exts: |
|
|
create_pad_on_first_run(name, ext) |
|
|
create_pad_on_first_run(name, ext) |
|
|
return redirect(url_for("pad", name=name)) |
|
|
return redirect(url_for("pad", name=name)) |
|
@ -166,16 +170,16 @@ def stylesheet(name): |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.css" |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.css" |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/template/') |
|
|
@APP.route('/<name>/pandoc-template/') |
|
|
def template(name): |
|
|
def pandoctemplate(name): |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.template.html" |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.pandoc-template.html" |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/html/') |
|
|
@APP.route('/<name>/html/') |
|
|
def html(name): |
|
|
def html(name): |
|
|
app_root = get_app_root() |
|
|
app_root = get_app_root() |
|
|
url = f"{ app_root }/{ name }/preview.html" |
|
|
url = f"{ app_root }/{ name }/preview.html" |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('iframe.html', url=url, name=name.strip()) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/pdf/') |
|
|
@APP.route('/<name>/pdf/') |
|
|
def pdf(name): |
|
|
def pdf(name): |
|
@ -183,12 +187,17 @@ def pdf(name): |
|
|
url = f"{ app_root }/{name}/pagedjs.html" |
|
|
url = f"{ app_root }/{name}/pagedjs.html" |
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('pdf.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/podcast/') |
|
|
@APP.route('/<name>/wildcard-template/') |
|
|
def podcast(name): |
|
|
def wildcardtemplate(name): |
|
|
app_root = get_app_root() |
|
|
url = f"{ APP.config['PAD_URL'] }/{ name }.wildcard-template.html" |
|
|
url = f"{ app_root }/{name}/podcast.rss" |
|
|
|
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
return render_template('iframe.html', url=url, name=name.strip(), pad_url=APP.config['PAD_URL']) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/wildcard/') |
|
|
|
|
|
def wildcard(name): |
|
|
|
|
|
app_root = get_app_root() |
|
|
|
|
|
url = f"{ app_root }/{name}/wildcard.raw" |
|
|
|
|
|
return render_template('iframe.html', url=url, name=name.strip()) |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
|
# RENDERED RESOURCES |
|
|
# RENDERED RESOURCES |
|
|
# ////////////////// |
|
|
# ////////////////// |
|
@ -201,19 +210,21 @@ def css(name): |
|
|
|
|
|
|
|
|
return css, 200, {'Content-Type': 'text/css; charset=utf-8'} |
|
|
return css, 200, {'Content-Type': 'text/css; charset=utf-8'} |
|
|
|
|
|
|
|
|
@APP.route('/<name>/pad.md') |
|
|
# only used for the pandoc command using the subprocess |
|
|
def md(name): |
|
|
# --- |
|
|
# TO GENERATE THE CONTENT IN MARKDOWN |
|
|
#@APP.route('/<name>/pad.md') |
|
|
template_pad_content = get_pad_content(name, ext='.md') |
|
|
#def md(name): |
|
|
|
|
|
# # TO GENERATE THE CONTENT IN MARKDOWN |
|
|
return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} |
|
|
# template_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
# |
|
|
|
|
|
# return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} |
|
|
|
|
|
|
|
|
@APP.route('/<name>/template.html') |
|
|
@APP.route('/<name>/pandoc-template.html') |
|
|
def pandoctemplate(name): |
|
|
def pandoctemplatehtml(name): |
|
|
# TO GENERATE THE PANDOC TEMPLATE |
|
|
# TO GENERATE THE TEMPLATE AS HTML FILE |
|
|
template_pad_content = get_pad_content(name, ext='.template.html') |
|
|
template_pad_content = get_pad_content(name, ext='.pandoc-template.html') |
|
|
|
|
|
|
|
|
return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} |
|
|
return template_pad_content, 200, {'Content-Type': 'text/html; charset=utf-8'} |
|
|
|
|
|
|
|
|
@APP.route('/<name>/preview.html') |
|
|
@APP.route('/<name>/preview.html') |
|
|
def preview(name): |
|
|
def preview(name): |
|
@ -241,9 +252,20 @@ def pagedjs(name): |
|
|
|
|
|
|
|
|
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
return render_template('pagedjs.html', name=name.strip(), pad_content=html, lang=lang, title=title) |
|
|
|
|
|
|
|
|
|
|
|
@APP.route('/<name>/wildcard.raw') |
|
|
|
|
|
def wildcardpage(name): |
|
|
|
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
|
|
|
wildcard_template_pad_content = get_pad_content(name, ext='.wildcard-template.html') |
|
|
|
|
|
audio = [] |
|
|
|
|
|
for line in md_pad_content.splitlines(): |
|
|
|
|
|
# if any(ext in line for ext in [".mp3", ".ogg"]): |
|
|
|
|
|
if ".mp3" in line: |
|
|
|
|
|
audio.append(line) |
|
|
|
|
|
|
|
|
|
|
|
return render_template_string(wildcard_template_pad_content, name=name.strip(), audio=audio) |
|
|
|
|
|
|
|
|
@APP.route('/<name>/podcast.rss') |
|
|
@APP.route('/<name>/podcast.rss') |
|
|
def rss(name): |
|
|
def rss(name): |
|
|
# TO GENERATE THE PODCAST RSS FEED |
|
|
|
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
md_pad_content = get_pad_content(name, ext='.md') |
|
|
audio = [] |
|
|
audio = [] |
|
|
for line in md_pad_content.splitlines(): |
|
|
for line in md_pad_content.splitlines(): |
|
@ -251,7 +273,7 @@ def rss(name): |
|
|
if ".mp3" in line: |
|
|
if ".mp3" in line: |
|
|
audio.append(line) |
|
|
audio.append(line) |
|
|
|
|
|
|
|
|
return render_template('podcast.rss', name=name.strip(), rss=rss, audio=audio) |
|
|
return template_pad_content, 200, {'Content-Type': 'text/plain; charset=utf-8'} |
|
|
|
|
|
|
|
|
# ////////////////// |
|
|
# ////////////////// |
|
|
|
|
|
|
|
|