<commit_before><?php
namespace wcf\system\html\input\node;
use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\system\event\EventHandler;
use wcf\system\html\node\AbstractHtmlNodeProcessor;
use wcf\util\DOMUtil;

/**
 * Transforms bbcode markers into the custom HTML element `<woltlab-metacode>`. This process
 * outputs well-formed markup with proper element nesting.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Html\Input\Node
 * @since	3.0
 */
class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
	/**
	 * list of bbcodes that represent block elements
	 * @var	string[]
	 */
	public $blockElements = [];
	
	/**
	 * list of bbcodes that represent source code elements
	 * @var	string[]
	 */
	public $sourceElements = [];
	
	/**
	 * @inheritDoc
	 */
	protected $tagName = 'woltlab-metacode-marker';
	
	/**
	 * HtmlInputNodeWoltlabMetacodeMarker constructor.
	 */
	public function __construct() {
		$this->blockElements = HtmlBBCodeParser::getInstance()->getBlockBBCodes();
		$this->sourceElements = HtmlBBCodeParser::getInstance()->getSourceBBCodes();
	}
	
	/**
	 * @inheritDoc
	 */
	public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		// metacode-marker isn't present at time of validation
		return [];
	}
	
	/**
	 * @inheritDoc
	 */
	public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		// collect pairs
		$pairs = $this->buildPairs($elements);
		
		// validate pairs and remove items that lack an opening/closing element
		$pairs = $this->validatePairs($pairs);
		
		// group pairs by tag name
		$groups = $this->groupPairsByName($pairs);
		
		$groups = $this->filterGroups($groups, $htmlNodeProcessor);
		if (empty($groups)) {
			return;
		}
		
		// convert source bbcode groups first to ensure no bbcodes inside
		// source blocks will be evaluated
		$groups = $this->convertSourceGroups($groups);
		
		$groups = $this->revertMarkerInsideCodeBlocks($groups, $htmlNodeProcessor);
		
		// convert pairs into HTML or metacode
		$this->convertGroups($groups);
	}
	
	/**
	 * Filters groups by reverting metacode markers for invalid bbcodes.
	 * 
	 * @param       array                           $groups                 grouped list of bbcode marker pairs
	 * @param       AbstractHtmlNodeProcessor       $htmlNodeProcessor      node processor instance
	 * @return      array                           filtered groups
	 */
	protected function filterGroups(array $groups, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		/** @noinspection PhpUndefinedMethodInspection */
		$data = [
			'context' => $htmlNodeProcessor->getContext(),
			'bbcodes' => array_keys($groups)<commit_msg>Fixed method call<commit_after><?php
namespace wcf\system\html\input\node;
use wcf\system\bbcode\HtmlBBCodeParser;
use wcf\system\event\EventHandler;
use wcf\system\html\node\AbstractHtmlNodeProcessor;
use wcf\util\DOMUtil;

/**
 * Transforms bbcode markers into the custom HTML element `<woltlab-metacode>`. This process
 * outputs well-formed markup with proper element nesting.
 * 
 * @author	<NAME>
 * @copyright	2001-2016 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\Html\Input\Node
 * @since	3.0
 */
class HtmlInputNodeWoltlabMetacodeMarker extends AbstractHtmlInputNode {
	/**
	 * list of bbcodes that represent block elements
	 * @var	string[]
	 */
	public $blockElements = [];
	
	/**
	 * list of bbcodes that represent source code elements
	 * @var	string[]
	 */
	public $sourceElements = [];
	
	/**
	 * @inheritDoc
	 */
	protected $tagName = 'woltlab-metacode-marker';
	
	/**
	 * HtmlInputNodeWoltlabMetacodeMarker constructor.
	 */
	public function __construct() {
		$this->blockElements = HtmlBBCodeParser::getInstance()->getBlockBBCodes();
		$this->sourceElements = HtmlBBCodeParser::getInstance()->getSourceBBCodes();
	}
	
	/**
	 * @inheritDoc
	 */
	public function isAllowed(AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		// metacode-marker isn't present at time of validation
		return [];
	}
	
	/**
	 * @inheritDoc
	 */
	public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		// collect pairs
		$pairs = $this->buildPairs($elements);
		
		// validate pairs and remove items that lack an opening/closing element
		$pairs = $this->validatePairs($pairs);
		
		// group pairs by tag name
		$groups = $this->groupPairsByName($pairs);
		
		$groups = $this->filterGroups($groups, $htmlNodeProcessor);
		if (empty($groups)) {
			return;
		}
		
		// convert source bbcode groups first to ensure no bbcodes inside
		// source blocks will be evaluated
		$groups = $this->convertSourceGroups($groups);
		
		$groups = $this->revertMarkerInsideCodeBlocks($groups, $htmlNodeProcessor);
		
		// convert pairs into HTML or metacode
		$this->convertGroups($groups);
	}
	
	/**
	 * Filters groups by reverting metacode markers for invalid bbcodes.
	 * 
	 * @param       array                           $groups                 grouped list of bbcode marker pairs
	 * @param       AbstractHtmlNodeProcessor       $htmlNodeProcessor      node processor instance
	 * @return      array                           filtered groups
	 */
	protected function filterGroups(array $groups, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
		/** @noinspection PhpUndefinedMethodInspection */
		$data = [
			'context' => $htmlNodeProcessor->getHtmlProcessor()->getContext(),
			'bbcodes' => array_keys($groups)
{'fraction_non_alphanumeric': 0.11426543647977289, 'fraction_numerical': 0.0035486160397444995, 'mean_word_length': 3.635690789473684, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '145312', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1591, 'n_words': 407}