public function printHtml() { $post = []; $md = $this->post("md"); $post['title'] = $this->post('title'); if ($post['title'] == '') { $post['title'] = "无题"; } $HyperDown = new \HyperDown\Parser(); $post['html'] = $HyperDown->makeHtml($md); $this->assign("Post", $post); $this->display("PostPreView.html"); }
/** * Post a post in post method * @return print json format string */ public function submit() { $post = []; $postId = $this->post("postId"); if (!($post['title'] = $this->post("title"))) { $post['title'] = "无题"; } $post['url'] = "a/" . md5(date("YmdHis")); if (!($post['created_at'] = $this->post("created_at"))) { $post['created_at'] = date("Y-m-d H:i:s"); } else { $post['created_at'] = date("Y-m-d H:i:s", strtotime($post['created_at'])); } if (!($post['category'] = $this->post("cateVal"))) { $post['category'] = 1; } $post['markdown'] = $this->post("markdown"); include ROOT_PATH . "/var/HyperDown.php"; $HyperDown = new \HyperDown\Parser(); $post['html'] = $HyperDown->makeHtml($post['markdown']); if (!($length = stripos($post['html'], "<!--more-->"))) { $length = 200; } $post['tags'] = $this->post('tags'); $post['public'] = $this->post("public"); if ($post['public'] !== '0') { $post['public'] = 1; } /** * edit an old post or public a new one! * @var [type] */ /** * if post have already exist * @var [type] */ if ($postId && ($thisPost = $this->PostModel->getPostById($postId))) { $oldCategory = $thisPost->category; $thisPost->title = $post['title']; $thisPost->public = $post['public']; $thisPost->category = $post['category']; $thisPost->markdown = $post['markdown']; $thisPost->html = $post['html']; $thisPost->tags = $post['tags']; $thisPost->created_at = $post['created_at']; $thisPost->save(); $oldCateList = explode(',', $oldCategory); $cateList = explode(',', $post['category']); $shouldDeleteCateList = array_diff($oldCateList, $cateList); foreach ($shouldDeleteCateList as $ce) { $cateModel = $this->CateModel->getCategoryById($ce); $cateModel->deletePost($postId); } $newCateList = array_diff($cateList, $oldCateList); foreach ($newCateList as $cate) { $cateModel = $this->CateModel->getCategoryById($cate); $cateModel->addPost($postId); } } else { $post['created_at'] = date("Y-m-d H:i:s"); $insertId = $this->PostModel->insertGetId($post); $cateList = explode(',', $post['category']); foreach ($cateList as $cate) { $cateModel = $this->CateModel->getCategoryById($cate); $cateModel->addPost($insertId); } } /** * rending the json string to client */ return $this->renderJson(['code' => 200, 'errmsg' => "ok", "go_url" => "/Admin/Post/List.html"]); }
<?php include 'Parser.php'; $parser = new HyperDown\Parser(); $text = '输入你要转换的内容'; $html = $parser->makeHtml($text); echo $html;