From: Nicolas Boisselier Date: Tue, 29 Nov 2016 00:27:16 +0000 (+0000) Subject: bdq X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=1c731db90b33a79270e8349e77ff26fba8dec353;p=nb.git bdq --- diff --git a/lib/php/db/page.php b/lib/php/db/page.php index 6f2056d2..bb098f5b 100644 --- a/lib/php/db/page.php +++ b/lib/php/db/page.php @@ -24,6 +24,9 @@ if (!empty($_SERVER['DOCUMENT_ROOT'])) { #debug([$js,$css]); } +function auto_doc_root() { +} + $Page = new Page([ 'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)), 'css' => $css, diff --git a/lib/php/functions.php b/lib/php/functions.php index 62cef74b..2c5d8f4b 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -52,6 +52,7 @@ function ar_map($return,$array,$as_hash=false) { } function txt2md($txt) { +# NB 28.11.16: TODO rename as nb::md2html global $_txt2md; if ($_txt2md === null) { require_once(dirname(__FILE__).'/parsedown/Parsedown.php'); diff --git a/lib/php/nb.php b/lib/php/nb.php index 82ce3a51..0c275cca 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -16,6 +16,7 @@ class NB { # Sql: elect type,ext from mime_type where ext in ('json','csv','txt','yaml','xml','html','doc','xls'); protected static $content_types_aliases = array( 'text' => 'txt', + 'human' => 'txt', ); protected static $content_types = array( @@ -802,6 +803,10 @@ class NB { return $rows; } + public static function strlen($v,$encoding='UTF-8') { + return mb_strlen($v,$encoding); + } + public static function mb_str_pad($input, $pad_length, $pad_string=' ', $pad_type=STR_PAD_RIGHT,$encoding='UTF-8'){ $mb_diff=mb_strlen($input, $encoding)-strlen($input); return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type); diff --git a/lib/php/page.php b/lib/php/page.php index 59bda74b..5e756cec 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -47,16 +47,15 @@ class Page extends nb { */ public function __construct($opt = []) { - // Nav - if (isset($opt['nav'])) list($title,$nav) = Page::nav_parse($opt['nav']); - unset($opt['nav']); - // Content-type if (isset($opt['content_type'])) $this->content_type($opt['content_type']); - #elseif($this->php_cli()) $this->content_type('text/html'); unset($opt['content_type']); if (!$this->content_type()) $this->content_type($this->client_content_type()); + // Nav + if (isset($opt['nav'])) list($title,$nav) = self::nav_parse($opt['nav']); + unset($opt['nav']); + // Statics foreach ([ 'charset', @@ -74,7 +73,9 @@ class Page extends nb { if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title; - // Call + // Call / Print + + // Nav foreach ((array)($this->call) as $call) { if (is_scalar($call)) { @@ -197,7 +198,30 @@ class Page extends nb { ); } - if (!$is_html) return join("\n",(array)$content); + # NB 28.11.16: Proper Markdown yould be great ! + #if (!$is_html) return (preg_match('/^(span|a|inline|label|input|select)$/',strtolower($tag))?"":"\n").join("\n",(array)$content); + // Markdonw to html + if (!$is_html) return join("\n",array_map(function($e) use($tag){ + + if (preg_match('/^(li|dd)$/',$tag)) { + $e = "- $e"; + } elseif ($tag == 'h1') { + $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'='); + } elseif ($tag == 'h2') { + $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'-'); + } elseif ($tag == 'code') { + $e = "```\n$e\n```\n"; + } elseif ($tag == 'a') { + $e = "[$e]\n"; + } + + return '' + .(preg_match('/^(p|div)$/',$tag)?"\n":'') + .$e + .(preg_match('/^(p|div)$/',$tag)?"\n":'') + ; + + },(array)$content)); if ($content===null) { self::tag_end($tag); @@ -365,12 +389,15 @@ class Page extends nb { if (preg_match('/tml$/',self::$content_type)) { + // META if (self::$charset) $head .= ''.NB_EOL; - $head .= ''.NB_EOL; - foreach ((array)($this->css) as $v) { - $head .= ''.NB_EOL; + // CSS + foreach ((array)($this->css) as $vv) { + foreach ($this->path2url($vv) as $v) { + $head .= ''.NB_EOL; + } } if ($this->css_code) $head .= '' @@ -379,9 +406,13 @@ class Page extends nb { . ' -->' . NB_EOL ; - foreach ((array)($this->js) as $v) { - $head .= '' . NB_EOL; + // JS + foreach ((array)($this->js) as $vv) { + foreach ($this->path2url($vv) as $v) { + $head .= '' . NB_EOL; + } } + if ($this->js_code) $head .= '' . '