diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | doc/config.rst | 8 | ||||
-rw-r--r-- | sphinx/builders/epub3.py | 1 | ||||
-rw-r--r-- | tests/test_build_epub.py | 28 |
4 files changed, 39 insertions, 1 deletions
@@ -59,7 +59,8 @@ Features added * LaTeX: new key ``'fvset'`` for :confval:`latex_elements`. For XeLaTeX/LuaLaTeX its default sets ``fanvyvrb`` to use normal, not small, fontsize in code-blocks (refs: #4793) -* Add :confval:`html_css_files` for adding CSS files from configuration +* Add :confval:`html_css_files` and :confval:`epub_css_files` for adding CSS + files from configuration Bugs fixed ---------- diff --git a/doc/config.rst b/doc/config.rst index 97e43e645..46958cde6 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1524,6 +1524,14 @@ the `Dublin Core metadata <http://dublincore.org/>`_. .. versionadded:: 1.1 +.. confval:: epub_css_files + + A list of CSS files. The entry must be a *filename* string or a tuple + containing the *filename* string and the *attributes* dictionary. For more + information, see :confval:`html_css_files`. + + .. versionadded:: 1.8 + .. confval:: epub_guide Meta data for the guide element of :file:`content.opf`. This is a diff --git a/sphinx/builders/epub3.py b/sphinx/builders/epub3.py index 752a3990d..895d2f5f5 100644 --- a/sphinx/builders/epub3.py +++ b/sphinx/builders/epub3.py @@ -247,6 +247,7 @@ def setup(app): app.add_config_value('epub_guide', (), 'env') app.add_config_value('epub_pre_files', [], 'env') app.add_config_value('epub_post_files', [], 'env') + app.add_config_value('epub_css_files', lambda config: config.html_css_files, 'epub') app.add_config_value('epub_exclude_files', [], 'env') app.add_config_value('epub_tocdepth', 3, 'env') app.add_config_value('epub_tocdup', True, 'env') diff --git a/tests/test_build_epub.py b/tests/test_build_epub.py index 2f09f6d5a..24450089b 100644 --- a/tests/test_build_epub.py +++ b/tests/test_build_epub.py @@ -317,6 +317,34 @@ def test_epub_writing_mode(app): assert 'writing-mode: vertical-rl;' in css +@pytest.mark.sphinx('epub', testroot='html_assets') +def test_epub_assets(app): + app.builder.build_all() + + # epub_sytlesheets (same as html_css_files) + content = (app.outdir / 'index.xhtml').text() + assert ('<link rel="stylesheet" type="text/css" href="_static/css/style.css" />' + in content) + assert ('<link media="print" rel="stylesheet" title="title" type="text/css" ' + 'href="https://example.com/custom.css" />' in content) + + +@pytest.mark.sphinx('epub', testroot='html_assets', + confoverrides={'epub_css_files': ['css/epub.css']}) +def test_epub_css_files(app): + app.builder.build_all() + + # epub_css_files + content = (app.outdir / 'index.xhtml').text() + assert '<link rel="stylesheet" type="text/css" href="_static/css/epub.css" />' in content + + # files in html_css_files are not outputed + assert ('<link rel="stylesheet" type="text/css" href="_static/css/style.css" />' + not in content) + assert ('<link media="print" rel="stylesheet" title="title" type="text/css" ' + 'href="https://example.com/custom.css" />' not in content) + + @pytest.mark.sphinx('epub') def test_run_epubcheck(app): app.build() |