click_extra.sphinx.opengraph moduleΒΆ

Keep the space a title icon leaves out of the og:title of a page.

A page title that opens on an icon, like # {octicon}`flame` Recipes with sphinx-design, renders as the SVG of the icon, a space, and the text. sphinxext-opengraph sets og:title to the text of that title without stripping it, so the social card of the page reads " Recipes" (sphinx-doc/sphinxext-opengraph#150). This module removes the space from the page title just before sphinxext-opengraph reads it, and puts the title back just after, so the theme renders the title it always did.

Todo

Delete this module once sphinx-doc/sphinxext-opengraph#150 ships in a sphinxext-opengraph release.

click_extra.sphinx.opengraph.OPENGRAPH_EXTENSION = 'sphinxext.opengraph'ΒΆ

Module name of the extension whose og:title this module fixes.

click_extra.sphinx.opengraph.TITLE_ICON_GAP = re.compile('^(\\s*<svg\\b.*?</svg>)\\s+', re.DOTALL)ΒΆ

A leading SVG icon of a page title, and the space that follows it.

click_extra.sphinx.opengraph.TITLE_STASH_KEY = 'click_extra_title_with_icon_gap'ΒΆ

Page context key holding the title as Sphinx rendered it, until it goes back.

click_extra.sphinx.opengraph.strip_title_icon_gap(app, pagename, templatename, context, doctree)[source]ΒΆ

Drop the space after a leading icon of the page title, for the extension.

Connected to html-page-context at priority 400, ahead of the default 500 sphinxext-opengraph reads the title at. Inert without sphinxext-opengraph, and on a title that opens on no icon.

Return type:

None

click_extra.sphinx.opengraph.restore_title(app, pagename, templatename, context, doctree)[source]ΒΆ

Put back the title strip_title_icon_gap() changed.

Connected to html-page-context at priority 600, after sphinxext-opengraph has read the title, so the templates of the theme get it unchanged.

Return type:

None

click_extra.sphinx.opengraph.setup(app)[source]ΒΆ

Register the two title hooks on app.

Called from click_extra.sphinx.setup() so projects only need to list "click_extra.sphinx" in their extensions.

Return type:

None