def test_dumps_media(advanced_file_regression: AdvancedFileRegressionFixture, tmp_pathplus: PathPlus): stylesheet: Dict[str, MutableMapping] = { ".wy-nav-content": { "max-width": (rem(1200), IMPORTANT) }, "li p:last-child": { "margin-bottom": (em(12), IMPORTANT), "margin-top": em(6), }, "html": { "scroll-behavior": "smooth" }, "@media screen and (min-width: 870px)": { "li p:last-child": { "max-width": (rem(1200), IMPORTANT) } }, } css = dumps(stylesheet, trailing_semicolon=True) advanced_file_regression.check(css, extension=".css") output_file = tmp_pathplus / "style.css" with output_file.open('w') as fp: dump(stylesheet, fp, trailing_semicolon=True) advanced_file_regression.check_file(output_file) dump(stylesheet, output_file, trailing_semicolon=True) advanced_file_regression.check_file(output_file)
def copy_assets(app: Sphinx, exception: Optional[Exception] = None) -> None: """ Copy asset files to the output. :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. """ if exception: # pragma: no cover return style = {} for colour, hex_ in _colour_map.items(): style[ f"div.sphinx-highlights div.highlight-{colour} div.card-header"] = { "background-color": hex_ } # if app.config.html_theme in {"domdf_sphinx_theme", "sphinx_rtd_theme"}: # header_colour = app.config.html_theme_options.get("style_nav_header_background", "#2980B9") # # style.blankline() # style.extend([ # "div.sphinx-highlights div.card-header {", # f" background-color: {header_colour}", # '}', # ]) css_dir = PathPlus(app.builder.outdir) / "_static" / "css" css_dir.maybe_make(parents=True) dict2css.dump(style, css_dir / "sphinx_highlights.css")
def test_dump_minify(advanced_file_regression: AdvancedFileRegressionFixture, tmp_pathplus: PathPlus): stylesheet: Dict[str, Style] = { ".wy-nav-content": { "max-width": (rem(1200), IMPORTANT) }, "li p:last-child": { "margin-bottom": (em(12), IMPORTANT), "margin-top": em(6), }, "html": { "scroll-behavior": "smooth" }, } css = dumps(stylesheet, minify=True) advanced_file_regression.check(css, extension=".css") output_file = tmp_pathplus / "style.css" with output_file.open('w') as fp: dump(stylesheet, fp, minify=True) advanced_file_regression.check_file(output_file) dump(stylesheet, output_file, minify=True) advanced_file_regression.check_file(output_file)
def test_loads(advanced_data_regression: AdvancedDataRegressionFixture, tmp_pathplus: PathPlus): style = [ ".wy-nav-content {", " max-width: 1200rem !important;", " }", '', "li p:last-child {", " margin-bottom: 12em !important;", " margin-top: 6em;", " }", '', "@media screen {", " html {", " scroll-behavior: smooth;", " }", '}', ] advanced_data_regression.check(loads('\n'.join(style))) stylesheet: Mapping[str, Mapping] = { ".wy-nav-content": { "max-width": (rem(1200), IMPORTANT) }, "li p:last-child": { "margin-bottom": (em(12), IMPORTANT), "margin-top": em(6), }, "html": { "scroll-behavior": "smooth" }, "@media screen and (min-width: 870px)": { "li p:last-child": { "max-width": (rem(1200), IMPORTANT) } }, } assert loads(dumps(stylesheet)) == stylesheet style_file = tmp_pathplus / "style.css" dump(stylesheet, style_file) assert load(style_file) == stylesheet with style_file.open() as fp: assert load(fp) == stylesheet
def copy_asset_files(app: Sphinx, exception: Optional[Exception] = None): """ Copy additional stylesheets into the HTML build directory. :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. """ if exception: # pragma: no cover return if app.builder is None or app.builder.format.lower( ) != "html": # pragma: no cover return static_dir = PathPlus(app.outdir) / "_static" static_dir.maybe_make(parents=True) dict2css.dump(_css.regex_styles, static_dir / "regex.css", minify=True)
def copy_asset_files(app: Sphinx, exception: Optional[Exception] = None) -> None: """ Copy asset files to the output. :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. .. versionchanged:: 2.7.0 Renamed from ``copy_assets``. The old name is deprecated an will be removed in 3.0.0 """ if exception: # pragma: no cover return if app.builder is None or app.builder.format.lower() != "html": # pragma: no cover return # style = StringList([ # ".docutils.container {", # " padding-left: 0 !important;", # " padding-right: 0 !important;", # '}', # '', # # "div.sphinx-tabs.docutils.container {", # # " padding-left: 0 !important;", # # " padding-right: 0 !important;", # # "}", # # '', # "div.ui.top.attached.tabular.menu.sphinx-menu.docutils.container {", # # " padding-left: 0 !important;", # # " padding-right: 0 !important;", # " margin-left: 0 !important;", # " margin-right: 0 !important;", # '}', # ]) css_static_dir = PathPlus(app.builder.outdir) / "_static" / "css" css_static_dir.maybe_make(parents=True) dict2css.dump(_css.tweaks_sphinx_panels_tabs_styles, css_static_dir / "tabs_customise.css")
def copy_asset_files(app: Sphinx, exception: Optional[Exception] = None): """ Copy additional stylesheets into the HTML build directory. :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. """ if exception: # pragma: no cover return if app.builder is None or app.builder.format.lower() != "html": # pragma: no cover return extensions_selector = ", ".join([ "p.sphinx-toolbox-extensions", "div.sphinx-toolbox-extensions.highlight-python", "div.sphinx-toolbox-extensions.highlight-python div.highlight", ]) rest_example_style = { "padding-left": "5px", "border-style": "dotted", "border-width": "1px", "border-color": "darkgray", } style: MutableMapping[str, dict2css.Style] = { "p.source-link": {"margin-bottom": 0}, "p.source-link + hr.docutils": {"margin-top": "10px"}, extensions_selector: {"margin-bottom": "10px"}, "div.rest-example.docutils.container": rest_example_style, **installation_styles, **shields_styles, **regex_styles, } css_static_dir = PathPlus(app.outdir) / "_static" / "css" css_static_dir.maybe_make(parents=True) dict2css.dump(style, css_static_dir / "sphinx-toolbox.css")
def copy_asset_files(app: Sphinx, exception: Optional[Exception] = None): """ Copy additional stylesheets into the HTML build directory. .. versionadded:: 2.6.0 :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. """ if exception: # pragma: no cover return if app.builder is None or app.builder.format.lower( ) != "html": # pragma: no cover return prompt_style: dict2css.Style = { "user-select": None, "font-size": "13px", "font-family": '"SFMono-Regular", Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace', "border": None, "padding": "11px 0 0", "margin": "0 5px 0 0", "box-shadow": None, "wrap-option": None, "white-space": "nowrap", } container_style: dict2css.Style = { "padding-top": "5px", "display": "flex", "align-items": "stretch", "margin": 0, } code_style_string = "div.code-cell.container div.code-cell-code, div.output-cell.container div.output-cell-code" code_style: dict2css.Style = { "width": "100%", "padding-top": 0, "margin-top": 0, } style: MutableMapping[str, dict2css.Style] = { "div.code-cell.container div.prompt": { "color": "#307FC1" }, "div.output-cell.container div.prompt": { "color": "#BF5B3D" }, "div.code-cell.container div.prompt, div.output-cell.container div.prompt": prompt_style, "div.code-cell.container, div.output-cell.container": container_style, code_style_string: code_style, } static_dir = PathPlus(app.outdir) / "_static" static_dir.maybe_make(parents=True) dict2css.dump(style, static_dir / "sphinx-toolbox-code.css")
def copy_asset_files(app: Sphinx, exception: Optional[Exception] = None): """ Copy additional stylesheets into the HTML build directory. .. versionadded:: 1.2.0 :param app: The Sphinx application. :param exception: Any exception which occurred and caused Sphinx to abort. """ if exception: # pragma: no cover return if app.builder is None or app.builder.format.lower() != "html": # pragma: no cover return static_dir = PathPlus(app.outdir) / "_static" static_dir.maybe_make(parents=True) dict2css.dump(_css.installation_styles, static_dir / "sphinx_toolbox_installation.css", minify=True) (static_dir / "sphinx_toolbox_installation.js").write_lines([ "// Based on https://github.com/executablebooks/sphinx-tabs/blob/master/sphinx_tabs/static/tabs.js", "// Copyright (c) 2017 djungelorm", "// MIT Licensed", '', "function deselectTabset(target) {", " const parent = target.parentNode;", " const grandparent = parent.parentNode;", '', ' if (parent.parentNode.parentNode.getAttribute("id").startsWith("installation")) {', '', " // Hide all tabs in current tablist, but not nested", " Array.from(parent.children).forEach(t => {", ' if (t.getAttribute("name") !== target.getAttribute("name")) {', ' t.setAttribute("aria-selected", "false");', " }", " });", '', " // Hide all associated panels", " Array.from(grandparent.children).slice(1).forEach(p => { // Skip tablist", ' if (p.getAttribute("name") !== target.getAttribute("name")) {', ' p.setAttribute("hidden", "false")', " }", " });", " }", '', " else {", " // Hide all tabs in current tablist, but not nested", " Array.from(parent.children).forEach(t => {", ' t.setAttribute("aria-selected", "false");', " });", '', " // Hide all associated panels", " Array.from(grandparent.children).slice(1).forEach(p => { // Skip tablist", ' p.setAttribute("hidden", "true")', " });", " }", '', '}', '', "// Compatibility with sphinx-tabs 2.1.0 and later", "function deselectTabList(tab) {deselectTabset(tab)}", '', ])