Skip to content

Commit

Permalink
Synced to 15b61f6
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 10, 2017
1 parent 2bcb84e commit 804ed8f
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 476 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s9e/text-formatter",
"version": "0.13.0",
"version": "0.13.1",
"type": "library",
"description": "Multi-purpose text formatting and markup library. Plugins offer support for BBCodes, Markdown, emoticons, HTML, embedding media (YouTube, etc...), enhanced typography and more.",
"homepage": "https://github.com/s9e/TextFormatter/",
Expand Down
2 changes: 1 addition & 1 deletion src/Bundles/Fatdown.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Bundles/Forum.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Bundles/Forum/Renderer.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Bundles/MediaPack.php

Large diffs are not rendered by default.

582 changes: 304 additions & 278 deletions src/Configurator.php

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Configurator/JavaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function getMinifier()
public function getParser(array $config = \null)
{
$this->configOptimizer->reset();
$this->xsl = (new XSLT)->getXSL($this->configurator->rendering);
$xslt = new XSLT;
$xslt->optimizer->normalizer->remove('RemoveLivePreviewAttributes');
$this->xsl = $xslt->getXSL($this->configurator->rendering);
$this->config = (isset($config)) ? $config : $this->configurator->asConfig();
$this->config = ConfigHelper::filterConfig($this->config, 'JS');
$this->config = $this->callbackGenerator->replaceCallbacks($this->config);
Expand Down
1 change: 1 addition & 0 deletions src/Configurator/JavaScript/HintGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function setPluginsHints()
protected function setRenderingHints()
{
$this->hints['postProcessing'] = (int) (\strpos($this->xsl, 'data-s9e-livepreview-postprocess') !== \false);
$this->hints['ignoreAttrs'] = (int) (\strpos($this->xsl, 'data-s9e-livepreview-ignore-attrs') !== \false);
}
protected function setRulesHints()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/JavaScript/externs.application.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ NamedNodeMap.prototype.length;
function Node() {}
/**
* @param {Node} newChild
* @return {Node}
* @return {!Node}
*/
Node.prototype.appendChild = function(newChild) {};
/**
Expand Down
20 changes: 10 additions & 10 deletions src/Configurator/JavaScript/externs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ function Symbol(opt_description) {}
/**
* @param {string} uri
* @return {string}
* @nosideeffects
* @throws {URIError} when used wrongly.
*/
function decodeURIComponent(uri) {}
/**
* @param {string} uri
* @return {string}
* @nosideeffects
* @throws {URIError} if one attempts to encode a surrogate which is not part of
*/
function encodeURIComponent(uri) {}
/**
Expand Down Expand Up @@ -154,13 +154,13 @@ Array.prototype.shift = function() {};
*/
Array.prototype.slice = function(opt_begin, opt_end) {};
/**
* @param {function(T,T):number=} opt_compareFunction Specifies a function that
* @param {function(T,T):number=} opt_compareFn Specifies a function that
* @this {IArrayLike<T>}
* @template T
* @modifies {this}
* @return {!Array<T>}
*/
Array.prototype.sort = function(opt_compareFunction) {};
Array.prototype.sort = function(opt_compareFn) {};
/**
* @param {*=} opt_index Index at which to start changing the array. If negative, * will begin that many elements from the end. A non-number type will be
* @param {*=} opt_howMany An integer indicating the number of old array elements
Expand Down Expand Up @@ -263,7 +263,7 @@ Object.prototype.toString = function() {};
* @param {*=} opt_pattern
* @param {*=} opt_flags
* @return {!RegExp}
* @nosideeffects
* @throws {SyntaxError} if opt_pattern is an invalid pattern.
*/
function RegExp(opt_pattern, opt_flags) {}
/**
Expand All @@ -282,6 +282,7 @@ RegExp.prototype.lastIndex;
RegExp.prototype.test = function(str) {};
/**
* @constructor
* @implements {Iterable<string>}
* @param {*=} opt_str
* @return {string}
* @nosideeffects
Expand Down Expand Up @@ -321,12 +322,11 @@ String.prototype.indexOf = function(searchValue, opt_fromIndex) {};
String.prototype.length;
/**
* @this {String|string}
* @param {RegExp|string} regex
* @param {string|Function} str
* @param {string=} opt_flags
* @param {RegExp|string} pattern
* @param {string|Function} replacement
* @return {string}
*/
String.prototype.replace = function(regex, str, opt_flags) {};
String.prototype.replace = function(pattern, replacement) {};
/**
* @this {String|string}
* @param {*=} opt_separator
Expand Down Expand Up @@ -420,7 +420,7 @@ NamedNodeMap.prototype.length;
function Node() {}
/**
* @param {Node} newChild
* @return {Node}
* @return {!Node}
*/
Node.prototype.appendChild = function(newChild) {};
/**
Expand Down
1 change: 1 addition & 0 deletions src/Configurator/RendererGenerators/XSLT/Optimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct()
$this->normalizer->append('MergeConsecutiveCopyOf');
$this->normalizer->append('MergeIdenticalConditionalBranches');
$this->normalizer->append('OptimizeNestedConditionals');
$this->normalizer->append('RemoveLivePreviewAttributes');
}
public function optimizeTemplate($template)
{
Expand Down
67 changes: 32 additions & 35 deletions src/Plugins/MediaEmbed/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use RuntimeException;
use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
use s9e\TextFormatter\Configurator\Items\Attribute;
use s9e\TextFormatter\Configurator\Items\AttributeFilters\RegexpFilter;
use s9e\TextFormatter\Configurator\Items\AttributePreprocessor;
use s9e\TextFormatter\Configurator\Items\Tag;
use s9e\TextFormatter\Plugins\ConfiguratorBase;
Expand Down Expand Up @@ -74,8 +73,7 @@ public function asConfig()
public function add($siteId, array $siteConfig = \null)
{
$siteId = $this->normalizeId($siteId);
if (!isset($siteConfig))
$siteConfig = $this->defaultSites->get($siteId);
$siteConfig = (isset($siteConfig)) ? $this->defaultSites->normalizeValue($siteConfig) : $this->defaultSites->get($siteId);
$this->collection[$siteId] = $siteConfig;
$tag = new Tag;
$tag->rules->allowChild('URL');
Expand All @@ -85,40 +83,21 @@ public function add($siteId, array $siteConfig = \null)
$attributes = [
'url' => ['type' => 'url']
];
if (isset($siteConfig['scrape']))
$attributes += $this->addScrapes($tag, $siteConfig['scrape']);
if (isset($siteConfig['extract']))
foreach ((array) $siteConfig['extract'] as $regexp)
{
$attrRegexps = $tag->attributePreprocessors->add('url', $regexp)->getAttributes();
foreach ($attrRegexps as $attrName => $attrRegexp)
$attributes[$attrName]['regexp'] = $attrRegexp;
}
$attributes += $this->addScrapes($tag, $siteConfig['scrape']);
foreach ($siteConfig['extract'] as $regexp)
{
$attrRegexps = $tag->attributePreprocessors->add('url', $regexp)->getAttributes();
foreach ($attrRegexps as $attrName => $attrRegexp)
$attributes[$attrName]['regexp'] = $attrRegexp;
}
if (isset($siteConfig['attributes']))
foreach ($siteConfig['attributes'] as $attrName => $attrConfig)
foreach ($attrConfig as $configName => $configValue)
$attributes[$attrName][$configName] = $configValue;
$hasRequiredAttribute = \false;
foreach ($attributes as $attrName => $attrConfig)
{
$attribute = $tag->attributes->add($attrName);
if (isset($attrConfig['preFilter']))
$this->appendFilter($attribute, $attrConfig['preFilter']);
if (isset($attrConfig['type']))
{
$filter = $this->configurator->attributeFilters['#' . $attrConfig['type']];
$attribute->filterChain->append($filter);
}
elseif (isset($attrConfig['regexp']))
$attribute->filterChain->append(new RegexpFilter($attrConfig['regexp']));
if (isset($attrConfig['required']))
$attribute->required = $attrConfig['required'];
else
$attribute->required = ($attrName === 'id');
if (isset($attrConfig['postFilter']))
$this->appendFilter($attribute, $attrConfig['postFilter']);
if (isset($attrConfig['defaultValue']))
$attribute->defaultValue = $attrConfig['defaultValue'];
$attribute = $this->addAttribute($tag, $attrName, $attrConfig);
$hasRequiredAttribute |= $attribute->required;
}
if (isset($attributes['id']['regexp']))
Expand Down Expand Up @@ -148,16 +127,36 @@ public function appendTemplate($template = '')
{
$this->appendTemplate = $this->configurator->templateNormalizer->normalizeTemplate($template);
}
protected function addAttribute(Tag $tag, $attrName, array $attrConfig)
{
$attribute = $tag->attributes->add($attrName);
if (isset($attrConfig['preFilter']))
$this->appendFilter($attribute, $attrConfig['preFilter']);
if (isset($attrConfig['type']))
{
$filter = $this->configurator->attributeFilters['#' . $attrConfig['type']];
$attribute->filterChain->append($filter);
}
elseif (isset($attrConfig['regexp']))
$attribute->filterChain->append('#regexp')->setRegexp($attrConfig['regexp']);
if (isset($attrConfig['required']))
$attribute->required = $attrConfig['required'];
else
$attribute->required = ($attrName === 'id');
if (isset($attrConfig['postFilter']))
$this->appendFilter($attribute, $attrConfig['postFilter']);
if (isset($attrConfig['defaultValue']))
$attribute->defaultValue = $attrConfig['defaultValue'];
return $attribute;
}
protected function addScrapes(Tag $tag, array $scrapes)
{
if (!isset($scrapes[0]))
$scrapes = [$scrapes];
$attributes = [];
$scrapeConfig = [];
foreach ($scrapes as $scrape)
{
$attrNames = [];
foreach ((array) $scrape['extract'] as $extractRegexp)
foreach ($scrape['extract'] as $extractRegexp)
{
$attributePreprocessor = new AttributePreprocessor($extractRegexp);
foreach ($attributePreprocessor->getAttributes() as $attrName => $attrRegexp)
Expand All @@ -168,8 +167,6 @@ protected function addScrapes(Tag $tag, array $scrapes)
}
$attrNames = \array_unique($attrNames);
\sort($attrNames);
if (!isset($scrape['match']))
$scrape['match'] = '//';
$entry = [$scrape['match'], $scrape['extract'], $attrNames];
if (isset($scrape['url']))
$entry[] = $scrape['url'];
Expand Down
Loading

0 comments on commit 804ed8f

Please sign in to comment.