Skip to content

Commit

Permalink
Allow to have a custom HTML <head> content using a 'head.html' file
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Wolneykien <[email protected]>
  • Loading branch information
wolneykien committed Apr 21, 2022
1 parent c992e0e commit 48af954
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions quizgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def add_dom_to_template(dom, html_file_name, quiz):
# Add the header. By replacing this early, we allow the header to
# contain IMG and LINK tags (or even CODE), though it would typically
# be pure HTML
content = content.replace('[STYLES_SCRIPTS]', get_head());
content = content.replace('[SUBMIT_LABEL]', _('Submit'))
content = content.replace('[HIDE_LABEL]', _('Hide'))
content = content.replace('[HEADER]', get_header())
Expand Down Expand Up @@ -549,6 +550,17 @@ def get_header():
else:
header = header_file.read()
return header

# Should a HTML head file exist return the content of that file
# otherwise return the STYLES_SCRIPTS
def get_head():
try:
header_file = open('head.html')
except IOError:
header = STYLES_SCRIPTS
else:
header = header_file.read()
return header

# Should a footer file exist return the content of that file
# otherwise return the standard footer
Expand Down Expand Up @@ -654,24 +666,8 @@ def main():
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>[TITLE]</title>
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans|Alike' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="quiz.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
[STYLES_SCRIPTS]
<script type="text/javascript">
const SUBMIT_LABEL = '[SUBMIT_LABEL]';
const HIDE_LABEL = '[HIDE_LABEL]';
Expand Down Expand Up @@ -982,6 +978,23 @@ def main():
}
"""

STYLES_SCRIPTS = r"""<meta charset="UTF-8" />
<link href='https://fonts.googleapis.com/css?family=Josefin+Sans|Alike' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="quiz.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.2/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
"""

if __name__ == '__main__':
main()
Expand Down

0 comments on commit 48af954

Please sign in to comment.