示例#1
0
 public function _getMarkdownContent()
 {
     // Parsedown
     $Parsedown = new \Parsedown();
     $texte = $Parsedown->setMarkupEscaped(true)->text($this->content);
     // Emojione
     $client = new \Emojione\Client(new \Emojione\Ruleset());
     $client->imageType = 'png';
     return $client->shortnameToImage($texte);
 }
示例#2
0
function markdown($s)
{
    $pd = new Parsedown();
    $pd->setMarkupEscaped(true);
    $pd->setimagesEnabled(false);
    return $pd->text($s);
}
示例#3
0
    public function test_no_markup()
    {
        $markdownWithHtml = <<<MARKDOWN_WITH_MARKUP
<div>_content_</div>

sparse:

<div>
<div class="inner">
_content_
</div>
</div>

paragraph

<style type="text/css">
    p {
        color: red;
    }
</style>

comment

<!-- html comment -->
MARKDOWN_WITH_MARKUP;
        $expectedHtml = <<<EXPECTED_HTML
<p>&lt;div&gt;<em>content</em>&lt;/div&gt;</p>
<p>sparse:</p>
<p>&lt;div&gt;
&lt;div class=&quot;inner&quot;&gt;
<em>content</em>
&lt;/div&gt;
&lt;/div&gt;</p>
<p>paragraph</p>
<p>&lt;style type=&quot;text/css&quot;&gt;
p {
color: red;
}
&lt;/style&gt;</p>
<p>comment</p>
<p>&lt;!-- html comment --&gt;</p>
EXPECTED_HTML;
        $parsedownWithNoMarkup = new Parsedown();
        $parsedownWithNoMarkup->setMarkupEscaped(true);
        $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
    }
示例#4
0
            echo "<p>User " . htmlspecialchars($_POST['blid']) . " not found.</p>";
        }
    }
    //One of the few time's we'll use a direct SQL query on a page
    $result = $db->query($baseQuery . $extendedQuery);
    echo "<h2>Search Results for ";
    echo "\"<u>" . htmlspecialchars($_POST['query']) . "</u>\"";
    if (isset($user) && $user) {
        echo " by <a href=\"/user/view.php?id=" . $user->getID() . "\">" . htmlspecialchars($user->getUsername()) . "</a>";
    }
    echo "</h2><hr />";
    if ($result->num_rows) {
        while ($row = $result->fetch_object()) {
            echo "<p><b><a href=\"addon.php?id=" . $row->id . "\">" . htmlspecialchars($row->name) . "</a></b><br />";
            if (strlen($row->description) > 200) {
                $desc = substr($row->description, 0, 196) . " ...";
            } else {
                $desc = $row->description;
            }
            $Parsedown = new Parsedown();
            $Parsedown->setBreaksEnabled(true);
            $Parsedown->setMarkupEscaped(true);
            //may need escaping
            echo $Parsedown->text($desc);
            echo "</p><br />";
        }
    } else {
        echo "We couldn't find anything. Sorry about that.";
    }
    $result->close();
}
 public function documentation()
 {
     global $pawUsers;
     $request = $this->_check("user_config");
     // GET DOCUMENTATION PAGE
     $docs = pawUsers_PATH . "/docs";
     $file = $docs . "/index.md";
     if (isset($_GET["page"]) && endsWith($_GET["page"], ".md")) {
         $page = urldecode($_GET["page"]);
         if (startsWith(realpath($docs . "/" . $page), realpath($docs)) && is_file($docs . "/" . $page)) {
             $file = $docs . "/" . $page;
         } else {
             $file = $docs . "/error.md";
         }
     }
     // READ DOCUMENTATION PAGE
     $mdtext = file_get_contents($file);
     $parser = new Parsedown();
     $parser->setMarkupEscaped(false);
     $content = $parser->text($mdtext);
     // DISPLAY DOCUMENTATION PAGE
     $this->display("../../plugins/paw_users/admin/docs", array("content" => $content));
 }
示例#6
0
文件: markdown.php 项目: rros/Shaarli
/**
 * Render shaare contents through Markdown parser.
 *   1. Remove HTML generated by Shaarli core.
 *   2. Generate markdown descriptions.
 *   3. Wrap description in 'markdown' CSS class.
 *
 * @param string $description input description text.
 *
 * @return string HTML processed $description.
 */
function process_markdown($description)
{
    $parsedown = new Parsedown();
    $processedDescription = $description;
    $processedDescription = reverse_text2clickable($processedDescription);
    $processedDescription = reverse_nl2br($processedDescription);
    $processedDescription = reverse_space2nbsp($processedDescription);
    $processedDescription = reset_quote_tags($processedDescription);
    $processedDescription = $parsedown->setMarkupEscaped(false)->setBreaksEnabled(true)->text($processedDescription);
    $processedDescription = '<div class="markdown">' . $processedDescription . '</div>';
    return $processedDescription;
}
示例#7
0
function markdown($text, $allow_html = false)
{
    static $parsedown = null;
    if ($parsedown === null) {
        include BOOTSTRAP_ROOT . 'includes/Parsedown.php';
        $parsedown = new Parsedown();
    }
    $parsedown->setBreaksEnabled(true);
    // should convert \n to <br/>?
    $parsedown->setMarkupEscaped(!$allow_html);
    // should escape HTML?
    $parsedown->setUrlsLinked(true);
    // should automatically link urls?
    return $parsedown->text($text);
}
示例#8
0
 /**
  * 
  *
  * @static 
  */
 public static function setMarkupEscaped($markupEscaped)
 {
     return \Parsedown::setMarkupEscaped($markupEscaped);
 }
示例#9
0
/**
 * Render shaare contents through Markdown parser.
 *   1. Remove HTML generated by Shaarli core.
 *   2. Reverse the escape function.
 *   3. Generate markdown descriptions.
 *   4. Sanitize sensible HTML tags for security.
 *   5. Wrap description in 'markdown' CSS class.
 *
 * @param string $description input description text.
 *
 * @return string HTML processed $description.
 */
function process_markdown($description)
{
    $parsedown = new Parsedown();
    $processedDescription = $description;
    $processedDescription = reverse_text2clickable($processedDescription);
    $processedDescription = reverse_nl2br($processedDescription);
    $processedDescription = reverse_space2nbsp($processedDescription);
    $processedDescription = unescape($processedDescription);
    $processedDescription = $parsedown->setMarkupEscaped(false)->setBreaksEnabled(true)->text($processedDescription);
    $processedDescription = sanitize_html($processedDescription);
    if (!empty($processedDescription)) {
        $processedDescription = '<div class="markdown">' . $processedDescription . '</div>';
    }
    return $processedDescription;
}
示例#10
0
function formatage_links($texte)
{
    if ($GLOBALS['use_markdown']) {
        include_once 'parsedown/parsedown.php';
        $Parsedown = new Parsedown();
        return stripslashes($Parsedown->setMarkupEscaped(true)->text($texte));
    }
    $tofind = array('#([^"\\[\\]|])((http|ftp)s?://([^"\'\\[\\]<>\\s]+))#i', '#\\[([^[]+)\\|([^[]+)\\]#', '#\\[b\\](.*?)\\[/b\\]#s', '#\\[i\\](.*?)\\[/i\\]#s', '#\\[s\\](.*?)\\[/s\\]#s', '#\\[u\\](.*?)\\[/u\\]#s');
    $toreplace = array('$1<a href="$2">$2</a>', '<a href="$2">$1</a>', '<strong>$1</strong>', '<em>$1</em>', '<del>$1</del>', '<u>$1</u>');
    // ceci permet de formater l’ensemble du message, sauf les balises [code],
    $nb_balises_code_avant = preg_match_all('#\\[code\\](.*?)\\[/code\\]#s', $texte, $balises_code, PREG_SET_ORDER);
    $texte_formate = preg_replace($tofind, $toreplace, ' ' . $texte . ' ');
    $texte_formate = nl2br(trim($texte_formate));
    if ($nb_balises_code_avant) {
        $nb_balises_code_apres = preg_match_all('#\\[code\\](.*?)\\[/code\\]#s', $texte_formate, $balises_code_apres, PREG_SET_ORDER);
        foreach ($balises_code as $i => $code) {
            $texte_formate = str_replace($balises_code_apres[$i][0], '<pre>' . $balises_code[$i][1] . '</pre>', $texte_formate);
        }
    }
    return $texte_formate;
}
示例#11
0
function parse_message($text, $hide_smilies)
{
    global $pun_config, $lang_common, $pun_user;
    if ($pun_config['o_censoring'] == '1') {
        $text = censor_words($text);
    }
    // If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
    }
    $Parsedown = new Parsedown();
    $text = $Parsedown->setMarkupEscaped(true)->setUrlsLinked(false)->text($text);
    if ($pun_config['o_make_links'] == '1') {
        $text = do_clickable($text);
    }
    // If the message contains code in Markdown
    if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false) {
        // If we have code from BBCode, put them back into the text
        if (isset($inside)) {
            $parts = explode("", $text);
            $text = '';
            foreach ($parts as $i => $part) {
                $text .= $part . (isset($inside[$i]) ? '[code]' . $inside[$i] . '[/code]' : '');
            }
        }
        // And take them out again.
        list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
    }
    if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false) {
        $text = do_bbcode($text);
    }
    if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0') {
        $text = do_smilies($text);
    }
    // Deal with newlines, tabs and multiple spaces
    $pattern = array("\n", "\t", '  ', '  ');
    $replace = array('<br />', '&#160; &#160; ', '&#160; ', ' &#160;');
    $text = str_replace($pattern, $replace, $text);
    // If we split up the message before we have to concatenate it together again (code tags)
    if (isset($inside)) {
        $parts = explode("", $text);
        $text = '';
        foreach ($parts as $i => $part) {
            $text .= $part;
            if (isset($inside[$i])) {
                $num_lines = substr_count($inside[$i], "\n");
                $text .= '</p><div class="codebox"><pre' . ($num_lines > 28 ? ' class="vscroll"' : '') . '><code>' . pun_trim(pun_htmlspecialchars($inside[$i]), "\n\r") . '</code></pre></div><p>';
            }
        }
    }
    return clean_paragraphs($text);
}