@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorRemarkupFigletBlockInterpreter
4 extends PhutilRemarkupBlockInterpreter
5 implements RemarkupSyntaxDocumentationProvider {
6
7 public function getInterpreterName() {
8 return 'figlet';
9 }
10
11 /**
12 * @phutil-external-symbol class Text_Figlet
13 */
14 public function markupContent($content, array $argv) {
15 $map = self::getFigletMap();
16
17 $font = idx($argv, 'font');
18 $font = phutil_utf8_strtolower($font);
19 if (empty($map[$font])) {
20 $font = 'standard';
21 }
22
23 $root = dirname(phutil_get_library_root('phabricator'));
24 require_once $root.'/externals/pear-figlet/Text/Figlet.php';
25
26 $figlet = new Text_Figlet();
27 $figlet->loadFont($map[$font]);
28
29 $result = $figlet->lineEcho($content);
30
31 $engine = $this->getEngine();
32
33 if ($engine->isTextMode()) {
34 return $result;
35 }
36
37 if ($engine->isHTMLMailMode()) {
38 return phutil_tag('pre', array(), $result);
39 }
40
41 return phutil_tag(
42 'div',
43 array(
44 'class' => 'PhabricatorMonospaced remarkup-figlet',
45 ),
46 $result);
47 }
48
49 private static function getFigletMap() {
50 $root = dirname(phutil_get_library_root('phabricator'));
51
52 $dirs = array(
53 $root.'/externals/figlet/fonts/',
54 $root.'/externals/pear-figlet/fonts/',
55 $root.'/resources/figlet/custom/',
56 );
57
58 $map = array();
59 foreach ($dirs as $dir) {
60 foreach (Filesystem::listDirectory($dir, false) as $file) {
61 if (preg_match('/\.flf\z/', $file)) {
62 $name = phutil_utf8_strtolower($file);
63 $name = preg_replace('/\.flf\z/', '', $name);
64 $map[$name] = $dir.$file;
65 }
66 }
67 }
68
69 return $map;
70 }
71
72 public function getDocumentation() {
73 return <<<EOT
74= Figlet
75The `figlet` interpreter allows you to write some large text.
76For example, this:
77
78```figlet{{{Some big text!}}}```
79
80...produces this:
81
82figlet{{{Some big text!}}}
83
84[[/reference/figlet/ | More information about Figlet]] is available.
85EOT;
86 }
87}