Parse the given tag with context informations.

@return string Returns the parsed tag value.
161999
private function parseTag($tag, $context)
    {
        // ensure tag is an object
        $this->instantiatTag($tag);
        // extract context
        $value = isset($context['value']) ? $context['value'] : false;
        $sub = isset($context['sub']) ? $context['sub'] : false;
        // the sub value can contain escaped values, those values must be parsed back into the original state.
        if ($sub) {
            $sub = str_replace(['\)', '\('], [')', '('], $sub);
        }
        // run parse method inside the tag object.
        return $this->tags[$tag]->parse($value, $sub);
    }
1234621
public function parseMarkup()
    {
        $extension = strtolower(File::extension($this->fileName));

        switch ($extension) {
            case 'txt':
                $result = htmlspecialchars($this->markup);
                break;
            case 'md':
                $result = Markdown::parse($this->markup);
                break;
            default:
                $result = $this->markup;
        }

        return $result;
    }
1199966
protected function getInsensitiveTag()
    {
        $tag = new SwatHtmlTag('span');

        $tag->id = $this->id;
        $tag->class = $this->getCSSClassString();

        if ($this->tooltip !== null) {
            $tag->title = $this->tooltip;
        }

        return $tag;
    }
1169177
protected boolean parse(ParsingContext context) {
		try {
			context.getParserInterceptor().openContext(context);
			boolean specialTagFound = false;
			final String lineSeparator = getLineSeparator();
			while (context.getMatcher().find()) {
				int groupIndex = findFirstGroup(context.getMatcher(), 0);
				final String tagName = context.getMatcher().group(groupIndex);
				if (lineSeparator.equals(tagName)) {
					context.incrementLineNo();
					continue;
				}
				final Tag tag = getTagForPattern(tagName);
				if (tag != null) {
					if (tag.isActive(context)) {
						final String tagDynamicName;
						if (tag.hasDynamicName()) {
							final OutParameter<String> dname = new OutParameter<>();
							extractDynamicName(tag, tagName, dname);
							tagDynamicName = dname.get();
						} else {
							tagDynamicName = null;
						}
						final String parameterValue;
						if (tag.hasParameter()) {
							groupIndex = findFirstGroup(context.getMatcher(), groupIndex);
							final String parameter = Strings.nullToEmpty(context.getMatcher().group(groupIndex));
							final ContentParserInterceptor subInterceptor = new ContentParserInterceptor(context.getParserInterceptor());
							final boolean inBlock = context.setInBlock(false);
							final boolean inParam = context.setInParameter(true);
							parse(parameter, context.getCurrentFile(),
									context.getMatcher().start(groupIndex) + context.getStartIndex(),
									context.getStage(),
									context,
									subInterceptor);
							context.setInParameter(inParam);
							context.setInBlock(inBlock);
							parameterValue = Strings.emptyToNull(subInterceptor.getResult());
						} else {
							parameterValue = null;
						}
						final String blockContent;
						if (tag.isOpeningTag()) {
							groupIndex = findFirstGroup(context.getMatcher(), groupIndex);
							final String tagContent = context.getMatcher().group(groupIndex);
							final ContentParserInterceptor subInterceptor = new ContentParserInterceptor(context.getParserInterceptor());
							final boolean inBlock = context.setInBlock(true);
							final boolean inParam = context.setInParameter(false);
							context.setVisibleInBlock(false);
							parse(Strings.nullToEmpty(tagContent), context.getCurrentFile(),
									context.getMatcher().start(groupIndex) + context.getStartIndex(),
									context.getStage(),
									context,
									subInterceptor);
							context.setInParameter(inParam);
							context.setInBlock(inBlock);
							blockContent = Strings.nullToEmpty(subInterceptor.getResult());
						} else {
							blockContent = null;
						}
						specialTagFound = true;
						try {
							context.getParserInterceptor().tag(context, tag, tagDynamicName, parameterValue, blockContent);
						} catch (Throwable exception) {
							reportError(context, Messages.SarlDocumentationParser_6, tagName, exception);
							return false;
						}
					} else {
						// Ignore the tag for this stage.
					}
				} else {
					reportError(context, Messages.SarlDocumentationParser_1, tagName);
					return false;
				}
			}
			context.getParserInterceptor().closeContext(context);
			return specialTagFound;
		} catch (ParsingException exception) {
			throw exception;
		} catch (Throwable exception) {
			final Throwable rootException = Throwables.getRootCause(exception);
			throw new ParsingException(
					rootException.getClass().getName() + " - " + rootException.getLocalizedMessage(), //$NON-NLS-1$
					context.getCurrentFile(),
					context.getLineNo(),
					rootException);
		}
	}
212000
public function getAllTagsText(): string
    {
        $examples = [];

        foreach (get_class_methods($this) as $method) {
            $reflection = new ReflectionMethod($this, $method);
            if ($reflection->isPublic() && !in_array($method, self::$public_but_not_allowed, true) && (string) $reflection->getReturnType() !== Builder::class) {
                $examples[$method] = $method;
            }
        }

        ksort($examples);

        return implode('<br>', $examples);
    }
256247
public function tag()
    {
        $tag = $this->getCurrentTag();

        if ($tag) {
            $this->blogPosts = $tag->BlogPosts();

            if ($this->isRSS()) {
                return $this->rssFeed($this->blogPosts, $tag->getLink());
            } else {
                return $this->render();
            }
        }

        $this->httpError(404, 'Not Found');

        return null;
    }
1295199
private function parseXml(\DOMNode $node, array $context = [])
    {
        $data = $this->parseXmlAttributes($node, $context);

        $value = $this->parseXmlValue($node, $context);

        if (!\count($data)) {
            return $value;
        }

        if (!\is_array($value)) {
            $data['#'] = $value;

            return $data;
        }

        if (1 === \count($value) && key($value)) {
            $data[key($value)] = current($value);

            return $data;
        }

        foreach ($value as $key => $val) {
            $data[$key] = $val;
        }

        return $data;
    }
491109
protected function captureEndTag()
	{
		if (empty($this->uppercaseText))
		{
			$this->uppercaseText = strtoupper($this->text);
		}
		$match     = '[/' . $this->bbcodeName . $this->bbcodeSuffix . ']';
		$endTagPos = strpos($this->uppercaseText, $match, $this->pos);
		if ($endTagPos === false)
		{
			return;
		}

		return $this->parser->addEndTag($this->getTagName(), $endTagPos, strlen($match));
	}
385389
public static function encode(TagContext $tagContext): string
    {
        $str = self::TAGS_VERSION_ID;
        /** @var Tag $tag */
        foreach ($tagContext->tags() as $tag) {
            $str .= self::KEYTYPE_STRING;
            $key = $tag->getKey()->getName();
            $buf = '';
            self::encodeUnsigned($buf, strlen($key));
            $str .= $buf . $key;
            $value = $tag->getValue()->getValue();
            $buf = '';
            self::encodeUnsigned($buf, strlen($value));
            $str .= $buf . $value;
        }
        return $str;
    }
861072
public static function parse(Tag &$Tag)
    {
        if (!empty($Tag->content) && $Tag->hasOption('translate') && is_callable(Config::get('translator'))) {
            $Tag->content = call_user_func_array(
                Config::get('translator'),
                array(
                    $Tag->content,
                    Config::get('textdomain')
                )
            );
        }
        
        if ($Tag->hasOption('bbContent')) {
            self::bb($Tag->content);
        }

        if ($Tag->hasOption('markdown')) {
            $Tag->addOption('cleanContent');
            self::markdown($Tag->content);
        }

        if ($Tag->hasOption('compress')) {
            self::compress($Tag);
        }

        return $Tag->content;
    }
31621
public function parse()
    {
        if (isset($this->raw->data)) {
            $this->setData($this->raw->data);
        }

        if (isset($this->raw->included)) {
            $this->setIncluded($this->raw->included);
        }

        if (isset($this->raw->links)) {
            $this->setLinks($this->raw->links);
        }

        if (isset($this->raw->meta)) {
            $this->setMeta($this->raw->meta);
        }

        if (isset($this->raw->errors)) {
            $this->setErrors($this->raw->errors);
        }

        return $this;
    }
411779
protected function parse()
    {
        $this->output = '';

        // Drop tags
        $this->parser->html = preg_replace('#<(' . implode('|', $this->drop) . ')[^>]*>.*</\\1>#sU', '', $this->parser->html);
        while ($this->parser->nextNode()) {
            switch ($this->parser->nodeType) {
                case 'doctype':
                    break;
                case 'pi':
                case 'comment':
                    if ($this->keepHTML) {
                        $this->flushLinebreaks();
                        $this->out($this->parser->node);
                        $this->setLineBreaks(2);
                    }
                    // else drop
                    break;
                case 'text':
                    $this->handleText();
                    break;
                case 'tag':
                    if (in_array($this->parser->tagName, $this->ignore)) {
                        break;
                    }
                    // If the previous tag was not a block element, we simulate a paragraph tag
                    if ($this->parser->isBlockElement && $this->parser->isNextToInlineContext && !in_array($this->parent(), $this->allowMixedChildren)) {
                        $this->setLineBreaks(2);
                    }
                    if ($this->parser->isStartTag) {
                        $this->flushLinebreaks();
                    }
                    if ($this->skipConversion) {
                        $this->isMarkdownable(); // update notConverted
                        $this->handleTagToText();
                        break;
                    }

                    // block elements
                    if (!$this->parser->keepWhitespace && $this->parser->isBlockElement) {
                        $this->fixBlockElementSpacing();
                    }

                    // inline elements
                    if (!$this->parser->keepWhitespace && $this->parser->isInlineContext) {
                        $this->fixInlineElementSpacing();
                    }

                    if ($this->isMarkdownable()) {
                        if ($this->parser->isBlockElement && $this->parser->isStartTag && !$this->lastWasBlockTag && !empty($this->output)) {
                            if (!empty($this->buffer)) {
                                $str =& $this->buffer[count($this->buffer) - 1];
                            } else {
                                $str =& $this->output;
                            }
                            if (substr($str, -strlen($this->indent) - 1) != "\n" . $this->indent) {
                                $str .= "\n" . $this->indent;
                            }
                        }
                        $func = 'handleTag_' . $this->parser->tagName;
                        $this->$func();
                        if ($this->linkPosition == self::LINK_AFTER_PARAGRAPH && $this->parser->isBlockElement && !$this->parser->isStartTag && empty($this->parser->openTags)) {
                            $this->flushFootnotes();
                        }
                        if (!$this->parser->isStartTag) {
                            $this->lastClosedTag = $this->parser->tagName;
                        }
                    } else {
                        $this->handleTagToText();
                        $this->lastClosedTag = '';
                    }
                    break;
                default:
                    trigger_error('invalid node type', E_USER_ERROR);
                    break;
            }
            $this->lastWasBlockTag = $this->parser->nodeType == 'tag' && $this->parser->isStartTag && $this->parser->isBlockElement;
        }
        if (!empty($this->buffer)) {
            // trigger_error('buffer was not flushed, this is a bug. please report!', E_USER_WARNING);
            while (!empty($this->buffer)) {
                $this->out($this->unbuffer());
            }
        }
        // cleanup
        $this->output = rtrim(str_replace('&amp;', '&', str_replace('&lt;', '<', str_replace('&gt;', '>', $this->output))));
        // end parsing, flush stacked tags
        $this->flushFootnotes();
        $this->stack = [];
    }
1241694
private function loadTagContent(): ?string
    {
        $contents = [];
        $nextOrClosingPos = $this->file->findNext([T_DOC_COMMENT_CLOSE_TAG, T_DOC_COMMENT_TAG], $this->stackPos + 1);
        $positionsTillEnd = TokenHelper::findNextAll($this->file->getBaseFile(), [T_DOC_COMMENT_STRING], $this->stackPos, $nextOrClosingPos);

        foreach ($positionsTillEnd as $position) {
            $contents[] = $this->tokens[$position]['content'];
        }

        return $contents ? implode(' ', $contents) : null;
    }
630565
public function getAssignedTags()
    {
        if ($this->_assignedTags === null) {
            $ids = ArrayHelper::getColumn($this->getContextConfigValue($this->varName, []), 'value');
            $this->_assignedTags = Tag::find()->where(['in','id', $ids])->indexBy('name')->all();
        }
        
        return $this->_assignedTags;
    }
1109217
public function getParsedContents()
    {
        if (null === $this->parsedContents) {
            $this->parsedContents = preg_split(
                '/\{
                    # "{@}" is not a valid inline tag. This ensures that
                    # we do not treat it as one, but treat it literally.
                    (?!@\})
                    # We want to capture the whole tag line, but without the
                    # inline tag delimiters.
                    (\@
                        # Match everything up to the next delimiter.
                        [^{}]*
                        # Nested inline tag content should not be captured, or
                        # it will appear in the result separately.
                        (?:
                            # Match nested inline tags.
                            (?:
                                # Because we did not catch the tag delimiters
                                # earlier, we must be explicit with them here.
                                # Notice that this also matches "{}", as a way
                                # to later introduce it as an escape sequence.
                                \{(?1)?\}
                                |
                                # Make sure we match hanging "{".
                                \{
                            )
                            # Match content after the nested inline tag.
                            [^{}]*
                        )* # If there are more inline tags, match them as well.
                           # We use "*" since there may not be any nested inline
                           # tags.
                    )
                \}/Sux',
                $this->contents,
                null,
                PREG_SPLIT_DELIM_CAPTURE
            );

            $count = count($this->parsedContents);
            for ($i=1; $i<$count; $i += 2) {
                $this->parsedContents[$i] = Tag::createInstance(
                    $this->parsedContents[$i],
                    $this->docblock
                );
            }

            //In order to allow "literal" inline tags, the otherwise invalid
            //sequence "{@}" is changed to "@", and "{}" is changed to "}".
            //See unit tests for examples.
            for ($i=0; $i<$count; $i += 2) {
                $this->parsedContents[$i] = str_replace(
                    array('{@}', '{}'),
                    array('@', '}'),
                    $this->parsedContents[$i]
                );
            }
        }
        return $this->parsedContents;
    }
78451
public function getTag()
    {
        $piwikUrl = $this->getPiwikUrl();

        $tag = <<<'EOT'
<script type="text/javascript">
var _paq = _paq || [];
(function(){ var u=(("https:" == document.location.protocol) ? "%s/" : "%s/");
_paq.push(['setSiteId', %s]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
s.parentNode.insertBefore(g,s); })();
</script>
<!-- End Piwik Code -->
EOT;

        return sprintf(
            $tag,
            $this->convertUrl($piwikUrl, true),
            $this->convertUrl($piwikUrl, false),
            $this->getSiteId()
        );
    }
1248610
public function parse()
	{
		while (($this->position = strpos($this->data, '&', $this->position)) !== false)
		{
			$this->consume();
			$this->entity();
			$this->consumed = '';
		}
		return $this->data;
	}