Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/rule/PhabricatorKeyboardRemarkupRule.php
Show First 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | public function markupKeystrokes(array $matches) { | ||||
$map = array(); | $map = array(); | ||||
foreach ($special as $spec) { | foreach ($special as $spec) { | ||||
foreach ($spec['aliases'] as $alias) { | foreach ($spec['aliases'] as $alias) { | ||||
$map[$alias] = $spec; | $map[$alias] = $spec; | ||||
} | } | ||||
} | } | ||||
$is_text = $this->getEngine()->isTextMode(); | $is_text = $this->getEngine()->isTextMode(); | ||||
$is_html_mail = $this->getEngine()->isHTMLMailMode(); | |||||
if ($is_html_mail) { | |||||
$key_style = array( | |||||
'display: inline-block;', | |||||
'min-width: 1em;', | |||||
'padding: 4px 5px 5px;', | |||||
'font-weight: normal;', | |||||
'font-size: 0.8rem;', | |||||
'text-align: center;', | |||||
'text-decoration: none;', | |||||
'line-height: 0.6rem;', | |||||
'border-radius: 3px;', | |||||
'box-shadow: inset 0 -1px 0 rgba(71, 87, 120, 0.08);', | |||||
'user-select: none;', | |||||
'background: #f7f7f7;', | |||||
'border: 1px solid #C7CCD9;', | |||||
); | |||||
$key_style = implode(' ', $key_style); | |||||
$join_style = array( | |||||
'padding: 0 4px;', | |||||
'color: #92969D;', | |||||
); | |||||
$join_style = implode(' ', $join_style); | |||||
} else { | |||||
$key_style = null; | |||||
$join_style = null; | |||||
} | |||||
$parts = array(); | $parts = array(); | ||||
foreach ($keys as $k => $v) { | foreach ($keys as $k => $v) { | ||||
$normal = phutil_utf8_strtolower($v); | $normal = phutil_utf8_strtolower($v); | ||||
if (isset($map[$normal])) { | if (isset($map[$normal])) { | ||||
$spec = $map[$normal]; | $spec = $map[$normal]; | ||||
} else { | } else { | ||||
$spec = array( | $spec = array( | ||||
'name' => null, | 'name' => null, | ||||
'symbol' => $v, | 'symbol' => $v, | ||||
); | ); | ||||
} | } | ||||
if ($is_text) { | if ($is_text) { | ||||
$parts[] = '['.$spec['symbol'].']'; | $parts[] = '['.$spec['symbol'].']'; | ||||
} else { | } else { | ||||
$parts[] = phutil_tag( | $parts[] = phutil_tag( | ||||
'kbd', | 'kbd', | ||||
array( | array( | ||||
'title' => $spec['name'], | 'title' => $spec['name'], | ||||
'style' => $key_style, | |||||
), | ), | ||||
$spec['symbol']); | $spec['symbol']); | ||||
} | } | ||||
} | } | ||||
if ($is_text) { | if ($is_text) { | ||||
$parts = implode(' + ', $parts); | $parts = implode(' + ', $parts); | ||||
} else { | } else { | ||||
$glue = phutil_tag( | $glue = phutil_tag( | ||||
'span', | 'span', | ||||
array( | array( | ||||
'class' => 'kbd-join', | 'class' => 'kbd-join', | ||||
'style' => $join_style, | |||||
), | ), | ||||
'+'); | '+'); | ||||
$parts = phutil_implode_html($glue, $parts); | $parts = phutil_implode_html($glue, $parts); | ||||
} | } | ||||
return $this->getEngine()->storeText($parts); | return $this->getEngine()->storeText($parts); | ||||
} | } | ||||
} | } |