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
F19891375: D7393.diff
Fri, Mar 27, 5:22 AM
F19869057: D7393.id16650.diff
Sun, Mar 15, 5:08 AM
F19868418: D7393.diff
Sun, Mar 15, 2:11 AM
F19832522: D7393.id16650.diff
Mar 10 2026, 10:41 PM
F19831866: D7393.diff
Mar 10 2026, 9:01 PM
F19786388: D7393.id16651.diff
Feb 25 2026, 8:41 AM
F19785040: D7393.id16652.diff
Feb 24 2026, 9:07 PM
F19620975: D7393.diff
Feb 4 2026, 12:48 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().