def export_file_as_web_markup(
    width,
    height,
    background_color,
    image_path,
    raster_for_previews,
    export_html,
):
    """Export loaded file as a .svg image file.

    That is, the current state of the file is exported,
    the objects currently alive, regardless of whether
    they are saved on disk.
    """
    ### create svg element

    svg = Element(
        "svg",
        {
            "width": str(width),
            "height": str(height),
            "xmlns": "http://www.w3.org/2000/svg",
            "xmlns:xlink": "http://www.w3.org/1999/xlink",
        },
    )

    ## create style element

    try:
        background_color[3]

    except IndexError:

        bg_color_style = f"fill:rgb{background_color};"

    else:

        bg_color_style = (
            f"fill:rgb{background_color[:3]};"
            "fill-opacity:"
            f"{round(background_color[3]/255, 3)};",
        )

    style = Element("style")

    style.text = (
        dedent(
            f"""
      rect.graph_bg {{{bg_color_style}}}

      .checker_a {{
        fill: rgb(235, 235, 235);
      }}

      .checker_b {{
        fill: rgb(20, 20, 20);
      }}
      """
        )
        + GENERAL_SURFACES_CSS
        + CALLABLE_NODE_CSS
        + PROXY_NODE_CSS
        + STLIB_NODE_CSS
        + THIRDLIB_NODE_CSS
        + BUILTIN_NODE_CSS
        + CAPSULE_NODE_CSS
        + GENVIEWER_NODE_CSS
        + OPERATOR_NODE_CSS
        + SOCKET_AND_LINE_CSS
        + TEXT_BLOCK_CSS
        + WIDGET_CSS
        + PREVIEW_OBJECTS_CSS
    )

    ### if we are to export an html page, create
    ### related tags and append style in the
    ### head element

    if export_html:

        html = Element("html")
        head = Element("head")
        body = Element("body")

        html.extend([head, body])

        title = Element("title")

        title.text = "Nodezator graph (python callables graph)"

        head.extend([title, style])

        body.append(svg)

    ### otherwise...
    else:
        svg.append(style)

    ## append a rect representing the background

    svg.append(
        Element(
            "rect",
            {
                "x": "0",
                "y": "0",
                "width": str(width),
                "height": str(height),
                "class": "graph_bg",
            },
        )
    )

    ## create and append pattern

    pattern = Element(
        "pattern",
        {
            "x": "0",
            "y": "0",
            "width": "10",
            "height": "10",
            "id": "checker_pattern",
            "patternUnits": "userSpaceOnUse",
        },
    )

    for x, y in ((0, 0), (5, 5)):

        pattern.append(
            Element(
                "rect",
                {
                    "x": str(x),
                    "y": str(y),
                    "width": "5",
                    "height": "5",
                    "class": "checker_a",
                },
            )
        )

    for x, y in ((0, 5), (5, 0)):

        pattern.append(
            Element(
                "rect",
                {
                    "x": str(x),
                    "y": str(y),
                    "width": "5",
                    "height": "5",
                    "class": "checker_b",
                },
            )
        )

    svg.append(pattern)

    ##

    if raster_for_previews:

        path = Path(image_path)

        parent = path.parent / (path.stem + "_files")

        APP_REFS.preview_handling_kit = (
            {},
            {},
            parent.name,
        )

    ###
    gm = APP_REFS.gm

    ## append preview panels and toolbars

    svg.extend(
        [
            obj.svg_repr()
            for obj in chain(
                gm.preview_panels,
                gm.preview_toolbars,
            )
        ]
    )

    ## append lines
    svg.extend(list(gm.yield_lines_as_svg()))

    ## append nodes and text blocks

    svg.extend(
        [
            obj.svg_repr()
            for obj in chain(
                gm.nodes,
                gm.text_blocks,
            )
        ]
    )

    ### save raster previews

    if raster_for_previews:

        if parent.is_file():

            raise RuntimeError(
                "Exporting can't proceed;"
                f" {parent} must not be a file"
                " (it must either be a directory"
                " or not exist at all, so that"
                " we can create/use it) to save"
                " the raster previews"
            )

        ## save raster previews

        preview_surf_map, preview_name_map = APP_REFS.preview_handling_kit[:2]

        # if there are raster previews to be saved
        # and the parent folder to be used doesn't
        # exist, create the parent folder
        if preview_surf_map and not parent.exists():
            parent.mkdir()

        # save

        for (key, surf) in preview_surf_map.items():

            name = preview_name_map[key]
            save_image(surf, str(parent / name))

        ## clear collections and delete preview
        ## handling kit

        for obj in APP_REFS.preview_handling_kit[:2]:
            obj.clear()

        del APP_REFS.preview_handling_kit

    ### define root element to save
    root = html if export_html else svg

    ### then save the root as markup text in the given
    ### path

    with (
        open(
            image_path,
            mode="w",
            encoding="utf-8",
        )
    ) as f:

        text = parseString(
            element_to_string(root, encoding="unicode")
        ).toprettyxml()

        if export_html:

            text = linesep.join(["<!DOCTYPE html>"] + text.splitlines()[1:])

        ### unescape all css lines

        for index, line in enumerate(text.splitlines()):

            if line.strip() == "<style>":
                css_start = index + 1

            elif line.strip() == "</style>":
                css_end = index

        text = linesep.join(
            unescape(line) if css_start <= index <= css_end else line
            for index, line in enumerate(text.splitlines())
        )

        ###
        f.write(text)
Export loaded file as a .svg image file.

    That is, the current state of the file is exported,
    the objects currently alive, regardless of whether
    they are saved on disk.
    
nodezator/editing/imageexport/main.py