Page MenuHomePhabricator

Make remarkup rules runtime-pluggable in a reasonable way
ClosedPublic

Authored by epriestley on Oct 24 2013, 11:28 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 3, 6:22 AM
Unknown Object (File)
Thu, May 2, 6:59 AM
Unknown Object (File)
Wed, Apr 24, 10:40 PM
Unknown Object (File)
Mon, Apr 22, 3:43 PM
Unknown Object (File)
Mon, Apr 22, 3:43 PM
Unknown Object (File)
Mon, Apr 22, 3:43 PM
Unknown Object (File)
Sun, Apr 21, 3:24 PM
Unknown Object (File)
Sun, Apr 21, 3:23 PM

Details

Summary

Gets rid of some old Differential-specific nonsense and replaces it with general runtime-pluggable Remarkup rules.

Facebook: This removes two options which may be in use. Have any classes being added via config here just subclass the new abstract bases instead. This should take 5 seconds to fix. You can adjust order by overriding getPriority() on the rules, if necessary.

Test Plan

See comments.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

I added this rule:

<?php

final class CustomInlineCodeRule extends PhabricatorRemarkupCustomInlineRule {

  public function apply($text) {
    return preg_replace_callback(
      '(<code>(.*?)</code>)s',
      array($this, 'markupInlineCodeBlock'),
      $text);
  }

  public function markupInlineCodeBlock($matches) {
    $engine = $this->getEngine();

    $text = $matches[1];

    $highlighter = new PhutilDefaultSyntaxHighlighterEngine();
    $highlighter->setConfig(
      'pygments.enabled',
      $engine->getConfig('pygments.enabled'));

    $lang = PhutilLanguageGuesser::guessLanguage($text);
    if (!$lang) {
      $lang = nonempty(
        $engine->getConfig('phutil.codeblock.language-default'),
        'php');
    }

    $source_body = phutil_tag(
      'span',
      array(
        'class' => 'remarkup-code PhabricatorMonospaced',
        'style' => 'white-space: pre-wrap; background: #fdfae7;',
      ),
      PhutilSafeHTML::applyFunction(
        'rtrim',
        $highlighter->highlightSource($lang, $text)));

    return $engine->storeText($source_body);
  }

}

..and got this reasonable-looking result:

{F74651}

See also https://twitter.com/sheki/status/393453127552102400

Sweet. That's got to be worth like 5 twitbucks or what have you.

epriestley updated this revision to Unknown Object (????).Oct 25 2013, 12:24 AM

ksort() is probably better than asort().