format with markdown if available
This commit is contained in:
@@ -14,6 +14,11 @@ from glob import fnmatch
|
||||
import base64
|
||||
import random
|
||||
from pprint import pprint
|
||||
try:
|
||||
import markdown
|
||||
MARKDOWN_AVAILABLE = True
|
||||
except ImportError:
|
||||
MARKDOWN_AVAILABLE = False
|
||||
|
||||
VERSION = "20211002"
|
||||
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"):
|
||||
return ""
|
||||
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(
|
||||
r"(https?:\/\/[\w\.,\-\@?^=%&:/~\+#]+)",
|
||||
'<a href="\\1">\\1</a>',
|
||||
@@ -802,17 +817,14 @@ function alternate(table) {
|
||||
css_style = """
|
||||
<style>
|
||||
/* Style modified from: https://css-tricks.com/snippets/php/display-styled-directory-contents/ */
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
body {
|
||||
color: #222;
|
||||
font: 14px monospace;
|
||||
padding: 0;
|
||||
background: #CCC;
|
||||
margin: 0;
|
||||
}
|
||||
h1 {
|
||||
.main_h1 {
|
||||
padding: 20px 0 12px 0;
|
||||
margin: 0 0 0 70px;
|
||||
font-family: sans-serif;
|
||||
@@ -829,12 +841,14 @@ function alternate(table) {
|
||||
border-top-left-radius: 70px;
|
||||
display: inline-block;
|
||||
min-width: calc(100% - 40px);
|
||||
padding: 0;
|
||||
}
|
||||
table {
|
||||
background-color: #F3F3F3;
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin: 15px 0;
|
||||
padding: 0;
|
||||
}
|
||||
th {
|
||||
background-color: #EB6000;
|
||||
@@ -895,6 +909,13 @@ function alternate(table) {
|
||||
.container pre {
|
||||
margin: 10px 10px 10px 10px;
|
||||
}
|
||||
.readme {
|
||||
padding: 0;
|
||||
margin: 5px;
|
||||
}
|
||||
.readme code {
|
||||
color: #0060EB;
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
header = (
|
||||
@@ -913,7 +934,7 @@ function alternate(table) {
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
"""
|
||||
).format(
|
||||
|
||||
Reference in New Issue
Block a user