Skip to content

How to deal with inline styles? #15

Closed
@bartveneman

Description

@bartveneman

It should be fairly easy to find inline styles, and it could certainly be very interesting to see their results, but how should they be reported? Inline styles don't have selectors, but merely declarations.

Scraping inline styles from a page:

[...document.querySelectorAll('[style]')].map(el => el.getAttribute('style')).join('')

We could generate a unique selector for each inline style attribute, but it could interfere with the resulting CSS statistics:

const nanoid = require('nanoid')
[...document.querySelectorAll('[style]')].map(el => {
  return `[x-inline-style-${nanoid()}] { // create a custom [x-inline-style-*] selector
    ${el.getAttribute('style')} // contains all declarations
  }`
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions