h
This commit is contained in:
parent
3116d650da
commit
412652b9dc
453 changed files with 39152 additions and 1629 deletions
5
vendor/mnapoli/front-yaml/.gitattributes
vendored
Normal file
5
vendor/mnapoli/front-yaml/.gitattributes
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
tests/ export-ignore
|
||||
.github/ export-ignore
|
5
vendor/mnapoli/front-yaml/.gitignore
vendored
Normal file
5
vendor/mnapoli/front-yaml/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
vendor/*
|
||||
composer.phar
|
||||
composer.lock
|
||||
|
||||
.phpunit.result.cache
|
18
vendor/mnapoli/front-yaml/LICENSE
vendored
Normal file
18
vendor/mnapoli/front-yaml/LICENSE
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
FrontYAML
|
||||
|
||||
Copyright (C) 2021 Matthieu Napoli
|
||||
|
||||
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 the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
77
vendor/mnapoli/front-yaml/README.md
vendored
Normal file
77
vendor/mnapoli/front-yaml/README.md
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
# FrontYAML
|
||||
|
||||
An implementation of YAML Front matter for PHP. It can parse both YAML **and** Markdown.
|
||||
|
||||
[](https://packagist.org/packages/mnapoli/front-yaml)
|
||||
|
||||
## Installation
|
||||
|
||||
Require the project with Composer:
|
||||
|
||||
```
|
||||
composer require mnapoli/front-yaml
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```php
|
||||
$parser = new Mni\FrontYAML\Parser;
|
||||
|
||||
$document = $parser->parse($str);
|
||||
|
||||
$yaml = $document->getYAML();
|
||||
$html = $document->getContent();
|
||||
```
|
||||
|
||||
If you don't want the Markdown to be parsed (maybe because it is not Markdown):
|
||||
|
||||
```php
|
||||
$document = $parser->parse($str, false);
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
The following file:
|
||||
|
||||
```markdown
|
||||
---
|
||||
foo: bar
|
||||
---
|
||||
This is **strong**.
|
||||
```
|
||||
|
||||
Will give:
|
||||
|
||||
```php
|
||||
var_export($document->getYAML());
|
||||
// array("foo" => "bar")
|
||||
|
||||
var_export($document->getContent());
|
||||
// "<p>This is <strong>strong</strong></p>"
|
||||
```
|
||||
|
||||
## YAML and Markdown parsers
|
||||
|
||||
```php
|
||||
$parser = new Mni\FrontYAML\Parser($yamlParser, $markdownParser);
|
||||
```
|
||||
|
||||
This library uses dependency injection and abstraction to allow you to provide your own YAML or Markdown parser.
|
||||
|
||||
```php
|
||||
interface YAMLParser
|
||||
{
|
||||
public function parse($yaml);
|
||||
}
|
||||
```
|
||||
|
||||
FrontYAML uses by default [Symfony's YAML parser](http://symfony.com/doc/current/components/yaml/introduction.html).
|
||||
|
||||
```php
|
||||
interface MarkdownParser
|
||||
{
|
||||
public function parse($markdown);
|
||||
}
|
||||
```
|
||||
|
||||
FrontYAML uses by default the [League CommonMark parser](https://github.com/thephpleague/commonmark).
|
22
vendor/mnapoli/front-yaml/composer.json
vendored
Normal file
22
vendor/mnapoli/front-yaml/composer.json
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "mnapoli/front-yaml",
|
||||
"license": "MIT",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mni\\FrontYAML\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Mni\\FrontYAML\\Test\\": "tests/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.4|^8.0",
|
||||
"symfony/yaml": "^4.0|^5.0|^6.0|^7.0",
|
||||
"league/commonmark": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.0"
|
||||
}
|
||||
}
|
21
vendor/mnapoli/front-yaml/phpunit.xml.dist
vendored
Normal file
21
vendor/mnapoli/front-yaml/phpunit.xml.dist
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
phpunit -c phpunit.xml
|
||||
-->
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
bootstrap="vendor/autoload.php">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Tests">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
</phpunit>
|
25
vendor/mnapoli/front-yaml/src/Bridge/CommonMark/CommonMarkParser.php
vendored
Normal file
25
vendor/mnapoli/front-yaml/src/Bridge/CommonMark/CommonMarkParser.php
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML\Bridge\CommonMark;
|
||||
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use League\CommonMark\MarkdownConverterInterface;
|
||||
use Mni\FrontYAML\Markdown\MarkdownParser;
|
||||
|
||||
/**
|
||||
* Bridge to the League CommonMark parser
|
||||
*/
|
||||
class CommonMarkParser implements MarkdownParser
|
||||
{
|
||||
private MarkdownConverterInterface $parser;
|
||||
|
||||
public function __construct(MarkdownConverterInterface $commonMarkConverter = null)
|
||||
{
|
||||
$this->parser = $commonMarkConverter ?: new CommonMarkConverter;
|
||||
}
|
||||
|
||||
public function parse(string $markdown): string
|
||||
{
|
||||
return $this->parser->convertToHtml($markdown)->getContent();
|
||||
}
|
||||
}
|
24
vendor/mnapoli/front-yaml/src/Bridge/Symfony/SymfonyYAMLParser.php
vendored
Normal file
24
vendor/mnapoli/front-yaml/src/Bridge/Symfony/SymfonyYAMLParser.php
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML\Bridge\Symfony;
|
||||
|
||||
use Mni\FrontYAML\YAML\YAMLParser;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
|
||||
/**
|
||||
* Bridge to the Symfony YAML parser
|
||||
*/
|
||||
class SymfonyYAMLParser implements YAMLParser
|
||||
{
|
||||
private Parser $parser;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->parser = new Parser;
|
||||
}
|
||||
|
||||
public function parse(string $yaml)
|
||||
{
|
||||
return $this->parser->parse($yaml);
|
||||
}
|
||||
}
|
37
vendor/mnapoli/front-yaml/src/Document.php
vendored
Normal file
37
vendor/mnapoli/front-yaml/src/Document.php
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML;
|
||||
|
||||
class Document
|
||||
{
|
||||
/** @var mixed */
|
||||
private $yaml;
|
||||
|
||||
private string $content;
|
||||
|
||||
/**
|
||||
* @param mixed $yaml YAML content.
|
||||
* @param string $content Content of the document.
|
||||
*/
|
||||
public function __construct($yaml, string $content)
|
||||
{
|
||||
$this->yaml = $yaml;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed YAML content.
|
||||
*/
|
||||
public function getYAML()
|
||||
{
|
||||
return $this->yaml;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Content of the document.
|
||||
*/
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
18
vendor/mnapoli/front-yaml/src/Markdown/MarkdownParser.php
vendored
Normal file
18
vendor/mnapoli/front-yaml/src/Markdown/MarkdownParser.php
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML\Markdown;
|
||||
|
||||
/**
|
||||
* Interface of a Markdown parser
|
||||
*/
|
||||
interface MarkdownParser
|
||||
{
|
||||
/**
|
||||
* Parses a Markdown string to HTML.
|
||||
*
|
||||
* @param string $markdown Markdown document.
|
||||
*
|
||||
* @return string HTML document.
|
||||
*/
|
||||
public function parse(string $markdown): string;
|
||||
}
|
71
vendor/mnapoli/front-yaml/src/Parser.php
vendored
Normal file
71
vendor/mnapoli/front-yaml/src/Parser.php
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML;
|
||||
|
||||
use Mni\FrontYAML\Bridge\CommonMark\CommonMarkParser;
|
||||
use Mni\FrontYAML\Bridge\Symfony\SymfonyYAMLParser;
|
||||
use Mni\FrontYAML\Markdown\MarkdownParser;
|
||||
use Mni\FrontYAML\YAML\YAMLParser;
|
||||
|
||||
/**
|
||||
* YAML Front matter parser
|
||||
*/
|
||||
class Parser
|
||||
{
|
||||
/**
|
||||
* @var YAMLParser
|
||||
*/
|
||||
private $yamlParser;
|
||||
|
||||
/**
|
||||
* @var MarkdownParser
|
||||
*/
|
||||
private $markdownParser;
|
||||
|
||||
private array $startSep;
|
||||
|
||||
private array $endSep;
|
||||
|
||||
/**
|
||||
* @param string|string[] $startSep
|
||||
* @param string|string[] $endSep
|
||||
*/
|
||||
public function __construct(
|
||||
?YAMLParser $yamlParser = null,
|
||||
?MarkdownParser $markdownParser = null,
|
||||
$startSep = '---',
|
||||
$endSep = '---'
|
||||
) {
|
||||
$this->yamlParser = $yamlParser ?: new SymfonyYAMLParser;
|
||||
$this->markdownParser = $markdownParser ?: new CommonMarkParser;
|
||||
$this->startSep = array_filter((array) $startSep, 'is_string') ?: ['---'];
|
||||
$this->endSep = array_filter((array) $endSep, 'is_string') ?: ['---'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string containing the YAML front matter and the markdown.
|
||||
*
|
||||
* @param bool $parseMarkdown Should the Markdown be turned into HTML?
|
||||
*/
|
||||
public function parse(string $str, bool $parseMarkdown = true): Document
|
||||
{
|
||||
$yaml = null;
|
||||
|
||||
$quote = static function ($str) {
|
||||
return preg_quote($str, "~");
|
||||
};
|
||||
|
||||
$regex = '~^('
|
||||
.implode('|', array_map($quote, $this->startSep)) # $matches[1] start separator
|
||||
."){1}[\r\n|\n]*(.*?)[\r\n|\n]+(" # $matches[2] between separators
|
||||
.implode('|', array_map($quote, $this->endSep)) # $matches[3] end separator
|
||||
."){1}[\r\n|\n]*(.*)$~s"; # $matches[4] document content
|
||||
|
||||
if (preg_match($regex, $str, $matches) === 1) { // There is a Front matter
|
||||
$yaml = trim($matches[2]) !== '' ? $this->yamlParser->parse(trim($matches[2])) : null;
|
||||
$str = ltrim($matches[4]);
|
||||
}
|
||||
|
||||
return new Document($yaml, $parseMarkdown ? $this->markdownParser->parse($str) : $str);
|
||||
}
|
||||
}
|
16
vendor/mnapoli/front-yaml/src/YAML/YAMLParser.php
vendored
Normal file
16
vendor/mnapoli/front-yaml/src/YAML/YAMLParser.php
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Mni\FrontYAML\YAML;
|
||||
|
||||
/**
|
||||
* Interface of a YAML parser
|
||||
*/
|
||||
interface YAMLParser
|
||||
{
|
||||
/**
|
||||
* Parses a YAML string.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function parse(string $yaml);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue