public static function fromHtml($html, $detail = false) { # Undo markdown require_once dirname(__FILE__) . '/html-to-markdown/HTML_To_Markdown.php'; $markdown = new HTML_To_Markdown($html); if (!$detail) { return self::deparseBlock($markdown->output()); } $detail = array('markdown' => $markdown->output(), 'human' => self::deparseBlock($markdown->output())); return $detail; }
$rs = $conn->query($sql); if ($rs === false) { trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR); } else { $rows_returned = $rs->num_rows; // dumper($rs->fetch_assoc()); while ($row = $rs->fetch_assoc()) { // process the posts $date = date('Y-m-d', strtotime($row['post_date_gmt'])); $filename = $row['post_name'] . '.md'; if ($row['post_status'] == 'publish') { $filename = $date . '-' . $filename; } // convert content to md $temp = new HTML_To_Markdown($row['post_content']); $md = $temp->output(); // change url and assets directory foreach ($config['old_wp_url'] as $arr) { // change upload $md = str_replace($arr . '/wp-content/uploads', 'images', $md); $md = str_replace($arr, '', $md); } // insert title in content; $md = "#" . $row['post_title'] . "\n\n" . $md; // create post in posts directory file_put_contents('posts/' . $filename, $md); } } echo 'Done! Go <a href="gen.php">generate the index now »</a>'; //// ========================= function dumper($multi)
function sanitize($v) { if (is_object($v)) { return $v; } $v = trim($v); if (!$v) { return ''; } if (preg_match($this->tag('p'), $v)) { $markdown = new HTML_To_Markdown($v, array('strip_tags' => true, 'remove_nodes' => 'img')); $v = $markdown->output(); $v = preg_replace('/\\[\\s*\\]/', '[link]', $v); } else { $v = strip_tags($v); $v = preg_replace("/\n/", " \n", $v); // Convert line breaks to markdown style } $v = trim($v, " \t\n\r\v Â"); return $v; }
protected function htmlToMarkdown($html) { $markdown = new \HTML_To_Markdown($html, $this->options); return $markdown->output(); }
/** * @param string $html * @return string */ protected function htmlToMarkdown($html) { $markdown = new \HTML_To_Markdown($html, array('header_style' => 'atx', 'bold_style' => '__', 'italic_style' => '_')); return $markdown->output(); }