src/LittleWikitext.php
/**
	 * Convert markup language to an Abstract Syntax Tree.
	 *
	 * @param string $markup The input markup
	 * @param array $options
	 * @return Root An abstract syntax tree corresponding to the input
	 */
Convert markup language to an Abstract Syntax Tree.
@param string $markup The input markup
@param array $options
@return Root An abstract syntax tree corresponding to the input
Convert markup language to an Abstract Syntax Tree . @param string $markup The input markup @param array $options @return Root An abstract syntax tree corresponding to the input
public static function markup2ast( string $markup, array $options = [] ): Root {
		$root = Grammar::load( "$markup\n" );
		$lastSection = $root->getLastChild();
		$last = $lastSection ? $lastSection->getLastChild() : null;
		if ( $last instanceof Paragraph && $last->toMarkup() === '' ) {
			'@phan-var Section $lastSection'; 
			$children = $root->getChildren();
			array_splice( $children, -1, 1, [
				new Section(
					$lastSection->getHeading(),
					array_slice(
						$lastSection->getChildren(),
						0, -1
					)
				)
			] );
			$root = new Root( $children );
		}
		return $root;
	}
public static function markup2ast ( string $ markup , array $ options = [ ] ) : Root { $ root = Grammar :: load ( " $ markup \n " ) ; $ lastSection = $ root -> getLastChild ( ) ; $ last = $ lastSection ? $ lastSection -> getLastChild ( ) : null ; if ( $ last instanceof Paragraph && $ last -> toMarkup ( ) === '' ) { '@phan-var Section $lastSection' ; $ children = $ root -> getChildren ( ) ; array_splice ( $ children , - 1 , 1 , [ new Section ( $ lastSection -> getHeading ( ) , array_slice ( $ lastSection -> getChildren ( ) , 0 , - 1 ) ) ] ) ; $ root = new Root ( $ children ) ; } return $ root ; }
Convert markup language to an Abstract Syntax Tree.
Convert markup language to an Abstract Syntax Tree .
// Ensure every line is terminated with a newline. // But strip the trailing blank line if one was added // @var Section $lastSection