How to set configuration values in Sphinx theme or extension build event? - python-sphinx

I am building a Sphinx theme that sub-classes another theme, and sets several default configuration values in Sphinx (for example, a subset of values of html_theme_options).
I have tried writing a callback event function to read app.config and set a variable if it does not exist, like this:
def setup(app):
app.config.html_theme_options["option"] = "value"
However, "value" does not seem to propagate to other stages in the Sphinx build process. If I inspect app.config.html_theme_options, I once again have the original default value before I reset it in my theme.
I have tried the same pattern in the config-inited and builder-inited build events, but it doesn't seem to work in either case. Does anybody know how to over-ride Sphinx defaults via your own theme or extension?

Related

Add a warning directive at the top of every page on a Sphinx RTD site

I'd like to add a simple warning directive at the top of every page on a Sphinx RTD site:
.. attention::
The next major release of this project will launch on X date.
In the meantime, we're looking for feedback.
If you'd like an early preview, please reach out at someemail#someaddress.com!
What's the simplest way to do this? I'm using the sphinx_rtd_theme.
I can see how to add a block using the extrabody block, but it appears outside the main content area and is positioned and styled totally independently.
Ideally, I'd want this block to show up at an attention directive just below the breadcrumbs on every page.
You could add this to the conf.py Sphinx configuration file:
rst_prolog = """.. attention::
The next major release is imminent.
"""
and it will be included at the beginning of every source file that is read ‒ see https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-rst_prolog.
F-string literals work too, so f'This is release #{release}' will substitute that variable value.

Rinohtype frontend for Sphinx: How to manipulate the PDF subtitle, which is 'Release' by default

I'm generating PDFs via the rinohtype extension of Sphinx (i.e. not via the LaTex extension!).
For the two bundled rinohtype templates 'book' and 'article', where the latter is the one I use, the subtitle of the title page always starts with 'Release' by default (and a release version string if one is provided in conf.py via release = '1.0' - this is commented out in my case).
I want to:
1a) either get rid of the complete subtitle, i.e. also 'Release' isn't printed on the PDF title page, or
1b) want to change 'Release' to some other String, 'Rev.' in my case;
2) also have the modification of 1a) and/or 1b) applied to the page headers after "front matter", where 'Release' is also the default string.
What I found so far is:
Here it is described for LaTex, how to hide 'Release' (the subtitle) on the front page. However, this doesnt work for rinohtype. No real surprise, but I gave it a try because rinohtype also interprets some latex settings...
How do I get rid of the "Release 1" in the Page Header of the Sphinx Latex Output?
I also digged into rinohtype stylesheets and I found a way to hide elements of the title page. The linked stylesheet example shows how to hide the date entry on the title page. However, I'm not sure if this is actually the easiest solution (i.e. changing/extending the stylesheet) and this does also not hide the 'Release' String in the following page headers - see my Question 2) above.
https://github.com/brechtm/rinohtype/blob/40a63c4e5ad7550f62b6860f1812cb67cafb9dc7/tests_regression/sphinx_minimal.rts
rinohtype currently does not support changing "Release" into something else at the moment. This might be added in the near future however; see issue #157. This should also affect the page headers/footers.
You can hide the Release subtitle by means of a style sheet, like you discovered. It is also possible to remove it from the page header by supplying a custom template configuration. You'll need to override the header text for the contents and back matter page templates:
[contents_right_page]
header_text = '\t\t{DOCUMENT_TITLE}'
[contents_left_page]
header_text = '{DOCUMENT_TITLE}'
[back_matter_right_page]
header_text = '\t\t{DOCUMENT_TITLE}'
[back_matter_left_page]
header_text = '{DOCUMENT_TITLE}'

Augmenting config.allowedContent instead of overriding default value

The section entitled Advanced Content Filter guide in the CKEditor docs talks about how to set values for config.allowedContent. The documentation states that you can override the default value. No mention is made of how to obtain the default value and augment it.
For example, I want to allow script tags in addition to the default tags supported, as enhanced by any installed plugins. If I inspect config.allowedContent in the browser in the area where I set CKEditor config properties, I see that allowedContent is undefined. That tells m the default behavior is triggered by the value undefined, which is unfortunate.
How can this be done? I can think of the following approaches:
1) Somehow list the value of allowedContent on the console after initialization is complete. Not sure how to do that. Hard-code that value, plus script in the config section of my code. This is not the way I'd like to go forward.
2) Write a little plugin that merely adds script to allowedContent. Not sure what that would look like. This is a viable way forward.
3) Any other ideas?
I suppose that editor.config.extraAllowedContent is a remedy to your problem.
Note that CKEditor secures all <script> tags in your contents so included JavaScript is not executed (avoiding XSS). Anyway, for debugging purposes, allowedContent rules are stored in editor.filter.allowedContent during editor's lifetime.

List of default themeid values

I would like to change some default parameters using a theme. For instance the collapse/expande image. I could ofcourse change the themeid for every categorized column but it would be best to set these values as default in the theme.
I came acros a post about a list of default themeid's but ofcourse this link is dead. Is there any other way of finding out the default theme id for xpage components?
Here's a list of theme ids for core controls:
http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_themes#themeID+values+for+core+controls
You can use the following code snippet to find the theme id of a control:
getComponent("dynamicViewPanel1").getStyleKitFamily()

JasperReports - Conditional style per locale?

Is there a way to use a different styles, or redefine a style, based on a report parameter locale? I need to modify font sizes for certain languages.
I have implemented this in the past using external style templates. There is a sample on jasperforge that illustrates how to do this.
Once you've moved your styles to external templates, you can create locale specific templates. The templating mechanism allows you to inherit from and override specific styles, so the locale specific versions don't get overly bloated. The example I linked above includes inheriting from and overriding base styles.
In your reports, you can then load the appropriate template at render time.
One easy way to do this is:
provide the path to the template that you want to use as a parameter
to the report
include a template tag in the jrxml file that references the
parameter:
<template><![CDATA[$P{TEMPLATE_PATH}]]></template>
Then, in the code that renders the report, just set the TEMPLATE_PATH parameter appropriately for the report locale.
Again, the linked documentation mentions how to do this.

Resources