Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions yardang/conf.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from pathlib import Path
from packaging.version import Version

from yardang.markdown import copy_relative_html_assets, rebase_relative_references
from yardang.utils import HtmlTitle

########################
# COMMON CONFIGURATION #
Expand All @@ -34,9 +35,12 @@ copyright = """{{copyright}}"""
title = """{{title}}"""
version = "{{version}}"
release = "{{version}}"
# Sphinx reuses this as the <title> tag, so it has to stay plain text; markup
# here shows up escaped in browser tabs and search results.
# Sphinx type-checks this as a plain str, so the styled form goes into the page
# context instead (see run_title_fallback).
html_title = """{{title}} v{{version}}"""
styled_html_title = HtmlTitle(
"""{{title}} <code style='font-size: var(--font-size--small--4);color: var(--sd-color-primary);'>v{{version}}</code>"""
)
docs_host_root = "{{docs_root}}"
root = "{{root}}"
cname = "{{ cname or '' }}"
Expand Down Expand Up @@ -425,6 +429,10 @@ def run_title_fallback(app, pagename, templatename, context, doctree):
# root page reading "<no title>".
if context.get("title") in (None, "", "&lt;no title&gt;", "<no title>"):
context["title"] = title
# furo's search page is the one template that drops docstitle into <title>
# unfiltered, so it keeps the plain form.
if pagename != "search":
context["docstitle"] = styled_html_title


def setup(app):
Expand Down
14 changes: 13 additions & 1 deletion yardang/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import os
import re
from pathlib import Path

import toml

__all__ = ("get_config", "get_config_flex")
__all__ = ("HtmlTitle", "get_config", "get_config_flex")


class HtmlTitle(str):
"""A title carrying markup that degrades to plain text for the ``<title>`` tag.

Themes render ``docstitle`` into the header verbatim but escape it for the
browser tab; ``__html__`` is what the ``|e`` and ``|striptags`` filters pick up.
"""

def __html__(self):
return re.sub(r"<[^>]+>", "", self)


def get_pyproject_toml():
Expand Down