online version of the infoZettel
This commit is contained in:
@@ -69,13 +69,14 @@ class AppCard{
|
||||
*
|
||||
* @return string html code for the AppCard
|
||||
*/
|
||||
public function htmlCode(){
|
||||
public function htmlCode($options=[]){
|
||||
$extraClass = $options['extraClass'] ?? "";
|
||||
$actionListCode = "";
|
||||
foreach($this->actionList as $a){
|
||||
$actionListCode .= $a->htmlCode();
|
||||
}
|
||||
return
|
||||
"<div style=\"padding:1%;\" class=\"col s12 m6\">".
|
||||
"<div style=\"padding:1%;\" class=\"col s12 m6 ".$extraClass."\">".
|
||||
"<div style=\"margin:1%;\" class=\"card blue-grey darken-1\">".
|
||||
(($this->link!=null)?("<a href=\"".$this->appLink."\">"):(""))."<div class=\"card-content white-text\">".
|
||||
"<span class=\"card-title\">".$this->title."</span>".
|
||||
@@ -155,4 +156,53 @@ if( !empty($anRetMessage) ){
|
||||
$retHtmlString .= "</div>";
|
||||
}
|
||||
return $retHtmlString;
|
||||
}?>
|
||||
}
|
||||
|
||||
/**
|
||||
* load a MarkdownFile with yaml header
|
||||
*
|
||||
* @param string $fileName filename of the markdown file
|
||||
* @return array assocative array('yaml'=>array(..), 'mdText'=>string) containing the yamlHeader as associative array and the markdown text as string
|
||||
*/
|
||||
function loadMarkdownFile($fileName){
|
||||
// load the whole file
|
||||
$fileText = file_get_contents($fileName);
|
||||
// split at '---' to get ((),yamls,array)
|
||||
$fileParts = preg_split('/[\n]*[-]{3}[\n]/', $fileText, 3);
|
||||
// not all mdfiles have a yamlHeader, so the mdText can be at different indices
|
||||
$yaml=[];
|
||||
$mdText = "";
|
||||
switch( count($fileParts) ){
|
||||
case 1:{
|
||||
$mdText = $fileParts[0];
|
||||
break;
|
||||
}
|
||||
case 3:{
|
||||
$yaml = Spyc::YAMLLoadString($fileParts[1]);
|
||||
$mdText = $fileParts[2];
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
$mdText = $fileText;
|
||||
}
|
||||
|
||||
}
|
||||
// get a title, if none is in the markdown
|
||||
if(!array_key_exists('title', $yaml)){
|
||||
// find the first heading, set it as header and remove it from the markdown
|
||||
if( preg_match("/^#(.*)$/m", $mdText, $matches) ){
|
||||
$yaml['title'] = $matches[1];
|
||||
$mdText = preg_replace("/^#(.*)$/m", "", $mdText, 1);
|
||||
}
|
||||
else{
|
||||
// fallback for the title, if not even one heading is found
|
||||
$yaml['title'] = "<fehlender Titel>";
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'yaml' => $yaml
|
||||
, 'mdText' => $mdText
|
||||
);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user