diff --git a/hosts/localhost/index.md b/hosts/localhost/index.md index 0e8baec..217dc05 100644 --- a/hosts/localhost/index.md +++ b/hosts/localhost/index.md @@ -1,4 +1,7 @@ -PHP MarkDown document manager, Free & OpenSource :heart_eyes: for easily create your documentation website** +# MarkDoc + +**PHP MarkDown document manager, Free & OpenSource :heart_eyes: for easily create your documentation website** + ``` __ __ _ _____ | \/ | | | | __ \ diff --git a/index.php b/index.php index 933ae74..2ca0267 100644 --- a/index.php +++ b/index.php @@ -21,6 +21,7 @@ define('LOG_DIR', HOST_DIR.LOG_FILE); define('HISTORY_DIR', HOST_DIR.HISTORY_FILE); include LIB_DIR."/Parsedown.php"; include LIB_DIR."/ParsedownExtra.php"; +include LIB_DIR."/ParsedownExtraPlus.php"; include LIB_DIR."/functions.php"; ### Security diff --git a/js/functionsadmin.js b/js/functionsadmin.js index 9bdae3f..5f90581 100644 --- a/js/functionsadmin.js +++ b/js/functionsadmin.js @@ -143,9 +143,11 @@ $(function(){ $("#save").click(function(e){ - e.preventDefault(); - file="/"+$("#files").jstree("get_path",nodes.node,"/").replace(/^.+?[/]/, ''); - if ($("#files").jstree("is_leaf",nodes.node)) + e.preventDefault(); + viewfile=""; + node=$("#files").jstree("get_selected"); + file="/"+$("#files").jstree("get_path",node,"/").replace(/^.+?[/]/, ''); + if ($("#files").jstree("is_leaf",node)) { data = editor.value(); $.ajax({ diff --git a/lib/Parsedown.php b/lib/Parsedown.php index 20142be..1b9d6d5 100644 --- a/lib/Parsedown.php +++ b/lib/Parsedown.php @@ -1081,11 +1081,6 @@ class Parsedown continue; } - if (isset($Inline['addon'])) - { - $markup .= $Inline['addon']; - } - # makes sure that the inline belongs to "our" marker if (isset($Inline['position']) and $Inline['position'] > $markerPosition) @@ -1114,8 +1109,7 @@ class Parsedown $markup .= $this->unmarkedText($unmarkedText); # compile the inline - if (isset($Inline['element'])) - $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); + $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); # remove the examined text $text = substr($text, $Inline['position'] + $Inline['extent']); @@ -1254,19 +1248,6 @@ class Parsedown ), ); - $modifier = explode('?', $Inline['element']['attributes']['src'], 2)[1] ?? ""; - list($size,$align) = explode('-', $modifier, 2); - $width = $height = 0; - if (preg_match('/^\d+x\d+$/', $size)) { - list($width, $height) = explode('x', $size); - } - if (preg_match('/^\d+$/', $size)) { - $width = $size; - } - if($width > 0) $Inline['element']['attributes']['width'] = $width; - if($height > 0) $Inline['element']['attributes']['height'] = $height; - if($align !="" ) $Inline['element']['attributes']['align'] = $align; - $Inline['element']['attributes'] += $Link['element']['attributes']; unset($Inline['element']['attributes']['href']); @@ -1339,20 +1320,6 @@ class Parsedown $Element['attributes']['href'] = $Definition['url']; $Element['attributes']['title'] = $Definition['title']; } - if ($Element['attributes']['href']=="tags") - { - $addon='
'; - $items=explode(" ",$Element['text']); - foreach($items as $item) - { - $addon.=''.$item.''; - } - $addon.='
'; - return array( - 'addon' => $addon, - 'extent' => $extent - ); - } return array( 'extent' => $extent, diff --git a/lib/ParsedownExtraPlus.php b/lib/ParsedownExtraPlus.php new file mode 100644 index 0000000..28e59bb --- /dev/null +++ b/lib/ParsedownExtraPlus.php @@ -0,0 +1,236 @@ +inlineMarkerList)) + { + $marker = $excerpt[0]; + + $markerPosition = strpos($text, $marker); + + $Excerpt = array('text' => $excerpt, 'context' => $text); + + foreach ($this->InlineTypes[$marker] as $inlineType) + { + # check to see if the current inline type is nestable in the current context + + if ( ! empty($nonNestables) and in_array($inlineType, $nonNestables)) + { + continue; + } + + $Inline = $this->{'inline'.$inlineType}($Excerpt); + + if ( ! isset($Inline)) + { + continue; + } + + if (isset($Inline['addon'])) + { + $markup .= $Inline['addon']; + } + + # makes sure that the inline belongs to "our" marker + + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) + { + continue; + } + + # sets a default inline position + + if ( ! isset($Inline['position'])) + { + $Inline['position'] = $markerPosition; + } + + # cause the new element to 'inherit' our non nestables + + foreach ($nonNestables as $non_nestable) + { + $Inline['element']['nonNestables'][] = $non_nestable; + } + + # the text that comes before the inline + $unmarkedText = substr($text, 0, $Inline['position']); + + # compile the unmarked text + $markup .= $this->unmarkedText($unmarkedText); + + # compile the inline + if (isset($Inline['element'])) + $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); + + # remove the examined text + $text = substr($text, $Inline['position'] + $Inline['extent']); + + continue 2; + } + + # the marker does not belong to an inline + + $unmarkedText = substr($text, 0, $markerPosition + 1); + + $markup .= $this->unmarkedText($unmarkedText); + + $text = substr($text, $markerPosition + 1); + } + + $markup .= $this->unmarkedText($text); + + return $markup; + } + + protected function inlineImage($Excerpt) + { + if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') + { + return; + } + + $Excerpt['text']= substr($Excerpt['text'], 1); + + $Link = $this->inlineLink($Excerpt); + + if ($Link === null) + { + return; + } + + $Inline = array( + 'extent' => $Link['extent'] + 1, + 'element' => array( + 'name' => 'img', + 'attributes' => array( + 'src' => $Link['element']['attributes']['href'], + 'alt' => $Link['element']['text'], + ), + ), + ); + + $modifier = explode('?', $Inline['element']['attributes']['src'], 2)[1] ?? ""; + list($size,$align) = explode('-', $modifier, 2); + $width = $height = 0; + if (preg_match('/^\d+x\d+$/', $size)) { + list($width, $height) = explode('x', $size); + } + if (preg_match('/^\d+$/', $size)) { + $width = $size; + } + if($width > 0) $Inline['element']['attributes']['width'] = $width; + if($height > 0) $Inline['element']['attributes']['height'] = $height; + if($align !="" ) $Inline['element']['attributes']['align'] = $align; + + $Inline['element']['attributes'] += $Link['element']['attributes']; + + unset($Inline['element']['attributes']['href']); + + return $Inline; + } + + protected function inlineLink($Excerpt) + { + $Element = array( + 'name' => 'a', + 'handler' => 'line', + 'nonNestables' => array('Url', 'Link'), + 'text' => null, + 'attributes' => array( + 'href' => null, + 'title' => null, + ), + ); + + $extent = 0; + + $remainder = $Excerpt['text']; + + if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) + { + $Element['text'] = $matches[1]; + + $extent += strlen($matches[0]); + + $remainder = substr($remainder, $extent); + } + else + { + return; + } + + if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) + { + $Element['attributes']['href'] = $matches[1]; + + if (isset($matches[2])) + { + $Element['attributes']['title'] = substr($matches[2], 1, - 1); + } + + $extent += strlen($matches[0]); + } + else + { + if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) + { + $definition = strlen($matches[1]) ? $matches[1] : $Element['text']; + $definition = strtolower($definition); + + $extent += strlen($matches[0]); + } + else + { + $definition = strtolower($Element['text']); + } + + if ( ! isset($this->DefinitionData['Reference'][$definition])) + { + return; + } + + $Definition = $this->DefinitionData['Reference'][$definition]; + + $Element['attributes']['href'] = $Definition['url']; + $Element['attributes']['title'] = $Definition['title']; + } + if ($Element['attributes']['href']=="tags") + { + $addon='
'; + $items=explode(" ",$Element['text']); + foreach($items as $item) + { + $addon.=''.$item.''; + } + $addon.='
'; + return array( + 'addon' => $addon, + 'extent' => $extent + ); + } + + return array( + 'extent' => $extent, + 'element' => $Element, + ); + } + + +} diff --git a/lib/functions.php b/lib/functions.php index f55b7c8..04deb4c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -69,7 +69,7 @@ function specialurl($url) Based on Pheditor "PHP file editor" By Hamid Samak Release under MIT license 2020 par Nicolas H.'; - $extra = new ParsedownExtra(); + $extra = new ParsedownExtraplus(); print($extra->text($content)); exit; case ':ADMIN': @@ -239,7 +239,7 @@ function getcontent($url,$md=true) } if ($md==true) { - $extra = new ParsedownExtra(); + $extra = new ParsedownExtraplus(); return $extra->text($content); } else diff --git a/readme.md b/readme.md index 7182da9..fade8d2 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MarkDoc -PHP MarkDown document manager, Free & OpenSource :heart_eyes: for easily create your documentation website** +**PHP MarkDown document manager, Free & OpenSource :heart_eyes: for easily create your documentation website** ``` __ __ _ _____ | \/ | | | | __ \