format with markdown if available
This commit is contained in:
@@ -14,6 +14,11 @@ from glob import fnmatch
|
|||||||
import base64
|
import base64
|
||||||
import random
|
import random
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
try:
|
||||||
|
import markdown
|
||||||
|
MARKDOWN_AVAILABLE = True
|
||||||
|
except ImportError:
|
||||||
|
MARKDOWN_AVAILABLE = False
|
||||||
|
|
||||||
VERSION = "20211002"
|
VERSION = "20211002"
|
||||||
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
||||||
@@ -461,7 +466,17 @@ def get_readme(path, no_read):
|
|||||||
if not os.path.exists("README.md"):
|
if not os.path.exists("README.md"):
|
||||||
return ""
|
return ""
|
||||||
with open("README.md", "rt") as fp:
|
with open("README.md", "rt") as fp:
|
||||||
return "<h2>README.md</h2><pre>{}</pre>".format(
|
if MARKDOWN_AVAILABLE:
|
||||||
|
return "<div class=readme>{}</div>".format(
|
||||||
|
markdown.markdown(
|
||||||
|
fp.read().strip(),
|
||||||
|
extensions=['extra']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
sys.stderr.write("import markdown failed, using simple regex\n")
|
||||||
|
return "<div class=readme><pre>{}</pre></div>".format(
|
||||||
re.sub(
|
re.sub(
|
||||||
r"(https?:\/\/[\w\.,\-\@?^=%&:/~\+#]+)",
|
r"(https?:\/\/[\w\.,\-\@?^=%&:/~\+#]+)",
|
||||||
'<a href="\\1">\\1</a>',
|
'<a href="\\1">\\1</a>',
|
||||||
@@ -802,17 +817,14 @@ function alternate(table) {
|
|||||||
css_style = """
|
css_style = """
|
||||||
<style>
|
<style>
|
||||||
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
||||||
* {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
body {
|
body {
|
||||||
color: #222;
|
color: #222;
|
||||||
font: 14px monospace;
|
font: 14px monospace;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background: #CCC;
|
background: #CCC;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
h1 {
|
.main_h1 {
|
||||||
padding: 20px 0 12px 0;
|
padding: 20px 0 12px 0;
|
||||||
margin: 0 0 0 70px;
|
margin: 0 0 0 70px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
@@ -829,12 +841,14 @@ function alternate(table) {
|
|||||||
border-top-left-radius: 70px;
|
border-top-left-radius: 70px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: calc(100% - 40px);
|
min-width: calc(100% - 40px);
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
table {
|
table {
|
||||||
background-color: #F3F3F3;
|
background-color: #F3F3F3;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 15px 0;
|
margin: 15px 0;
|
||||||
|
padding: 0;
|
||||||
}
|
}
|
||||||
th {
|
th {
|
||||||
background-color: #EB6000;
|
background-color: #EB6000;
|
||||||
@@ -895,6 +909,13 @@ function alternate(table) {
|
|||||||
.container pre {
|
.container pre {
|
||||||
margin: 10px 10px 10px 10px;
|
margin: 10px 10px 10px 10px;
|
||||||
}
|
}
|
||||||
|
.readme {
|
||||||
|
padding: 0;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
.readme code {
|
||||||
|
color: #0060EB;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
"""
|
"""
|
||||||
header = (
|
header = (
|
||||||
@@ -913,7 +934,7 @@ function alternate(table) {
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>{title}</h1>
|
<h1 class="main_h1">{title}</h1>
|
||||||
<table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody>
|
<table class="sortable" id="fileList"><thead><tr><th>Name</th><th class="right">Size</th><th class="right">Size B</th><th class="right">Modified</th></tr></thead><tbody>
|
||||||
"""
|
"""
|
||||||
).format(
|
).format(
|
||||||
|
|||||||
Reference in New Issue
Block a user