Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Merging styles does not work #7

Closed
chanan opened this issue May 15, 2018 · 1 comment
Closed

Merging styles does not work #7

chanan opened this issue May 15, 2018 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@chanan
Copy link
Owner

chanan commented May 15, 2018

The following does not work correctly:

Css secondPre = Css.CreateNew()
        .AddRule("position", "relative")
        .AddRule("padding", 20)
        .OpenSelector(":before")
            .AddRule("position", "absolute")
            .AddRule("top", 0)
            .AddRule("opacity", 0.6)
            .AddRule("left", "7px")
            .AddRule("font-size", "0.8rem")
        .CloseSelector()
        .AddDynamicRule((css, attributes) =>
        {
            var lang = attributes.GetStringAttribute("language");
            var isHtml = "html" == lang;
            css.OpenSelector(":before")
                .AddRule("content", $"\\\"{lang}\\\"")
            .CloseSelector();
            if (isHtml)
            {
                css.AddRule("background-color", "#0c1e35")
                    .AddRule("color", "white");
            }
        });

When converted to json, :before isn't merged, its overwritten.

@chanan chanan added the bug Something isn't working label May 15, 2018
@chanan chanan self-assigned this May 15, 2018
@chanan
Copy link
Owner Author

chanan commented May 15, 2018

A workaround for this in the meantime would be to create this as two different variables:

Css secondPre = Css.CreateNew()
        .AddRule("position", "relative")
        .AddRule("padding", 20)
        .OpenSelector(":before")
            .AddRule("position", "absolute")
            .AddRule("top", 0)
            .AddRule("opacity", 0.6)
            .AddRule("left", "7px")
            .AddRule("font-size", "0.8rem")
        .CloseSelector();

Css secondPre2 = Css.CreateNew()
        .AddDynamicRule((css, attributes) =>
        {
            var lang = attributes.GetStringAttribute("language");
            var isHtml = "html" == lang;
            css.OpenSelector(":before")
                .AddRule("content", $"\\\"{lang}\\\"")
            .CloseSelector();
            if (isHtml)
            {
                css.AddRule("background-color", "#0c1e35")
                    .AddRule("color", "white");
            }
        });

@chanan chanan closed this as completed May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant