Example #1
0
 public function run()
 {
     // Create default rules for handling MathJax
     Rule::create(['start_markdown' => '$$', 'close_markdown' => '$$', 'start_tag' => '$$', 'close_tag' => '$$', 'is_protected' => true, 'comment' => 'Protect $$...$$ from Parsedown']);
     Rule::create(['start_markdown' => '$', 'close_markdown' => '$', 'start_tag' => '$', 'close_tag' => '$', 'is_protected' => true, 'comment' => 'Protect $...$ from Parsedown']);
     Rule::create(['start_markdown' => '\\begin{align}', 'close_markdown' => '\\end{align}', 'start_tag' => '\\begin{align}', 'close_tag' => '\\end{align}', 'is_protected' => true, 'comment' => 'Protect \\begin{align}...\\end{align} from Parsedown']);
     Rule::create(['start_markdown' => '\\begin{equation}', 'close_markdown' => '\\end{equation}', 'start_tag' => '\\begin{equation}', 'close_tag' => '\\end{equation}', 'is_protected' => true, 'comment' => 'Protect \\begin{equation}...\\end{equation} from Parsedown']);
     // And an example to show how we can extend the Parsedown intepreter
     Rule::create(['start_markdown' => '@@', 'close_markdown' => '@@', 'start_tag' => '<strong class="text-primary">', 'close_tag' => '</strong>', 'is_protected' => false, 'comment' => 'Use @@text@@ for a <strong class="text-primary"> shortcut']);
 }
Example #2
0
 public function index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $postId) {
             if (!($rule = RuleModel::find($postId))) {
                 continue;
             }
             $rule->delete();
         }
     }
     return $this->listRefresh();
 }
Example #3
0
 /**
  * Performs the required changes after Parsedown has interpreted the input
  *
  * @param   string          $original   Contains the original text, before
  *                                      preMarkdownHook and Parsedown have done their jobs.
  * @param   MarkdownData    $data       Contains the text parsed so far
  * @return  void                        The parsed text is returned in $data
  *
  * @author Frank Wikström <*****@*****.**>
  **/
 public static function postMarkdownHook($original, $data)
 {
     $text = trim($data->text);
     $rules = Rule::remember(5, 'cached_rules')->get();
     // First put back all the protected items
     foreach (self::$dictionary as $key => $value) {
         $text = str_replace($key, $value, $text);
     }
     // Then process the other replacement rules.
     foreach ($rules as $rule) {
         if (!$rule->is_protected) {
             $avoid = $rule->start_markdown . $rule->close_markdown;
             $delimiter = self::getDelimiter($avoid);
             $search = $delimiter . preg_quote($rule->start_markdown) . '(.*?)' . preg_quote($rule->close_markdown) . $delimiter . 's';
             $replace = $rule->start_tag . '$1' . $rule->close_tag;
             $text = preg_replace($search, $replace, $text);
         }
     }
     $data->text = $text;
 }