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)
Mon, Dec 23, 2:03 PM
Unknown Object (File)
Tue, Dec 17, 7:47 AM
Unknown Object (File)
Sun, Dec 15, 2:20 PM
Unknown Object (File)
Sat, Dec 14, 4:27 PM
Unknown Object (File)
Sat, Dec 14, 2:35 PM
Unknown Object (File)
Sun, Dec 8, 9:25 AM
Unknown Object (File)
Sun, Dec 8, 7:26 AM
Unknown Object (File)
Dec 3 2024, 12:21 AM

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

Branch
plugremarkup
Lint
Lint Passed
Unit
Tests Passed

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().