Path: blob/master/src/infrastructure/markup/blockrule/PhutilRemarkupNoteBlockRule.php
12241 views
<?php12final class PhutilRemarkupNoteBlockRule extends PhutilRemarkupBlockRule {34public function getMatchingLineCount(array $lines, $cursor) {5$num_lines = 0;67if (preg_match($this->getRegEx(), $lines[$cursor])) {8$num_lines++;9$cursor++;1011while (isset($lines[$cursor])) {12if (trim($lines[$cursor])) {13$num_lines++;14$cursor++;15continue;16}17break;18}19}2021return $num_lines;22}2324public function markupText($text, $children) {25$matches = array();26preg_match($this->getRegEx(), $text, $matches);2728if (idx($matches, 'showword')) {29$word = $matches['showword'];30$show = true;31} else {32$word = $matches['hideword'];33$show = false;34}3536$class_suffix = phutil_utf8_strtolower($word);3738// This is the "(IMPORTANT)" or "NOTE:" part.39$word_part = rtrim(substr($text, 0, strlen($matches[0])));4041// This is the actual text.42$text_part = substr($text, strlen($matches[0]));43$text_part = $this->applyRules(rtrim($text_part));4445$text_mode = $this->getEngine()->isTextMode();46$html_mail_mode = $this->getEngine()->isHTMLMailMode();47if ($text_mode) {48return $word_part.' '.$text_part;49}5051if ($show) {52$content = array(53phutil_tag(54'span',55array(56'class' => 'remarkup-note-word',57),58$word_part),59' ',60$text_part,61);62} else {63$content = $text_part;64}6566if ($html_mail_mode) {67if ($class_suffix == 'important') {68$attributes = array(69'style' => 'margin: 16px 0;70padding: 12px;71border-left: 3px solid #c0392b;72background: #f4dddb;',73);74} else if ($class_suffix == 'note') {75$attributes = array(76'style' => 'margin: 16px 0;77padding: 12px;78border-left: 3px solid #2980b9;79background: #daeaf3;',80);81} else if ($class_suffix == 'warning') {82$attributes = array(83'style' => 'margin: 16px 0;84padding: 12px;85border-left: 3px solid #f1c40f;86background: #fdf5d4;',87);88}89} else {90$attributes = array(91'class' => 'remarkup-'.$class_suffix,92);93}9495return phutil_tag(96'div',97$attributes,98$content);99}100101private function getRegEx() {102static $regex;103104if ($regex === null) {105$words = array(106'NOTE',107'IMPORTANT',108'WARNING',109);110111foreach ($words as $k => $word) {112$words[$k] = preg_quote($word, '/');113}114$words = implode('|', $words);115116$regex =117'/^(?:'.118'(?:\((?P<hideword>'.$words.')\))'.119'|'.120'(?:(?P<showword>'.$words.'):))\s*'.121'/';122}123124return $regex;125}126}127128129