private function buildNewTestEngine()
 {
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('uri.allowed-protocols', array('http' => true));
     $rules = array();
     $rules[] = new PhutilRemarkupRuleEscapeRemarkup();
     $rules[] = new PhutilRemarkupRuleHyperlink();
     $rules[] = new PhutilRemarkupRuleEscapeHTML();
     $rules[] = new PhutilRemarkupRuleMonospace();
     $rules[] = new PhutilRemarkupRuleBold();
     $rules[] = new PhutilRemarkupRuleItalic();
     $blocks = array();
     $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
     foreach ($blocks as $block) {
         if (!$block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule) {
             $block->setMarkupRules($rules);
         }
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
 private function buildNewTestEngine()
 {
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('uri.prefix', 'http://www.example.com/');
     $engine->setConfig('uri.allowed-protocols', array('http' => true));
     $rules = array();
     $rules[] = new PhutilRemarkupRuleEscapeRemarkup();
     $rules[] = new PhutilRemarkupRuleMonospace();
     $rules[] = new PhutilRemarkupRuleDocumentLink();
     $rules[] = new PhutilRemarkupRuleHyperlink();
     $rules[] = new PhutilRemarkupRuleBold();
     $rules[] = new PhutilRemarkupRuleItalic();
     $rules[] = new PhutilRemarkupRuleDel();
     $blocks = array();
     $blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupHorizontalRuleBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupSimpleTableBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
     foreach ($blocks as $block) {
         if (!$block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule) {
             $block->setMarkupRules($rules);
         }
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
 private function buildNewTestEngine()
 {
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('uri.allowed-protocols', array('http' => true, 'mailto' => true, 'tel' => true));
     $rules = array();
     $rules[] = new PhutilRemarkupEscapeRemarkupRule();
     $rules[] = new PhutilRemarkupMonospaceRule();
     $rules[] = new PhutilRemarkupDocumentLinkRule();
     $rules[] = new PhutilRemarkupHyperlinkRule();
     $rules[] = new PhutilRemarkupBoldRule();
     $rules[] = new PhutilRemarkupItalicRule();
     $rules[] = new PhutilRemarkupDelRule();
     $rules[] = new PhutilRemarkupUnderlineRule();
     $rules[] = new PhutilRemarkupHighlightRule();
     $blocks = array();
     $blocks[] = new PhutilRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupReplyBlockRule();
     $blocks[] = new PhutilRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupHorizontalRuleBlockRule();
     $blocks[] = new PhutilRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupLiteralBlockRule();
     $blocks[] = new PhutilRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupTableBlockRule();
     $blocks[] = new PhutilRemarkupSimpleTableBlockRule();
     $blocks[] = new PhutilRemarkupDefaultBlockRule();
     $blocks[] = new PhutilRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupInterpreterBlockRule();
     foreach ($blocks as $block) {
         if (!$block instanceof PhutilRemarkupCodeBlockRule) {
             $block->setMarkupRules($rules);
         }
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
 public static function renderTableOfContents(PhutilRemarkupEngine $engine)
 {
     $key = self::KEY_HEADER_TOC;
     $anchors = $engine->getTextMetadata($key, array());
     if (count($anchors) < 2) {
         // Don't generate a TOC if there are no headers, or if there's only
         // one header (since such a TOC would be silly).
         return null;
     }
     $depth = 0;
     $toc = array();
     foreach ($anchors as $anchor => $info) {
         list($level, $name) = $info;
         while ($depth < $level) {
             $toc[] = '<ul>';
             $depth++;
         }
         while ($depth > $level) {
             $toc[] = '</ul>';
             $depth--;
         }
         $toc[] = phutil_render_tag('li', array(), phutil_render_tag('a', array('href' => '#' . $anchor), phutil_escape_html($name)));
     }
     while ($depth > 0) {
         $toc[] = '</ul>';
         $depth--;
     }
     return implode("\n", $toc);
 }
 private static function newMarkupEngine(array $options)
 {
     $options += self::getMarkupEngineDefaultConfiguration();
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('preserve-linebreaks', true);
     $engine->setConfig('pygments.enabled', $options['pygments']);
     $rules = array();
     $rules[] = new PhutilRemarkupRuleEscapeRemarkup();
     if ($options['fileproxy']) {
         $rules[] = new PhabricatorRemarkupRuleProxyImage();
     }
     if ($options['youtube']) {
         $rules[] = new PhabricatorRemarkupRuleYoutube();
     }
     $rules[] = new PhutilRemarkupRuleHyperlink();
     $rules[] = new PhabricatorRemarkupRuleDifferentialHandle();
     $rules[] = new PhabricatorRemarkupRuleManiphestHandle();
     $rules[] = new PhabricatorRemarkupRuleEmbedFile();
     $rules[] = new PhabricatorRemarkupRuleDifferential();
     $rules[] = new PhabricatorRemarkupRuleDiffusion();
     $rules[] = new PhabricatorRemarkupRuleManiphest();
     $rules[] = new PhabricatorRemarkupRulePaste();
     if ($options['macros']) {
         $rules[] = new PhabricatorRemarkupRuleImageMacro();
     }
     $rules[] = new PhabricatorRemarkupRuleMention();
     $rules[] = new PhabricatorRemarkupRulePhriction();
     $custom_rule_classes = $options['custom-inline'];
     if ($custom_rule_classes) {
         foreach ($custom_rule_classes as $custom_rule_class) {
             PhutilSymbolLoader::loadClass($custom_rule_class);
             $rules[] = newv($custom_rule_class, array());
         }
     }
     $rules[] = new PhutilRemarkupRuleEscapeHTML();
     $rules[] = new PhutilRemarkupRuleMonospace();
     $rules[] = new PhutilRemarkupRuleBold();
     $rules[] = new PhutilRemarkupRuleItalic();
     $blocks = array();
     $blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
     $custom_block_rule_classes = $options['custom-block'];
     if ($custom_block_rule_classes) {
         foreach ($custom_block_rule_classes as $custom_block_rule_class) {
             PhutilSymbolLoader::loadClass($custom_block_rule_class);
             $blocks[] = newv($custom_block_rule_class, array());
         }
     }
     foreach ($blocks as $block) {
         if (!$block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule) {
             $block->setMarkupRules($rules);
         }
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
 /**
  * @task engine
  */
 public static function newMarkupEngine(array $options)
 {
     $options += self::getMarkupEngineDefaultConfiguration();
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('preserve-linebreaks', $options['preserve-linebreaks']);
     $engine->setConfig('pygments.enabled', $options['pygments']);
     $engine->setConfig('uri.allowed-protocols', $options['uri.allowed-protocols']);
     $engine->setConfig('differential.diff', $options['differential.diff']);
     $engine->setConfig('header.generate-toc', $options['header.generate-toc']);
     $engine->setConfig('syntax-highlighter.engine', $options['syntax-highlighter.engine']);
     $engine->setConfig('uri.full', $options['uri.full']);
     $rules = array();
     $rules[] = new PhutilRemarkupEscapeRemarkupRule();
     $rules[] = new PhutilRemarkupMonospaceRule();
     $rules[] = new PhutilRemarkupDocumentLinkRule();
     $rules[] = new PhabricatorNavigationRemarkupRule();
     if ($options['youtube']) {
         $rules[] = new PhabricatorYoutubeRemarkupRule();
     }
     $applications = PhabricatorApplication::getAllInstalledApplications();
     foreach ($applications as $application) {
         foreach ($application->getRemarkupRules() as $rule) {
             $rules[] = $rule;
         }
     }
     $rules[] = new PhutilRemarkupHyperlinkRule();
     if ($options['macros']) {
         $rules[] = new PhabricatorImageMacroRemarkupRule();
         $rules[] = new PhabricatorMemeRemarkupRule();
     }
     $rules[] = new PhutilRemarkupBoldRule();
     $rules[] = new PhutilRemarkupItalicRule();
     $rules[] = new PhutilRemarkupDelRule();
     $rules[] = new PhutilRemarkupUnderlineRule();
     foreach (self::loadCustomInlineRules() as $rule) {
         $rules[] = $rule;
     }
     $blocks = array();
     $blocks[] = new PhutilRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupReplyBlockRule();
     $blocks[] = new PhutilRemarkupLiteralBlockRule();
     $blocks[] = new PhutilRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupHorizontalRuleBlockRule();
     $blocks[] = new PhutilRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupTableBlockRule();
     $blocks[] = new PhutilRemarkupSimpleTableBlockRule();
     $blocks[] = new PhutilRemarkupInterpreterBlockRule();
     $blocks[] = new PhutilRemarkupDefaultBlockRule();
     foreach (self::loadCustomBlockRules() as $rule) {
         $blocks[] = $rule;
     }
     foreach ($blocks as $block) {
         $block->setMarkupRules($rules);
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }
Ejemplo n.º 7
0
 /**
  * @task engine
  */
 private static function newMarkupEngine(array $options)
 {
     $options += self::getMarkupEngineDefaultConfiguration();
     $engine = new PhutilRemarkupEngine();
     $engine->setConfig('preserve-linebreaks', true);
     $engine->setConfig('pygments.enabled', $options['pygments']);
     $engine->setConfig('uri.allowed-protocols', $options['uri.allowed-protocols']);
     $engine->setConfig('differential.diff', $options['differential.diff']);
     $engine->setConfig('header.generate-toc', $options['header.generate-toc']);
     $engine->setConfig('syntax-highlighter.engine', $options['syntax-highlighter.engine']);
     $rules = array();
     $rules[] = new PhutilRemarkupRuleEscapeRemarkup();
     $rules[] = new PhutilRemarkupRuleMonospace();
     $custom_rule_classes = $options['custom-inline'];
     if ($custom_rule_classes) {
         foreach ($custom_rule_classes as $custom_rule_class) {
             $rules[] = newv($custom_rule_class, array());
         }
     }
     $rules[] = new PhutilRemarkupRuleDocumentLink();
     if ($options['fileproxy']) {
         $rules[] = new PhabricatorRemarkupRuleProxyImage();
     }
     if ($options['youtube']) {
         $rules[] = new PhabricatorRemarkupRuleYoutube();
     }
     $rules[] = new PhutilRemarkupRuleHyperlink();
     $rules[] = new PhabricatorRemarkupRulePhriction();
     $rules[] = new PhabricatorRemarkupRuleDifferentialHandle();
     $rules[] = new PhabricatorRemarkupRuleManiphestHandle();
     $rules[] = new PhabricatorRemarkupRuleEmbedFile();
     $rules[] = new PhabricatorRemarkupRuleDifferential();
     $rules[] = new PhabricatorRemarkupRuleDiffusion();
     $rules[] = new PhabricatorRemarkupRuleManiphest();
     $rules[] = new PhabricatorRemarkupRulePaste();
     $rules[] = new PhabricatorRemarkupRuleCountdown();
     $rules[] = new PonderRuleQuestion();
     if ($options['macros']) {
         $rules[] = new PhabricatorRemarkupRuleImageMacro();
     }
     $rules[] = new PhabricatorRemarkupRuleMention();
     $rules[] = new PhutilRemarkupRuleEscapeHTML();
     $rules[] = new PhutilRemarkupRuleBold();
     $rules[] = new PhutilRemarkupRuleItalic();
     $rules[] = new PhutilRemarkupRuleDel();
     $blocks = array();
     $blocks[] = new PhutilRemarkupEngineRemarkupQuotesBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupLiteralBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupHeaderBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupListBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupCodeBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupNoteBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupTableBlockRule();
     $blocks[] = new PhutilRemarkupEngineRemarkupDefaultBlockRule();
     $custom_block_rule_classes = $options['custom-block'];
     if ($custom_block_rule_classes) {
         foreach ($custom_block_rule_classes as $custom_block_rule_class) {
             $blocks[] = newv($custom_block_rule_class, array());
         }
     }
     foreach ($blocks as $block) {
         if ($block instanceof PhutilRemarkupEngineRemarkupLiteralBlockRule) {
             $literal_rules = array();
             $literal_rules[] = new PhutilRemarkupRuleEscapeHTML();
             $literal_rules[] = new PhutilRemarkupRuleLinebreaks();
             $block->setMarkupRules($literal_rules);
         } else {
             if (!$block instanceof PhutilRemarkupEngineRemarkupCodeBlockRule) {
                 $block->setMarkupRules($rules);
             }
         }
     }
     $engine->setBlockRules($blocks);
     return $engine;
 }