From 5f6503c905e67c12b6050e1f49682feab0389126 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Sat, 6 Jun 2015 13:12:56 -0700 Subject: [PATCH] Add suffix to HTML context. Fixes #1873 --- doc/templating.rst | 5 +++++ sphinx/builders/html.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/doc/templating.rst b/doc/templating.rst index 19ed14840ec..5286e0312e5 100644 --- a/doc/templating.rst +++ b/doc/templating.rst @@ -399,3 +399,8 @@ are in HTML form), these variables are also available: * ``includehidden`` (``False`` by default): if true, the TOC tree will also contain hidden entries. + +.. data:: page_source_suffix + + The suffix of the file that was rendered. Since we support a list of :confval:`source_suffix`, + this will allow you to properly link to the original source file. diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 431ac4091d2..885e3d127b9 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -408,6 +408,9 @@ def get_doc_context(self, docname, body, metatags): # metadata for the document meta = self.env.metadata.get(docname) + # Suffix for the document + source_suffix = '.' + self.env.doc2path(docname).split('.')[-1] + # local TOC and global TOC tree self_toc = self.env.get_toc_for(docname, self) toc = self.render_partial(self_toc)['fragment'] @@ -425,6 +428,7 @@ def get_doc_context(self, docname, body, metatags): toc = toc, # only display a TOC if there's more than one item to show display_toc = (self.env.toc_num_entries[docname] > 1), + page_source_suffix = source_suffix, ) def write_doc(self, docname, doctree):