mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
FIX Allow multi-line headers
This commit is contained in:
parent
ded5432ec0
commit
c00570ae55
@ -527,22 +527,29 @@ class DocumentationParser
|
||||
*
|
||||
* @param DocumentationPage
|
||||
*/
|
||||
public static function retrieve_meta_data(DocumentationPage &$page)
|
||||
public static function retrieve_meta_data(DocumentationPage $page)
|
||||
{
|
||||
if ($md = $page->getMarkdown()) {
|
||||
$matches = preg_match_all(
|
||||
'/
|
||||
(?<key>[A-Za-z0-9_-]+):
|
||||
\s*
|
||||
(?<value>.*)
|
||||
/x', $md, $meta
|
||||
);
|
||||
|
||||
if ($matches) {
|
||||
foreach ($meta['key'] as $index => $key) {
|
||||
if (isset($meta['value'][$index])) {
|
||||
$page->setMetaData($key, $meta['value'][$index]);
|
||||
$md = $page->getMarkdown();
|
||||
if ($md) {
|
||||
// get the text up to the first empty line
|
||||
$extPattern = "/^(.+)\n\r*\n/Uis";
|
||||
$matches = preg_match($extPattern, $md, $block);
|
||||
|
||||
if ($matches && $block[1]) {
|
||||
|
||||
// find the key/value pairs
|
||||
$lines = preg_split('/\v+/', $block[1]);
|
||||
$key = '';
|
||||
$value = '';
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, ':') !== false) {
|
||||
list($key, $value) = explode(':', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
} else {
|
||||
$value .= ' ' . trim($line);
|
||||
}
|
||||
$page->setMetaData($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -281,24 +281,28 @@ class DocumentationPage extends ViewableData
|
||||
public function populateMetaDataFromText(&$md, $removeMetaData = false)
|
||||
{
|
||||
if ($md) {
|
||||
// get the text up to the first whiteline
|
||||
$extPattern = "/^(.+)\n(\r)*\n/Uis";
|
||||
// get the text up to the first empty line
|
||||
$extPattern = "/^(.+)\n\r*\n/Uis";
|
||||
$matches = preg_match($extPattern, $md, $block);
|
||||
|
||||
if ($matches && $block[1]) {
|
||||
$metaDataFound = false;
|
||||
|
||||
// find the key/value pairs
|
||||
$intPattern = '/(?<key>[A-Za-z][A-Za-z0-9_-]+)[\t]*:[\t]*(?<value>[^:\n\r\/]+)/x';
|
||||
$matches = preg_match_all($intPattern, $block[1], $meta);
|
||||
|
||||
foreach ($meta['key'] as $index => $key) {
|
||||
if (isset($meta['value'][$index])) {
|
||||
// check if a property exists for this key
|
||||
if (property_exists(get_class(), $key)) {
|
||||
$this->$key = $meta['value'][$index];
|
||||
$metaDataFound = true;
|
||||
}
|
||||
$lines = preg_split('/\v+/', $block[1]);
|
||||
$key = '';
|
||||
$value = '';
|
||||
foreach ($lines as $line) {
|
||||
if (strpos($line, ':') !== false) {
|
||||
list($key, $value) = explode(':', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
} else {
|
||||
$value .= ' ' . trim($line);
|
||||
}
|
||||
if (property_exists(get_class(), $key)) {
|
||||
$this->$key = $value;
|
||||
$metaDataFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -399,6 +399,8 @@ HTML;
|
||||
|
||||
$this->assertEquals('Dr. Foo Bar.', $this->metaDataPage->author);
|
||||
$this->assertEquals("Foo Bar's Test page.", $this->metaDataPage->getTitle());
|
||||
$this->assertEquals("Foo Bar's Test page.", $this->metaDataPage->getTitle());
|
||||
$this->assertEquals("A long intro that splits over many lines", $this->metaDataPage->getIntroduction());
|
||||
}
|
||||
|
||||
public function testRewritingRelativeLinksToFiles()
|
||||
|
@ -1,5 +1,8 @@
|
||||
Title: Foo Bar's Test page.
|
||||
Author: Dr. Foo Bar.
|
||||
Another: Test.
|
||||
Introduction: A long intro that
|
||||
splits over
|
||||
many lines
|
||||
|
||||
# Content
|
||||
|
Loading…
Reference in New Issue
Block a user