From d181571cd0c03a9e6a6172c9816898ec0c8c06ba Mon Sep 17 00:00:00 2001 From: Kevin Sheppard Date: Sun, 1 Nov 2020 22:28:29 +0000 Subject: [PATCH] ENH: Gracefully handle case with no title Gracefully handle case with no title. --- docs/specimen.rst | 5 +++++ sphinx_material/__init__.py | 3 ++- sphinx_material/sphinx_material/layout.html | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/specimen.rst b/docs/specimen.rst index ee20a3a72..f6ecc8b80 100644 --- a/docs/specimen.rst +++ b/docs/specimen.rst @@ -390,3 +390,8 @@ Right Alignment :alt: Right Image, 60% scale :scale: 60% :align: right + + +Links +----- +This is a link to a page with no title: :ref:`No Title`. diff --git a/sphinx_material/__init__.py b/sphinx_material/__init__.py index 93a64f9f8..bd298e0dd 100644 --- a/sphinx_material/__init__.py +++ b/sphinx_material/__init__.py @@ -1,6 +1,7 @@ """Sphinx Material theme.""" import hashlib +import html import inspect import os import re @@ -301,4 +302,4 @@ def __new__(cls, *args, **kwargs): def get_html_context(): - return {"table_fix": TableFix, "derender_toc": DerenderToc} + return {"table_fix": TableFix, "derender_toc": DerenderToc, "unescape": html.unescape} diff --git a/sphinx_material/sphinx_material/layout.html b/sphinx_material/sphinx_material/layout.html index e86343c25..1a73d07d0 100644 --- a/sphinx_material/sphinx_material/layout.html +++ b/sphinx_material/sphinx_material/layout.html @@ -51,7 +51,14 @@ {% if theme_touch_icon %} {% endif %} - {{ super() }} + + {% if "no title" in title or not title.strip() %} + {% set ts = unescape(titlesuffix).strip()[1:].strip() %} + {{ ts|e }} + {% else %} + {{ title|striptags|e }}{{ titlesuffix }} + {% endif %} + {%- endblock %} {%- block extrahead %}