Ejemplo n.º 1
0
 /**
  * Converts a given string to our xml friendly text.
  * This step involves purifying the string
  *
  * @param String $string Input string to reformat
  * @return String Reformatted string (optional HTML -> Markdown, UTF-8)
  */
 public function xml_ready($string, $convert_to_markdown = true)
 {
     static $purifier = null;
     static $fixer = null;
     static $markdown = null;
     if ($purifier === null) {
         $purifier_config = HTMLPurifier_Config::createDefault();
         $purifier_config->set('Cache.SerializerPath', realpath($GLOBALS['TMP_PATH']));
         $purifier = new HTMLPurifier($purifier_config);
         $markdown = new HTML_To_Markdown();
         $markdown->set_option('strip_tags', true);
     }
     $string = studip_utf8encode($string);
     $string = $purifier->purify($string);
     if ($convert_to_markdown) {
         $string = $markdown->convert($string);
         $string = preg_replace('/\\[\\]\\((\\w+:\\/\\/.*?)\\)/', '', $string);
         $string = preg_replace('/\\[(\\w+:\\/\\/.*?)\\/?\\]\\(\\1\\/?\\s+"(.*?)"\\)/isxm', '$2: $1', $string);
         $string = preg_replace('/\\[(\\w+:\\/\\/.*?)\\/?\\]\\(\\1\\/?\\)/isxm', '$1', $string);
         $string = preg_replace('/\\[(.*?)\\]\\((\\w+:\\/\\/.*?)\\)/', '$1: $2', $string);
     }
     $string = preg_replace('/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/', '', $string);
     $string = trim($string);
     $string = htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
     return $string;
 }
Ejemplo n.º 2
0
 /**
  * In addition to markdown conversion, strips images and treats h3-6 as paragraphs.
  * @param string $html
  * @return string empty if conversion fails
  */
 public static function convert($html)
 {
     $converter = new HTML_To_Markdown();
     $html = preg_replace('/<img[^>]*>/', '', $html);
     $html = preg_replace('/<(\\/)?h[3-6]>/', '<$1p>', $html);
     $converter->set_option('header_style', 'postmatic');
     $converter->set_option('strip_tags', true);
     $markdown = $converter->convert($html);
     return $markdown ? $markdown : '';
 }
Ejemplo n.º 3
0
 /**
  * Create the Calendar Event
  *
  * @param $title
  * @param $startDate
  * @param null $description
  * @param int $duration
  * @param null $location
  */
 public function __construct($title, $startDate, $description = null, $duration = 60, $location = null)
 {
     if ($description) {
         $markdown = new HTML_To_Markdown();
         $markdown->set_option('strip_tags', true);
         $noImageText = preg_replace(array("/<img[^>]+\\>/i", "/<hr[^>]+\\>/i"), "", $description);
         $markdown->convert($noImageText);
         $this->description = $markdown;
     }
     if (is_numeric($startDate)) {
         $startTimestamp = new DateTime();
         $startTimestamp->setTimestamp($startDate);
     } else {
         $startTimestamp = new DateTime($startDate);
     }
     $startTimestamp->setTimezone(new DateTimeZone('UTC'));
     $this->startDate = $startTimestamp->format('Ymd\\THis\\Z');
     $this->duration = $duration;
     $this->endDate = $startTimestamp->modify('+' . $duration . ' minutes')->format('Ymd\\THis\\Z');
     $this->location = $location;
     $this->title = strip_tags($title);
 }
Ejemplo n.º 4
0
 public function test_set_option()
 {
     $markdown = new HTML_To_Markdown();
     $markdown->set_option('strip_tags', true);
     $markdown->convert('<span>Strip</span>');
     $this->assertEquals('Strip', $markdown->__toString());
 }
Ejemplo n.º 5
0
 public static function text($html = null, $overrides = null)
 {
     $md = new \HTML_To_Markdown($overrides);
     return $md->convert($html);
 }
Ejemplo n.º 6
0
 /**
  * Convert HTML to markdown
  *
  * @since 1.0.0
  *
  * @param  string $html
  * @return string
  */
 protected function convertToMarkdown($html)
 {
     $converter = new HTML_To_Markdown();
     $converter->set_option('strip_tags', false);
     $converter->set_option('header_style', $this->headingStyle);
     return $converter->convert($html);
 }