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
F20859713: D7393.id16651.diff
Fri, Jun 26, 5:27 AM
Unknown Object (File)
Apr 16 2026, 10:46 AM
Unknown Object (File)
Apr 16 2026, 10:45 AM
Unknown Object (File)
Mar 27 2026, 5:22 AM
Unknown Object (File)
Mar 15 2026, 5:08 AM
Unknown Object (File)
Mar 15 2026, 2:11 AM
Unknown Object (File)
Mar 10 2026, 10:41 PM
Unknown Object (File)
Mar 10 2026, 9:01 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

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