Fix MarkupFixer, del files, mod headers
Этот коммит содержится в:
родитель
e8d9b87ced
Коммит
c00cb51d29
4
.gitignore
поставляемый
4
.gitignore
поставляемый
@ -1,6 +1,4 @@
|
|||||||
# files
|
# files
|
||||||
vendor/
|
vendor/
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
composer.lock
|
||||||
# IDE stuff
|
|
||||||
.idea/workspace.xml
|
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
# ChangeLog - PHP TableOfContents (TOC)
|
# ChangeLog - PHP TableOfContents (TOC)
|
||||||
All notable changes to this project are documented in this file.
|
All notable changes to this project are documented in this file.
|
||||||
|
|
||||||
## 1.0 - 2014-12-30
|
## Forked 1.0 - 2015-02-04
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- MarkupFixer - Don't remove EOL-symbol
|
||||||
|
- MarkupFixer - Id naming <http://www.w3.org/TR/html4/types.html#type-name>
|
||||||
|
|
||||||
|
## Original 1.0 - 2014-12-30
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Initial Version
|
- Initial Version
|
||||||
|
1
LICENSE
1
LICENSE
@ -1,6 +1,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2014 Casey McLaughlin
|
Copyright (c) 2013-2014 Casey McLaughlin
|
||||||
|
Copyright (c) 2015 Igor V Belousov
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -30,7 +30,7 @@ Install via [Composer](http://getcomposer.org/) by including the following in yo
|
|||||||
|
|
||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"caseyamcl/toc": "~1.0",
|
"igorvbelousov/toc": "~1.0",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Igor V Belousov",
|
"name": "Igor V Belousov",
|
||||||
"email": "igor@belousovv.ru",
|
"email": "igor@belousovv.ru",
|
||||||
|
"homepage": "http://belousovv.ru",
|
||||||
"role": "Developer"
|
"role": "Developer"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
245
composer.lock
сгенерированный
245
composer.lock
сгенерированный
@ -1,245 +0,0 @@
|
|||||||
{
|
|
||||||
"_readme": [
|
|
||||||
"This file locks the dependencies of your project to a known state",
|
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
|
||||||
"This file is @generated automatically"
|
|
||||||
],
|
|
||||||
"hash": "01914fa61e59dbe4c7c3d1772643be14",
|
|
||||||
"packages": [
|
|
||||||
{
|
|
||||||
"name": "cocur/slugify",
|
|
||||||
"version": "v1.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/cocur/slugify.git",
|
|
||||||
"reference": "2c929c56997e663747be9bb635e58db918a0134f"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/cocur/slugify/zipball/2c929c56997e663747be9bb635e58db918a0134f",
|
|
||||||
"reference": "2c929c56997e663747be9bb635e58db918a0134f",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3.3"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"codeclimate/php-test-reporter": "dev-master",
|
|
||||||
"laravel/framework": "~4.1",
|
|
||||||
"mockery/mockery": "~0.9",
|
|
||||||
"phpunit/phpunit": "~3.7",
|
|
||||||
"sami/sami": "~1.3",
|
|
||||||
"satooshi/php-coveralls": "0.6.*",
|
|
||||||
"silex/silex": "~1.2",
|
|
||||||
"symfony/dependency-injection": "~2.4",
|
|
||||||
"symfony/http-kernel": "~2.4",
|
|
||||||
"twig/twig": "~1",
|
|
||||||
"zendframework/zend-modulemanager": "~2.2",
|
|
||||||
"zendframework/zend-servicemanager": "~2.2",
|
|
||||||
"zendframework/zend-view": "~2.2"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Cocur\\Slugify\\": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Ivo Bathke",
|
|
||||||
"email": "ivo.bathke@gmail.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Florian Eckerstorfer",
|
|
||||||
"email": "florian@eckerstorfer.co",
|
|
||||||
"homepage": "https://florian.ec"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Converts a string into a slug.",
|
|
||||||
"keywords": [
|
|
||||||
"slug",
|
|
||||||
"slugify"
|
|
||||||
],
|
|
||||||
"time": "2014-11-26 22:45:14"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "knplabs/knp-menu",
|
|
||||||
"version": "v2.0.1",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/KnpLabs/KnpMenu.git",
|
|
||||||
"reference": "5758d0026d7ed00c8dd4727e413918cf2dc74c1a"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/KnpLabs/KnpMenu/zipball/5758d0026d7ed00c8dd4727e413918cf2dc74c1a",
|
|
||||||
"reference": "5758d0026d7ed00c8dd4727e413918cf2dc74c1a",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"pimple/pimple": "1.0.*",
|
|
||||||
"silex/silex": "1.0.*",
|
|
||||||
"twig/twig": ">=1.2,<2.0-dev"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"pimple/pimple": "for the built-in implementations of the menu provider and renderer provider",
|
|
||||||
"silex/silex": "for the integration with your silex application",
|
|
||||||
"twig/twig": "for the TwigRenderer and the integration with your templates"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "2.0.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"Knp\\Menu\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Christophe Coevoet",
|
|
||||||
"email": "stof@notk.org"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "KnpLabs",
|
|
||||||
"homepage": "http://knplabs.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Symfony Community",
|
|
||||||
"homepage": "https://github.com/KnpLabs/KnpMenu/contributors"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "An object oriented menu library",
|
|
||||||
"homepage": "http://knplabs.com",
|
|
||||||
"keywords": [
|
|
||||||
"menu",
|
|
||||||
"tree"
|
|
||||||
],
|
|
||||||
"time": "2014-08-01 09:50:16"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sunra/php-simple-html-dom-parser",
|
|
||||||
"version": "v1.5.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/sunra/php-simple-html-dom-parser.git",
|
|
||||||
"reference": "a0b80ace086c7e09085669205e1b3c2c9c7a453c"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/sunra/php-simple-html-dom-parser/zipball/a0b80ace086c7e09085669205e1b3c2c9c7a453c",
|
|
||||||
"reference": "a0b80ace086c7e09085669205e1b3c2c9c7a453c",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.3.2"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"Sunra\\PhpSimple\\HtmlDomParser": "Src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Sunra",
|
|
||||||
"email": "sunra@yandex.ru",
|
|
||||||
"homepage": "http://github.com/sunra"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.",
|
|
||||||
"homepage": "https://github.com/sunra/php-simple-html-dom-parser",
|
|
||||||
"keywords": [
|
|
||||||
"dom",
|
|
||||||
"html",
|
|
||||||
"parser"
|
|
||||||
],
|
|
||||||
"time": "2013-05-04 14:32:03"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"packages-dev": [
|
|
||||||
{
|
|
||||||
"name": "twig/twig",
|
|
||||||
"version": "v1.17.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/twigphp/Twig.git",
|
|
||||||
"reference": "2493970fa4d587eca73f77e6d8bd48a8bdd4c608"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/2493970fa4d587eca73f77e6d8bd48a8bdd4c608",
|
|
||||||
"reference": "2493970fa4d587eca73f77e6d8bd48a8bdd4c608",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">=5.2.4"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-master": "1.17-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-0": {
|
|
||||||
"Twig_": "lib/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"BSD-3-Clause"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Fabien Potencier",
|
|
||||||
"email": "fabien@symfony.com",
|
|
||||||
"homepage": "http://fabien.potencier.org",
|
|
||||||
"role": "Lead Developer"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Armin Ronacher",
|
|
||||||
"email": "armin.ronacher@active-4.com",
|
|
||||||
"role": "Project Founder"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Twig Team",
|
|
||||||
"homepage": "http://twig.sensiolabs.org/contributors",
|
|
||||||
"role": "Contributors"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Twig, the flexible, fast, and secure template language for PHP",
|
|
||||||
"homepage": "http://twig.sensiolabs.org",
|
|
||||||
"keywords": [
|
|
||||||
"templating"
|
|
||||||
],
|
|
||||||
"time": "2015-01-14 10:15:49"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"aliases": [],
|
|
||||||
"minimum-stability": "stable",
|
|
||||||
"stability-flags": [],
|
|
||||||
"prefer-stable": false,
|
|
||||||
"prefer-lowest": false,
|
|
||||||
"platform": {
|
|
||||||
"php": ">=5.4"
|
|
||||||
},
|
|
||||||
"platform-dev": []
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
|
|
||||||
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="PHP TOC Test Suite">
|
|
||||||
<directory suffix="Test.php">./tests</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
|
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory>./</directory>
|
|
||||||
<exclude>
|
|
||||||
<directory>./tests</directory>
|
|
||||||
<directory>./vendor</directory>
|
|
||||||
</exclude>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
</phpunit>
|
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
* @author Igor V Belouosv <igor@belousovv.ru>
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@ -19,75 +19,104 @@
|
|||||||
namespace TOC;
|
namespace TOC;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Sunra\PhpSimple\HtmlDomParser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TOC Markup Fixer adds `id` attributes to all H1...H6 tags where they do not
|
* TOC Markup Fixer adds `id` attributes to all H1...H6 tags where they do not
|
||||||
* already exist
|
* already exist
|
||||||
*
|
*
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*/
|
*/
|
||||||
class MarkupFixer
|
class MarkupFixer
|
||||||
{
|
{
|
||||||
use HeaderTagInterpreter;
|
use HeaderTagInterpreter;
|
||||||
|
private $ids = array();
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
/**
|
||||||
|
* Fix markup
|
||||||
|
*
|
||||||
|
* @param string $markup
|
||||||
|
* @param int $topLevel
|
||||||
|
* @param int $depth
|
||||||
|
* @return string Markup with added IDs
|
||||||
|
*/
|
||||||
|
public function fix($markup, $topLevel = 1, $depth = 6)
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
$tags = $this->determineHeaderTags($topLevel, $depth);
|
||||||
* @var HtmlDomParser
|
preg_replace_callback(
|
||||||
*/
|
'/<.*?id[\t,\ ]*?=[\t,\ ]*?[\'|"](.*?)[\'|"].*?>/ui',
|
||||||
private $domParser;
|
function ($m)
|
||||||
|
{
|
||||||
|
array_push($this->ids, $m[1]);
|
||||||
|
},
|
||||||
|
$markup);
|
||||||
|
$markup = preg_replace_callback(
|
||||||
|
'/(<h['.
|
||||||
|
implode('|', $tags)
|
||||||
|
.'](\s+[^>]*?)?)>(.*?)<\/h/ui',
|
||||||
|
'self::fix_callback',
|
||||||
|
$markup
|
||||||
|
);
|
||||||
|
$this->ids = array();
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
return $markup;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Replace callback for fix function
|
||||||
*
|
*
|
||||||
* @param HtmlDomParser $domParser
|
* @param array $value
|
||||||
*/
|
* @return string Markup with added IDs
|
||||||
public function __construct(HtmlDomParser $domParser = null)
|
*/
|
||||||
|
private function fix_callback($value)
|
||||||
|
{
|
||||||
|
$sluggifier = new UniqueSluggifier();
|
||||||
|
if (preg_match('/id/ui',$value[1])==false)
|
||||||
{
|
{
|
||||||
$this->domParser = $domParser ?: new HtmlDomParser();
|
if (preg_match('/title/ui',$value[1])) {
|
||||||
}
|
$title = preg_replace_callback(
|
||||||
|
'/.*title[\t,\ ]*?=[\t,\ ]*?[\'|"](.*?)[\'|"]/ui',
|
||||||
|
function ($m){return $m[1];},
|
||||||
|
$value[1]);
|
||||||
|
return $value[1].' id="'.
|
||||||
|
preg_replace(
|
||||||
|
'/^[-0-9._:]/',
|
||||||
|
'N',
|
||||||
|
$sluggifier->slugify($title)
|
||||||
|
)
|
||||||
|
.'">'.$value[3].'</h';
|
||||||
|
}
|
||||||
|
return $value[1].' id="'.
|
||||||
|
preg_replace(
|
||||||
|
'/^[-0-9._:]/',
|
||||||
|
'N',
|
||||||
|
$this->CheckUniqId($sluggifier->slugify($value[3]))
|
||||||
|
)
|
||||||
|
.'">'.$value[3].'</h';
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
return $value[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix markup
|
* Check and return unique id
|
||||||
*
|
*
|
||||||
* @param string $markup
|
* @param string $id Check id
|
||||||
* @param int $topLevel
|
* @param integer $number parametr for recursive check
|
||||||
* @param int $depth
|
*
|
||||||
* @return string Markup with added IDs
|
* @return string unique id
|
||||||
* @throws RuntimeException
|
*/
|
||||||
*/
|
private function CheckUniqId($id,$number=0){
|
||||||
public function fix($markup, $topLevel = 1, $depth = 6)
|
$tmpid = ($number>0)?$id.'-'.$number:$id;
|
||||||
{
|
if (array_search($tmpid, $this->ids)===false)
|
||||||
$sluggifier = new UniqueSluggifier();
|
{
|
||||||
|
array_push($this->ids,$tmpid);
|
||||||
$tags = $this->determineHeaderTags($topLevel, $depth);
|
return $tmpid;
|
||||||
$parsed = $this->domParser->str_get_html($markup);
|
}
|
||||||
|
$number++;
|
||||||
// Runtime exception for bad code
|
return $this->CheckUniqId($id,$number);
|
||||||
if ( ! $parsed) {
|
}
|
||||||
throw new RuntimeException("Could not parse HTML");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract items
|
|
||||||
foreach ($parsed->find(implode(', ', $tags)) as $tag) {
|
|
||||||
|
|
||||||
// Ignore tags that already have IDs
|
|
||||||
if ($tag->id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tag->id = preg_replace('/^[-0-9._:]+/', '',
|
|
||||||
$sluggifier->slugify($tag->title ?: $tag->plaintext)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (string) $parsed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF: TocMarkupFixer.php */
|
/* EOF: TocMarkupFixer.php */
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
@ -42,14 +43,30 @@ class MarkupFixerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
|
public function testFixAddsIdsW3C()
|
||||||
|
{
|
||||||
|
$obj = new MarkupFixer();
|
||||||
|
|
||||||
|
$html = "<h1>1 Number and ID</h1><h2>: 123</h2>";
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'<h1 id="N-number-and-id">1 Number and ID</h1><h2 id="N23">: 123</h2>',
|
||||||
|
$obj->fix($html, 1, 2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
public function testFixDoesNotDuplicateIdsWhenFixing()
|
public function testFixDoesNotDuplicateIdsWhenFixing()
|
||||||
{
|
{
|
||||||
$obj = new MarkupFixer();
|
$obj = new MarkupFixer();
|
||||||
|
|
||||||
$html = "<h1>FooBar</h1><h2>FooBar</h2><h3>FooBar</h3>";
|
$html = "<h1>FooBar</h1><h2>FooBar</h2><h3>FooBar</h3><div id='foobar'>
|
||||||
|
</div>";
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'<h1 id="foobar">FooBar</h1><h2 id="foobar-1">FooBar</h2><h3 id="foobar-2">FooBar</h3>',
|
'<h1 id="foobar-1">FooBar</h1><h2 id="foobar-2">FooBar</h2><h3 id="foobar-3">FooBar</h3><div id=\'foobar\'>
|
||||||
|
</div>',
|
||||||
$obj->fix($html, 1, 3)
|
$obj->fix($html, 1, 3)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -60,6 +77,20 @@ class MarkupFixerTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$obj = new MarkupFixer();
|
$obj = new MarkupFixer();
|
||||||
|
|
||||||
|
$html = "<h1>No ID</h1><h2 title = 'b'>Existing ID</h2><h3>Ignored</h3>";
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'<h1 id="no-id">No ID</h1><h2 title = \'b\' id="b">Existing ID</h2><h3>Ignored</h3>',
|
||||||
|
$obj->fix($html, 1, 2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------
|
||||||
|
|
||||||
|
public function testFixUsesTitleAttributeWhenAvailableiWithOutTabs()
|
||||||
|
{
|
||||||
|
$obj = new MarkupFixer();
|
||||||
|
|
||||||
$html = "<h1>No ID</h1><h2 title='b'>Existing ID</h2><h3>Ignored</h3>";
|
$html = "<h1>No ID</h1><h2 title='b'>Existing ID</h2><h3>Ignored</h3>";
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
* PHP TableOfContents Library
|
* PHP TableOfContents Library
|
||||||
*
|
*
|
||||||
* @license http://opensource.org/licenses/MIT
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link https://github.com/caseyamcl/toc
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @package caseyamcl/toc
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
/**
|
/**
|
||||||
* toc
|
* toc
|
||||||
*
|
*
|
||||||
* @license ${LICENSE_LINK}
|
* @license http://opensource.org/licenses/MIT
|
||||||
* @link ${PROJECT_URL_LINK}
|
* @link https://github.com/igorvbelousov/toc
|
||||||
* @version ${VERSION}
|
* @version 1.0
|
||||||
* @package ${PACKAGE_NAME}
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
|
@ -6,7 +6,12 @@
|
|||||||
/**
|
/**
|
||||||
* PHP TOC Unit Tests Bootstrap File
|
* PHP TOC Unit Tests Bootstrap File
|
||||||
*
|
*
|
||||||
|
* @license http://opensource.org/licenses/MIT
|
||||||
|
* @link https://github.com/igorvbelousov/toc
|
||||||
|
* @version 1.0
|
||||||
|
* @package igorvbelousov/toc
|
||||||
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
* @author Casey McLaughlin <caseyamcl@gmail.com>
|
||||||
|
* @author Igor V Belousov <igor@belousovv.ru>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Files to ensure exist
|
//Files to ensure exist
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user