Skip to content

Commit

Permalink
feat: set html title element (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: fabianfgross <[email protected]>
  • Loading branch information
very-doge-wow and fabianfgross authored Jun 4, 2024
1 parent 24de2f2 commit 78ecd32
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
10 changes: 8 additions & 2 deletions EXAMPLE/prometheus-advanced.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>prometheus - helm chart documentation</title>
<style>
html {
--blue: #0288d1;
--dark-blue: #006da8;
--light-blue: #E0F2FF;
--margin-top: 3em;
}

body, html {
Expand Down Expand Up @@ -57,7 +59,7 @@
}
.content {
padding: 20px;
margin-top: 3em;
margin-top: var(--margin-top);
}
.container {
padding: 20px;
Expand Down Expand Up @@ -106,6 +108,10 @@
overflow: auto;
font-size: medium;
}

h1, h2, h3, h4, h5, h6 {
scroll-margin-top: var(--margin-top);
}
</style>
</head>
<body>
Expand Down
1 change: 1 addition & 0 deletions EXAMPLE/prometheus.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="utf-8" />
<meta name="generator" content="very-doge-wow/stella" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>prometheus - helm chart documentation</title>
<style type="text/css" media="screen">
body {
font-family: sans-serif;
Expand Down
31 changes: 20 additions & 11 deletions writer/doc_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def write(output: str, doc: dict, template: str, format_html: bool, advanced_htm
<meta charset="utf-8" />
<meta name="generator" content="very-doge-wow/stella" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>REPLACE_STRING_TITLE</title>
<style type="text/css" media="screen">
REPLACE_STRING_STYLE
</style>
Expand All @@ -110,6 +111,7 @@ def write(output: str, doc: dict, template: str, format_html: bool, advanced_htm
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>REPLACE_STRING_TITLE</title>
<style>
html {
--blue: #0288d1;
Expand Down Expand Up @@ -312,19 +314,26 @@ def write(output: str, doc: dict, template: str, format_html: bool, advanced_htm
</html>
"""

with (open(output, "w") as file):
with open(output, "w") as file:
if format_html:
logging.debug("converting md to html before write")
logging.debug("Converting Markdown to HTML")
title_str = f"{doc['name']} - helm chart documentation"
result = markdown.markdown(result, extensions=["tables"])
if format_html and not advanced_html:
if css != "":
logging.debug("adding custom css to html before write")
with open(css, "r") as style:
result = html_simple_template.replace("REPLACE_STRING_STYLE", style.read()).replace("REPLACE_STRING_BODY", result)
elif format_html:
logging.debug("converting md to html before write using advanced html")
result = html_advanced_template.replace("REPLACE_STRING_BODY", result)
# simply output the text (md or html, don't care)

if not advanced_html:
if css:
logging.debug("Adding custom CSS to HTML")
with open(css, "r") as style:
css_content = style.read()
result = html_simple_template.replace("REPLACE_STRING_STYLE", css_content).replace(
"REPLACE_STRING_BODY", result)
else:
logging.debug("Using advanced HTML template")
result = html_advanced_template.replace("REPLACE_STRING_BODY", result)

# title is replaced regardless of advanced or simple html
result = result.replace("REPLACE_STRING_TITLE", title_str)

file.write(result)

logging.info(f"Wrote doc to {output}.")
Expand Down
2 changes: 2 additions & 0 deletions writer/doc_writer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def test_writer_advanced_html():
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>unittest - helm chart documentation</title>
<style>
html {
--blue: #0288d1;
Expand Down Expand Up @@ -767,6 +768,7 @@ def test_writer_html_custom_css():
<meta charset="utf-8" />
<meta name="generator" content="very-doge-wow/stella" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>unittest - helm chart documentation</title>
<style type="text/css" media="screen">
tr {
border-top: 1px solid #ddd;
Expand Down

0 comments on commit 78ecd32

Please sign in to comment.