Esempio n. 1
0
 public function testTable()
 {
     $markup = new StudipFormat();
     $index = 0;
     foreach (array('|a|table' . PHP_EOL => '<table class="content">' . '<tr><td>a</td><td>table</td></tr>' . '</table>', '| this  | is a | table |' . PHP_EOL . '| with | two | rows |' => '<table class="content">' . '<tr><td>this</td><td>is a</td><td>table</td></tr>' . '<tr><td>with</td><td>two</td><td>rows</td></tr>' . '</table>') as $in => $out) {
         ++$index;
         $this->assertEquals($out, $markup->format($in), 'test number ' . $index);
     }
 }
 public static function format($text)
 {
     StudipFormat::addStudipMarkup("blubberhashtag", "(^|\\s)#([\\w\\d_\\.\\-]*[\\w\\d])", "", "ForumPosting::markupHashtags");
     $output = formatReady($text);
     StudipFormat::removeStudipMarkup("blubberhashtag");
     return $output;
 }
Esempio n. 3
0
 /**
  * Special format-function that adds hashtags to the common formatReady-markup.
  * @param string $text : original text with studip-markup plus hashtags
  * @return string : formatted text
  */
 public static function format($text)
 {
     StudipFormat::addStudipMarkup("blubberhashtag", BlubberPosting::$hashtags_regexp, null, "BlubberPosting::markupHashtags");
     $output = formatReady($text);
     StudipFormat::removeStudipMarkup("blubberhashtag");
     return $output;
 }
Esempio n. 4
0
 /**
  * Initializes a new WikiFormat instance.
  */
 public function __construct()
 {
     parent::__construct();
     foreach (self::$wiki_rules as $name => $rule) {
         $this->addMarkup($name, $rule['start'], $rule['end'], $rule['callback'], $rule['before'] ?: null);
     }
 }
Esempio n. 5
0
 /**
  * Extracts urls and their according open graph infos from a given string
  * 
  * @param String $string Text to extract urls and open graph infos from
  * @return OpenGraphURLCollection containing the extracted urls
  */
 public static function extract($string)
 {
     $collection = new OpenGraphURLCollection();
     if (Config::get()->OPENGRAPH_ENABLE) {
         $regexp = StudipFormat::getStudipMarkups()['links']['start'];
         $matched = preg_match_all('/' . $regexp . '/ms', $string, $matches, PREG_SET_ORDER);
         foreach ($matches as $match) {
             $url = $match[2];
             if (!$url) {
                 continue;
             }
             if (!isLinkIntern($url)) {
                 $og_url = OpenGraphURL::fromURL($url);
                 if ($og_url && !$collection->find($og_url->id)) {
                     $og_url->store();
                     $collection[] = $og_url;
                 }
             }
         }
     }
     return $collection;
 }
Esempio n. 6
0
/**
 * Simplified version of formatReady that handles link formatting only.
 *
 * @param  string $text   Marked-up text.
 * @param  bool   $nl2br  Convert newlines to <br>.
 * @return string         Marked-up text with markup-links converted to
 *                        HTML-links.
 */
function formatLinks($text, $nl2br = TRUE)
{
    $link_markup_rule = StudipFormat::getStudipMarkup('links');
    $markup = new TextFormat();
    $markup->addMarkup('links', $link_markup_rule['start'], $link_markup_rule['end'], $link_markup_rule['callback']);
    if ($nl2br) {
        // fix newlines
        $text = nl2br($text, FALSE);
    }
    return Markup::purify($markup->format(trim($text)));
}