Merge pull request #96 from 2m/fix/inner-html-2m

Add inner_html tag attribute (rebase)
This commit is contained in:
Leonardo Cavaletti 2022-04-03 17:54:28 +01:00 committed by GitHub
commit ab3ec1a491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 11 deletions

View File

@ -162,6 +162,13 @@ theme = "dark"
type="text/javascript"
src="/example/custom-script.js"
# the following injects this script in the <head>:
# <script>console.log("Hello, world!")</script>
[[site.inject.body.script]]
inner_html="""
console.log("Hello, world!")
"""
## Individual Page Settings ##
# the [pages] table defines override settings for individual pages, by defining
# a sub-table named after the page url (or part of the url, but careful about

View File

@ -625,6 +625,12 @@ class Parser:
for element in elements:
injected_tag = soup.new_tag(tag)
for attr, value in element.items():
# `inner_html` refers to the tag's inner content
# and will be added later
if attr == "inner_html":
continue
injected_tag[attr] = value
# if the value refers to a file, copy it to the dist folder
if attr.lower() in ["href", "src"]:
@ -636,6 +642,11 @@ class Parser:
# shutil.copyfile(source, destination)
injected_tag[attr] = str(cached_custom_file) # source.name
log.debug(f"Injecting <{section}> tag: {injected_tag}")
# adding `inner_html` as the tag's content
if "inner_html" in element:
injected_tag.string = element["inner_html"]
soup.find(section).append(injected_tag)
def inject_loconotion_script_and_css(self, soup):