Skip to content

Discarding of "invalid" property values - way to keep in parsed object? #171

@cjsio

Description

@cjsio

Hello, great project you all have worked on here.

I'm parsing scss files which works wonderfully for the css portions but drops out any properties/values that cannot be perfectly parsed, and I'd like to disable this strictness. I understand that this won't provide full support for less/scss syntax, but it would help drastically even with a few updates.

Update: There is a tolerateInvalidValues parameter in the StylesheetParser constructor method. Setting this to true handles the scss-variables issue (which is now in strikethrough markup).

For example, consider these properties and values:

.classname {
    background: $bgColor;
    font-size: $mediumFont;
}

Currently, the parsed .classname ruleblock will parse in ExCSS as if it's empty, simply because the values are preprocessor variables. For our purposes, it would be much better to store the invalid vanilla css value of $bgColor or $mediumFont in the parsed object instead of acting like the property doesn't even exist.

Remaining Issue

@include mixin-name-here; and @include mixin-with-params(12px, #000); statements are likewise completely dropped. I understand that importing mixin definition property values is outside the scope of this project, but again, I'd like the parse output to at least acknowledge that the @include statement is present. Can an .InvalidProperties or similar collection be added to each IStyleRule object, where @include or other preprocessor-specific statements can at least be recallable?

Lastly, there should be some way (even if using a custom CssStyleFormatter definition) to print out these invalid statements using this library's native .ToCss() method.

For invalid vanilla property values (like the variables in the first example), if the raw value is set inside the parsed property (eg. font-size or background), then .ToCss() would function as expected without further modification. This functionality could of course be walled behind a boolean toggle, such as parser.HonorInvalidValues = true;. See tolerateInvalidValues parameter info above

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions