mirror of
https://github.com/pattern-lab/patternlab-php.git
synced 2025-01-17 22:29:12 +01:00
moving the documentation parser
This commit is contained in:
parent
6d145d5034
commit
2bd8e52a7d
@ -1,25 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*!
|
||||
* Pattern Lab Pattern Documentation Parser Class - v0.7.12
|
||||
* Documentation Parser Class
|
||||
*
|
||||
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
|
||||
* Licensed under the MIT license
|
||||
*
|
||||
* Parses any .md files the Pattern Data rules find. Returns the data
|
||||
*
|
||||
*/
|
||||
|
||||
namespace PatternLab;
|
||||
namespace PatternLab\Parsers;
|
||||
|
||||
use \Symfony\Component\Yaml\Yaml;
|
||||
use \Michelf\MarkdownExtra;
|
||||
|
||||
class DocumentationParser {
|
||||
class Documentation {
|
||||
|
||||
protected static $lineEndingsSet = false;
|
||||
|
||||
/**
|
||||
* Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
|
||||
* @param {String} the file that generated the error
|
||||
* Convert markdown data into proper mark-up
|
||||
* @param {String} the text to be converted
|
||||
*
|
||||
* @return {String} the converted mark-up
|
||||
*/
|
||||
public static function convertMarkdown($text) {
|
||||
$markdown = MarkdownExtra::defaultTransform($text);
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse YAML data into an array
|
||||
* @param {String} the text to be parsed
|
||||
*
|
||||
* @return {Array} the parsed content
|
||||
*/
|
||||
public static function convertYAML($text) {
|
||||
$yaml = Yaml::parse($text);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only the relevant YAML from the given text
|
||||
* @param {String} the text to be parsed
|
||||
*
|
||||
* @return {Array} the parsed content
|
||||
*/
|
||||
public static function getYAML($text) {
|
||||
list($yaml,$markdown) = self::parse($text);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only the relevant converted markdown from the given text
|
||||
* @param {String} the text to be parsed
|
||||
*
|
||||
* @return {Array} the parsed content
|
||||
*/
|
||||
public static function getMarkdown($text) {
|
||||
list($yaml,$markdown) = self::parse($text);
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and convert YAML and markdown in Pattern Lab documention files
|
||||
* @param {String} the text to be chunked for YAML and markdown
|
||||
*
|
||||
* @return {Array} array containing both the YAML and converted markdown
|
||||
*/
|
||||
public static function parse($text) {
|
||||
|
||||
@ -65,29 +113,8 @@ class DocumentationParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
|
||||
* @param {String} the file that generated the error
|
||||
* Set the proper line endings so the text can be parsed properly
|
||||
*/
|
||||
public static function convertMarkdown($text) {
|
||||
$markdown = MarkdownExtra::defaultTransform($text);
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
public static function convertYAML($text) {
|
||||
$yaml = Yaml::parse($text);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
public static function getYAML($text) {
|
||||
list($yaml,$markdown) = self::parse($text);
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
public static function getMarkdown($text) {
|
||||
list($yaml,$markdown) = self::parse($text);
|
||||
return $markdown;
|
||||
}
|
||||
|
||||
protected static function setLineEndings() {
|
||||
if (!self::$lineEndingsSet) {
|
||||
ini_set("auto_detect_line_endings", true);
|
Loading…
x
Reference in New Issue
Block a user