oh my god
This commit is contained in:
parent
8c1bbc8179
commit
e6e9bfcba8
15 changed files with 49 additions and 42 deletions
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
from html import escape
|
||||
from typing import Any
|
||||
|
||||
from jinja2 import nodes
|
||||
|
@ -26,8 +28,13 @@ class IncludeRawExtension(Extension):
|
|||
return Markup(source[0])
|
||||
|
||||
|
||||
_BETWEEN_TAGS_RE = re.compile(r"<br />\s+<")
|
||||
|
||||
|
||||
def hexdoc_minify(value: str) -> str:
|
||||
return "".join(line.strip() for line in value.splitlines())
|
||||
merged_lines = "".join(line.strip() for line in value.splitlines())
|
||||
return _BETWEEN_TAGS_RE.sub("<br /><", merged_lines)
|
||||
|
||||
# return minify_html.minify(
|
||||
# code=value,
|
||||
# keep_closing_tags=True,
|
||||
|
@ -42,7 +49,7 @@ def hexdoc_block(value: Any, allow_none: bool = False) -> str:
|
|||
case LocalizedStr() | str():
|
||||
# use Markup to tell Jinja not to escape this string for us
|
||||
lines = str(value).splitlines()
|
||||
return Markup("<br />".join(Markup.escape(line) for line in lines))
|
||||
return Markup("<br />".join(escape(line) for line in lines))
|
||||
case FormatTree():
|
||||
with HTMLStream() as out:
|
||||
with value.style.element(out):
|
||||
|
@ -61,4 +68,4 @@ def hexdoc_wrap(value: str, *args: str):
|
|||
attributes = " " + " ".join(attributes)
|
||||
else:
|
||||
attributes = ""
|
||||
return f"<{tag}{attributes}>{value}</{tag}>"
|
||||
return Markup(f"<{tag}{attributes}>{escape(str(value))}</{tag}>")
|
||||
|
|
|
@ -46,7 +46,7 @@ def main(args: Args) -> None:
|
|||
undefined=StrictUndefined,
|
||||
lstrip_blocks=True,
|
||||
trim_blocks=True,
|
||||
autoescape=False,
|
||||
autoescape=True,
|
||||
extensions=[IncludeRawExtension],
|
||||
)
|
||||
env.filters |= dict( # for some reason, pylance doesn't like the {} here
|
||||
|
|
8
doc/templates/book.html.jinja
vendored
8
doc/templates/book.html.jinja
vendored
|
@ -1,7 +1,7 @@
|
|||
<div class="container">
|
||||
<div class='container'>
|
||||
{% if show_landing_text %}
|
||||
<header class="jumbotron">
|
||||
<h1 class="book-title">
|
||||
<header class='jumbotron'>
|
||||
<h1 class='book-title'>
|
||||
{{ book.name }}
|
||||
</h1>
|
||||
{{ book.landing_text|hexdoc_block }}
|
||||
|
@ -10,7 +10,7 @@
|
|||
<nav>
|
||||
{% include "tableofcontents.html.jinja" %}
|
||||
</nav>
|
||||
<main class="book-body">
|
||||
<main class='book-body'>
|
||||
{% for category in book.categories.values() %}
|
||||
{% include "category.html.jinja" -%}
|
||||
{% endfor -%}
|
||||
|
|
2
doc/templates/category.html.jinja
vendored
2
doc/templates/category.html.jinja
vendored
|
@ -1,6 +1,6 @@
|
|||
{% import "macros.html.jinja" as macros -%}
|
||||
|
||||
<section id="{{ category.id.path }}">
|
||||
<section id='{{ category.id.path }}'>
|
||||
{% call macros.maybe_spoilered(category) %}
|
||||
{{ macros.section_header(category, "h2", "category-title") }}
|
||||
{{ category.description|hexdoc_block }}
|
||||
|
|
2
doc/templates/entry.html.jinja
vendored
2
doc/templates/entry.html.jinja
vendored
|
@ -1,6 +1,6 @@
|
|||
{% import "macros.html.jinja" as macros -%}
|
||||
|
||||
<div id="{{ entry.id.path }}">
|
||||
<div id='{{ entry.id.path }}'>
|
||||
{% call macros.maybe_spoilered(entry) %}
|
||||
{{ macros.section_header(entry, "h3", "entry-title") }}
|
||||
{% for page in entry.pages %}
|
||||
|
|
22
doc/templates/macros.html.jinja
vendored
22
doc/templates/macros.html.jinja
vendored
|
@ -1,18 +1,18 @@
|
|||
{% macro permalink(href) %}
|
||||
<a href="#{{ href }}" class="permalink small" title="Permalink">
|
||||
<i class="bi bi-link-45deg"></i>
|
||||
<a href='#{{ href }}' class='permalink small' title='Permalink'>
|
||||
<i class='bi bi-link-45deg'></i>
|
||||
</a>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro maybe_spoilered_link(value) %}
|
||||
<a href="#{{ value.id.path }}" class="{{ 'spoilered' if value.is_spoiler else '' }}">
|
||||
{{- value.name -}}
|
||||
<a href='#{{ value.id.path }}' class='{{ "spoilered" if value.is_spoiler else "" }}'>
|
||||
{{- value.name|hexdoc_block -}}
|
||||
</a>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro maybe_spoilered(value) %}
|
||||
{% if value.is_spoiler %}
|
||||
<div class="spoilered">
|
||||
<div class='spoilered'>
|
||||
{{ caller() }}
|
||||
</div>
|
||||
{% else %}
|
||||
|
@ -21,13 +21,13 @@
|
|||
{%- endmacro %}
|
||||
|
||||
{% macro jump_to_top() %}
|
||||
<a href="#table-of-contents" class="permalink small" title="Jump to top">
|
||||
<i class="bi bi-box-arrow-up"></i>
|
||||
<a href='#table-of-contents' class='permalink small' title='Jump to top'>
|
||||
<i class='bi bi-box-arrow-up'></i>
|
||||
</a>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro section_header(value, header_tag, class_name) %}
|
||||
<{{ header_tag }} class="{{ class_name }} page-header">
|
||||
<{{ header_tag }} class='{{ class_name }} page-header'>
|
||||
{{ value.name|hexdoc_block }}
|
||||
{{ jump_to_top() }}
|
||||
{{ permalink(value.id.path) }}
|
||||
|
@ -35,11 +35,11 @@
|
|||
{%- endmacro %}
|
||||
|
||||
{% macro recipe_block(recipes, result_attribute, description, separator) %}
|
||||
<blockquote class="crafting-info">
|
||||
<blockquote class='crafting-info'>
|
||||
Depicted in the book: {{ description }} {{
|
||||
recipes
|
||||
|map(attribute="result." ~ result_attribute)
|
||||
|map("hexdoc_wrap", "code")
|
||||
|map(attribute='result.' ~ result_attribute)
|
||||
|map('hexdoc_wrap', 'code')
|
||||
|join(separator)
|
||||
}}.
|
||||
</blockquote>
|
||||
|
|
5
doc/templates/main.html.jinja
vendored
5
doc/templates/main.html.jinja
vendored
|
@ -127,8 +127,8 @@
|
|||
<script>
|
||||
{# TODO: kinda hacky #}
|
||||
{% filter indent(6) %}
|
||||
{% include_raw "main.js" %}
|
||||
{% endfilter %}
|
||||
{%+ include_raw "main.js" %}
|
||||
{% endfilter +%}
|
||||
|
||||
</script>
|
||||
|
||||
|
@ -153,3 +153,4 @@
|
|||
{% endfilter +%}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
4
doc/templates/pages/ImagePage.html.jinja
vendored
4
doc/templates/pages/ImagePage.html.jinja
vendored
|
@ -1,9 +1,9 @@
|
|||
{% extends "pages/PageWithTitle.html.jinja" %}
|
||||
|
||||
{% block inner_body %}
|
||||
<p class="img-wrapper">
|
||||
<p class='img-wrapper'>
|
||||
{% for image in page.images %}
|
||||
<img src="{{ props.asset_url(image) }}"></img>
|
||||
<img src='{{ props.asset_url(image) }}'></img>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{{ super() }}
|
||||
|
|
4
doc/templates/pages/LinkPage.html.jinja
vendored
4
doc/templates/pages/LinkPage.html.jinja
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
{% block inner_body %}
|
||||
{{ super() }}
|
||||
<h4 class="linkout">
|
||||
<a href="{{ page.url }}">{{ page.link_text }}</a>
|
||||
<h4 class='linkout'>
|
||||
<a href='{{ page.url|hexdoc_block }}'>{{ page.link_text }}</a>
|
||||
</h4>
|
||||
{% endblock inner_body %}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{% extends "pages/PageWithPattern.html.jinja" %}
|
||||
|
||||
{% block title_attrs %} class="pattern-title"{% endblock %}
|
||||
{% block title_attrs %} class='pattern-title'{% endblock %}
|
||||
|
|
6
doc/templates/pages/Page.html.jinja
vendored
6
doc/templates/pages/Page.html.jinja
vendored
|
@ -1,8 +1,8 @@
|
|||
{% if page.anchor %}
|
||||
{# set a variable so children can use this value #}
|
||||
{% set page_anchor_id = entry.id.path ~ '@' ~ page.anchor %}
|
||||
<div id="{{ page_anchor_id }}">
|
||||
{# not required because EmptyPage uses this template directly #}
|
||||
{% set page_anchor_id = entry.id.path ~ "@" ~ page.anchor %}
|
||||
<div id='{{ page_anchor_id }}'>
|
||||
{# body isn' required because EmptyPage uses this template directly #}
|
||||
{% block body scoped %}{% endblock %}
|
||||
</div>
|
||||
{% else %}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{% extends "pages/PageWithTitle.html.jinja" %}
|
||||
|
||||
{% block inner_body %}
|
||||
<details class="spell-collapsible">
|
||||
<summary class="collapse-spell"></summary>
|
||||
<details class='spell-collapsible'>
|
||||
<summary class='collapse-spell'></summary>
|
||||
{% for pattern in page.patterns %}
|
||||
<canvas class="spell-viz" width=216 height=216 data-string="{{ pattern.signature }}" data-start="{{ pattern.startdir.name.lower() }}" data-per-world="{{ pattern.is_per_world }}">
|
||||
<canvas class='spell-viz' width='216' height='216' data-string='{{ pattern.signature }}' data-start='{{ pattern.startdir.name.lower() }}' data-per-world='{{ pattern.is_per_world }}'>
|
||||
Your browser does not support visualizing patterns. Pattern code: {{ pattern.signature }}
|
||||
</canvas>
|
||||
{% endfor %}
|
||||
|
|
5
doc/templates/pages/PageWithTitle.html.jinja
vendored
5
doc/templates/pages/PageWithTitle.html.jinja
vendored
|
@ -5,9 +5,8 @@
|
|||
{% if page.title is not none %}
|
||||
{# we need title_attrs for PageWithPattern #}
|
||||
<h4{% block title_attrs %}{% endblock %}>
|
||||
{{ page.title }}
|
||||
{# page_anchor_id is conditionally defined in Page #}
|
||||
{% if page_anchor_id is defined %}
|
||||
{{ page.title|hexdoc_block }}
|
||||
{% if page_anchor_id is defined %} {# note: page_anchor_id is conditionally defined in Page #}
|
||||
{{ macros.permalink(page_anchor_id) }}
|
||||
{% endif %}
|
||||
</h4>
|
||||
|
|
2
doc/templates/pages/SpotlightPage.html.jinja
vendored
2
doc/templates/pages/SpotlightPage.html.jinja
vendored
|
@ -1,7 +1,7 @@
|
|||
{% extends "pages/PageWithTitle.html.jinja" %}
|
||||
|
||||
{% block inner_body %}
|
||||
<h4 class="spotlight-title page-header">
|
||||
<h4 class='spotlight-title page-header'>
|
||||
{{ page.item }}
|
||||
</h4>
|
||||
{{ super() }}
|
||||
|
|
8
doc/templates/tableofcontents.html.jinja
vendored
8
doc/templates/tableofcontents.html.jinja
vendored
|
@ -1,13 +1,13 @@
|
|||
{% import "macros.html.jinja" as macros %}
|
||||
<h2 id="table-of-contents" class="page-header">
|
||||
<h2 id='table-of-contents' class='page-header'>
|
||||
Table of Contents
|
||||
<a href="javascript:void(0)" class="permalink toggle-link small" data-target="toc-category" title="Toggle all">
|
||||
<i class="bi bi-list-nested"></i>
|
||||
<a href='javascript:void(0)' class='permalink toggle-link small' data-target='toc-category' title='Toggle all'>
|
||||
<i class='bi bi-list-nested'></i>
|
||||
</a>
|
||||
{{ macros.permalink("table-of-contents") }}
|
||||
</h2>
|
||||
{% for category in book.categories.values() %}
|
||||
<details class="toc-category">
|
||||
<details class='toc-category'>
|
||||
<summary>
|
||||
{{ macros.maybe_spoilered_link(category) }}
|
||||
</summary>
|
||||
|
|
Loading…
Reference in a new issue