/**
  * Convert data
  *
  * @param   string  $data
  * @return  string
  */
 public function convert($data)
 {
     // markdownify doesn't like attrs
     $data = $this->strip_attrs($data);
     $md = new Markdownify_Extra();
     return $md->parseString($data);
 }
 function html_to_text($html)
 {
     static $parser;
     if (!isset($parser)) {
         $parser = new Markdownify_Extra();
         $parser->keepHTML = false;
     }
     return @$parser->parseString($html);
 }
 public function parse_string($template, $data = array(), $return = FALSE, $config = array())
 {
     if (!is_array($config)) {
         $config = array();
     }
     $config = array_merge($this->config, $config);
     $ci = $this->ci;
     $is_mx = false;
     if (!$return) {
         list($ci, $is_mx) = $this->detect_mx();
     }
     $parser = new Markdownify_Extra($config['linksAfterEachParagraph'], $config['bodyWidth'], $config['keepHTML']);
     $template = @$parser->parseString($template);
     return $this->output($template, $return, $ci, $is_mx);
 }
Exemple #4
0
 public static function alternativeMultipartForTemplate($oTemplate, $sAlternative = null, $sCharset = null, $aTextifyMethods = 'markdown')
 {
     $sContent = $oTemplate->render();
     if ($sCharset === null) {
         $sCharset = $oTemplate->getCharset();
     }
     if ($sAlternative === null) {
         $sAlternative = $sContent;
     }
     if ($aTextifyMethods !== null) {
         if (!is_array($aTextifyMethods)) {
             $aTextifyMethods = explode('-', $aTextifyMethods);
         }
         foreach ($aTextifyMethods as $sTextfyMethod) {
             if ($sTextfyMethod === 'markdown') {
                 require_once 'markdownify/Markdownify_Extra.php';
                 $oMarkdownify = new Markdownify_Extra(false, false, false);
                 $sAlternative = $oMarkdownify->parseString($sAlternative);
             } else {
                 if ($sTextfyMethod === 'strip_tags') {
                     $sAlternative = strip_tags($sAlternative, '<' . implode('><', self::$ALLOWED_TAGS) . '>');
                 } else {
                     if ($sTextfyMethod === 'strip_tags/full') {
                         $sAlternative = strip_tags($sAlternative);
                     } else {
                         if ($sTextfyMethod === 'purify') {
                             require_once 'htmlpurifier/HTMLPurifier.standalone.php';
                             $oPurifierConfig = HTMLPurifier_Config::createDefault();
                             $sCacheDir = MAIN_DIR . '/' . DIRNAME_GENERATED . '/' . DIRNAME_CACHES . '/purifier';
                             if (!file_exists($sCacheDir)) {
                                 mkdir($sCacheDir);
                             }
                             $oPurifierConfig->set('Cache.SerializerPath', $sCacheDir);
                             $oPurifierConfig->set('AutoFormat.AutoParagraph', true);
                             $oPurifierConfig->set('HTML.AllowedElements', self::$ALLOWED_TAGS);
                             $oPurifier = new HTMLPurifier($oPurifierConfig);
                             $sAlternative = $oPurifier->purify($sAlternative);
                         }
                     }
                 }
             }
         }
     }
     $oMimeTree = new MIMEMultipart('alternative');
     $oMimeTree->addPart(MIMELeaf::leafWithText($sAlternative, '8bit', $sCharset));
     $oMimeTree->addPart(new MIMELeaf($sContent, 'text/html', '8bit', $sCharset));
     return $oMimeTree;
 }
Exemple #5
0
 public static function html2markdown($s)
 {
     static $md;
     if (!isset($md)) {
         $md = new Markdownify_Extra();
     }
     return $md->parseString($s);
 }
/**
 * Converts HTML into markdown
 * 
 * @param string $html
 * @return string markdown
 */
function wpmarkdown_html_to_markdown($html)
{
    $md = new Markdownify_Extra();
    $markdown = $md->parseString($html);
    return $markdown;
}
Exemple #7
0
/**
 * Converts HTML into markdown.
 * 
 * Optionally you can specify where it should first balance the tags in the 
 * given HTML {@see balanceTags}.
 * 
 * @uses   balanceTags
 * @param  string $html                The HTML to convert to markdown
 * @param  bool   $balance_tags  If true, balances HTML tags. Default true.
 * @return string The generated markdown
 */
function wpmarkdown_html_to_markdown($html, $balance_tags = true)
{
    $md = new Markdownify_Extra();
    $balance_tags = apply_filters('wp_markdown_balance_tags', $balance_tags);
    if ($balance_tags) {
        $html = force_balance_tags($html);
    }
    $markdown = $md->parseString($html);
    return $markdown;
}
<?php 
require dirname(__FILE__) . '/markdownify_extra.php';
function param($name, $default = false)
{
    if (!in_array('--' . $name, $_SERVER['argv'])) {
        return $default;
    }
    reset($_SERVER['argv']);
    while (each($_SERVER['argv'])) {
        if (current($_SERVER['argv']) == '--' . $name) {
            break;
        }
    }
    $value = next($_SERVER['argv']);
    if ($value === false || substr($value, 0, 2) == '--') {
        return true;
    } else {
        return $value;
    }
}
$input = stream_get_contents(STDIN);
$linksAfterEachParagraph = param('links');
$bodyWidth = param('width');
$keepHTML = param('html', true);
if (param('no_extra')) {
    $parser = new Markdownify($linksAfterEachParagraph, $bodyWidth, $keepHTML);
} else {
    $parser = new Markdownify_Extra($linksAfterEachParagraph, $bodyWidth, $keepHTML);
}
echo $parser->parseString($input) . "\n";