Sha256: f213ad3d371f90cd6262509eb47ccb059d23bbb4b5ebbddb2bf84b54dd89d7f7

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

# HTML check API

For checking HTML elements in `.liquid` files.

If you need to check an HTML tag or its attributes, use an `HtmlCheck`.

The HTML in Liquid files is parsed using the Nokogiri, by consequence you will get [`Nokogiri::XML::Node`][nokogiri].


```ruby
module ThemeCheck
  class MyCheckName < HtmlCheck
    category :html,
    # A check can belong to multiple categories. Valid ones:
    categories :translation, :performance
    severity :suggestion # :error or :style

    def on_document(node)
      # Called with the root node of all theme files
      node.value      # is an instance of Nokogiri::XML::Node
      node.theme_file # is the html_file being analyzed, See lib/theme_check/theme_file.rb.
      node.parent     # is the parent node.
      node.children   # are the children nodes.
      # See lib/theme_check/html_node.rb for more helper methods
      theme # Gives you access to all the theme files in the theme. See lib/theme_check/theme.rb.
    end

    def on_img(node)
      # Called for every <img> element in the file.
      node.attributes["class"] # Get the class attribute of the img element.
    end

    def on_a(node)
      # Called for every <a> element in the file.
    end
  end
end
```

## Resources

- [Nokogiri::XML::Node API doc][nokogiri]

[nokogiri]: https://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node


Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
theme-check-1.15.0 docs/api/html_check.md
theme-check-1.14.0 docs/api/html_check.md
theme-check-1.13.0 docs/api/html_check.md
theme-check-1.12.1 docs/api/html_check.md
theme-check-1.12.0 docs/api/html_check.md
theme-check-1.11.0 docs/api/html_check.md
theme-check-1.10.3 docs/api/html_check.md
theme-check-1.10.2 docs/api/html_check.md
theme-check-1.10.1 docs/api/html_check.md
theme-check-1.10.0 docs/api/html_check.md
theme-check-1.9.2 docs/api/html_check.md
theme-check-1.9.1 docs/api/html_check.md
theme-check-1.9.0 docs/api/html_check.md
theme-check-1.8.0 docs/api/html_check.md
theme-check-1.7.2 docs/api/html_check.md
theme-check-1.7.1 docs/api/html_check.md
theme-check-1.7.0 docs/api/html_check.md
theme-check-1.6.2 docs/api/html_check.md