Skip to content

[ISSUE-18]Adds support for custom HTML template provision via command arguments or configuration#19

Open
NicStraussRW wants to merge 3 commits intojtackaberry:masterfrom
NicStraussRW:luadox/issues/18/add_support_for_custom_html_templates
Open

[ISSUE-18]Adds support for custom HTML template provision via command arguments or configuration#19
NicStraussRW wants to merge 3 commits intojtackaberry:masterfrom
NicStraussRW:luadox/issues/18/add_support_for_custom_html_templates

Conversation

@NicStraussRW
Copy link
Copy Markdown
Contributor

Refer to ISSUE-18

@jtackaberry Could you please review and consider this change for inclusion in main repo?

Comment thread luadox/render/html.py Outdated
Comment on lines +102 to +106

self._templates = {
'head': assets.get('head.tmpl.html').decode('utf8'),
'foot': assets.get('foot.tmpl.html').decode('utf8'),
'search': assets.get('search.tmpl.html').decode('utf8'),
'head': open(head_template, 'r', encoding='utf8').read() if head_template else assets.get('head.tmpl.html').decode('utf8'),
'foot': open(foot_template, 'r', encoding='utf8').read() if foot_template else assets.get('foot.tmpl.html').decode('utf8'),
'search': open(search_template, 'r', encoding='utf8').read() if search_template else assets.get('search.tmpl.html').decode('utf8'),
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't assume UTF-8 here when reading the user-provided templates. We can assume UTF-8 when they're a distributed asset since encoding is under our control, but when it's external and user-defined, it could be a different encoding.

Input encoding is configurable, so you can grab the config file for encoding per

encoding = config.get('project', 'encoding', fallback=locale.getpreferredencoding())

Comment thread luadox/main.py Outdated
help='Custom CSS file (html renderer)')
p.add_argument('--favicon', action='store', type=str, metavar='FILE',
help='Path to favicon file (html renderer)')
p.add_argument('--head_template', action='store', type=str, metavar='FILE',
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use underscores for command line flags, use dashes instead. So --head-template, --foot-template, and --search-template.

Comment thread luadox/render/html.py
css = self.config.get('project', 'css', fallback=None)
if css:
# The stylesheet is always copied to doc root, so take only the filename
_, css = os.path.split(css)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit slipped in from the other PR. Ideally PRs would be independent from one another, which requires a separate branch per PR on your fork. This allows PRs to be merged independent of one another. It's not a big deal in this one, because I already merged #17 so this will be ignored, but it's more of a problem for the other PRs.

@NicStraussRW
Copy link
Copy Markdown
Contributor Author

@jtackaberry, there is a new commit with review changes. Thanks!

P.S. I will wait for merge and rebase the next PR's as they only really make sense on top of this. Is that fine?

@NicStraussRW NicStraussRW requested a review from jtackaberry March 5, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants