oliver-noth / markup-check
Parses and checks certain tags in an html markup given by either an url to fetch the markup from or the markup itself.
Requires
- php: ^8.0
Requires (Dev)
- behat/behat: ^3.6
- phpunit/phpunit: ^9
README
MarkupCheck is a composer package, which parses and checks certain tags in an html markup given by either an url to fetch the markup from or the markup itself.
Table of contents
Getting Started
Requirements
- Your local machine must run with at least PHP 8.0
- Be sure to have composer installed
Installation
Use composer to download and install MarkupCheck.
You can add MarkupCheck as a local, per-project dependency to your project:
$ composer require oliver-noth/markupcheck
If you only need MarkupCheck during development, then you should add it as a development-time dependency:
$ composer require --dev oliver-noth/markupcheck
Usage
Basic
First instantiate a new markup checker
$factory = new \OliverNoth\MarkupCheck\Main\Factory();
$markupChecker = $factory->createHtmlMarkupChecker('https://getcomposer.org/');
then get the parsed tags
$parsedTags = $markupChecker->getParsedTags();
or render them as json
$markupChecker->renderParsedTagsAsJson();
exit;
Parsed tags will be provided in an array (example shown below)
[
'headings' => [
'notes' => [
'Markup contains exactly 1 first heading (h1 tag).',
],
'tags' => [
0 => [
'name' => 'h1',
'rank' => 1,
'value' => 'First headline',
'attributes' => [
'class' => 'article',
],
],
],
],
'anchors' => [
'notes' => [
'All anchors are linked correctly.',
],
'tags' => [
0 => [
'name' => 'a',
'value' => 'Get your example here',
'attributes' => [
'href' => 'https://www.example.com',
'target' => '_blank',
'class' => 'cta',
],
],
],
],
'images' => [
'notes' => [
'All images seem to have either an alt attribute or a title attribute.',
],
'tags' => [
0 => [
'name' => 'img',
'attributes' => [
'src' => 'https://www.example.com/image_01.jpg',
'alt' => 'Image 01',
'class' => 'slider',
],
],
],
],
];
Further
See example/basic-usage.php
to get an idea on how to render parsed tags.
Docker
Set up a docker container on your local machine using ddev.
Prerequisites
- Be sure to have docker installed and running. If not, follow these instructions.
Setup
Install ddev (using Homebrew/Linuxbrew is recommended):
$ brew tap drud/ddev && brew install ddev
Create and cd into your project directory (replace folder name `<PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project
` according to your needs):
$ mkdir -p <PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project
$ cd <PATH-TO-YOUR-PROJECT-DIRECTORY>/my-project
Create a new docker container
Configure a ddev docker container (replace project-name my-project
according to your needs):
$ ddev config --project-name=my-project --project-type=php --php-version=8.0 --docroot="" --create-docroot --disable-settings-management --http-port=8088 --https-port=44388
Create configured container and clone composer package into it:
IMPORTANT: Eventually arising question `Warning: ALL EXISTING CONTENT of the project root (~/my-project) will be deleted
` must be answered with 'yes'
$ ddev composer create oliver-noth/markup-check
Create index.php in document root of created container:
$ ddev exec chmod 755 example/write-index.sh && ddev exec ./example/write-index.sh
Finally start created container
$ ddev start
Once you have started the container, your project can be reached at `http://my-project.ddev.site:8088
.<br>
NOTE: Subdomain
my-project` should be replaced with project-name you have chosen before.
Unit tests
This package is completely unit tested. You can run them in the created container:
$ ddev exec vendor/bin/phpunit
Displaying a code coverage summary needs enabling a code coverage driver. Use xdebug, check it and get the summary:
$ ddev xdebug
$ ddev xdebug status
$ ddev exec vendor/bin/phpunit --coverage-text
NOTE: Although code coverage is at 100%, maybe the container displays a smaller coverage.
Running it on your local machine (assuming a code coverage driver like xdebug is installed) in your project directory should display 100%. Working on a fix...
$ vendor/bin/phpunit --coverage-text
Digging deeper
For instance managing the webserver behaviour of the container acting as such could be done by entering the container:
$ ddev ssh
MORE: Complete documentation can be found at ddev.readthedocs.io