diff --git a/web/app/models/HTML.php b/web/app/models/HTML.php
index f037f09..a361aef 100644
--- a/web/app/models/HTML.php
+++ b/web/app/models/HTML.php
@@ -144,8 +144,10 @@ class HTML {
public static function purifier() {
$config = HTMLPurifier_Config::createDefault();
- //$config->set('HTML.Doctype', 'HTML 4.01 Transitional');
- $config->set('Cache.DefinitionImpl', null);
+ // $config->set('Cache.DefinitionImpl', null);
+ $config->set('HTML.DefinitionID', 'UOJ__HTML::purifier()');
+ $config->set('HTML.DefinitionRev', 1);
+ $config->set('Output.Newline', true);
$def = $config->getHTMLDefinition(true);
$def->addElement('section', 'Block', 'Flow', 'Common');
@@ -155,6 +157,16 @@ class HTML {
$def->addElement('header', 'Block', 'Flow', 'Common');
$def->addElement('footer', 'Block', 'Flow', 'Common');
+ $extra_allowed_html = [
+ 'span' => ['data-realname' => 'Text', 'data-uoj-username' => 'Number'],
+ ];
+
+ foreach ($extra_allowed_html as $element => $attributes) {
+ foreach ($attributes as $attribute => $type) {
+ $def->addAttribute($element, $attribute, $type);
+ }
+ }
+
return new HTMLPurifier($config);
}
@@ -172,6 +184,7 @@ class HTML {
'small' => [],
'del' => [],
'br' => [],
+ 'span' => ['data-realname' => 'Text', 'data-uoj-username' => 'Number'],
];
$config = HTMLPurifier_Config::createDefault();
@@ -181,7 +194,7 @@ class HTML {
foreach ($allowed_html as $element => $attributes) {
$allowed_elements[$element] = true;
- foreach ($attributes as $attribute => $x) {
+ foreach ($attributes as $attribute => $type) {
$allowed_attributes["$element.$attribute"] = true;
}
}
@@ -189,6 +202,17 @@ class HTML {
$config->set('HTML.AllowedElements', $allowed_elements);
$config->set('HTML.AllowedAttributes', $allowed_attributes);
+ // $config->set('Cache.DefinitionImpl', null);
+ $config->set('HTML.DefinitionID', 'UOJ__HTML::purifier_inline()');
+ $config->set('HTML.DefinitionRev', 1);
+ $def = $config->getHTMLDefinition(true);
+
+ foreach ($allowed_html as $element => $attributes) {
+ foreach ($attributes as $attribute => $type) {
+ $def->addAttribute($element, $attribute, $type);
+ }
+ }
+
return new HTMLPurifier($config);
}
diff --git a/web/app/models/UOJMarkdown.php b/web/app/models/UOJMarkdown.php
index 641641d..64e2ded 100644
--- a/web/app/models/UOJMarkdown.php
+++ b/web/app/models/UOJMarkdown.php
@@ -54,16 +54,16 @@ class UOJMarkdown extends ParsedownMath {
// https://gist.github.com/ShNURoK42/b5ce8baa570975db487c
protected function inlineUserMention($Excerpt) {
if (preg_match('/^@([^\s]+)/', $Excerpt['text'], $matches)) {
- if (validateUsername($matches[1]) && ($user = queryUser($matches[1]))) {
+ if (validateUsername($matches[1]) && ($user = queryUser($matches[1])) && $user['usergroup'] != 'B') {
return [
'extent' => strlen($matches[0]),
'element' => [
- 'name' => 'a',
+ 'name' => 'span',
'text' => '@' . $user['username'],
'attributes' => [
- 'href' => '/user/' . $user['username'],
'class' => 'uoj-username',
'data-realname' => $user['realname'],
+ 'data-uoj-username' => 1,
],
],
];
diff --git a/web/js/uoj.js b/web/js/uoj.js
index 68d543c..3c1f465 100644
--- a/web/js/uoj.js
+++ b/web/js/uoj.js
@@ -428,7 +428,7 @@ $(document).ready(function() {
// highlight
$.fn.uoj_highlight = function() {
return $(this).each(function() {
- $(this).find("span.uoj-username").each(replaceWithHighlightUsername);
+ $(this).find("span.uoj-username, span[data-uoj-username]").each(replaceWithHighlightUsername);
$(this).find(".uoj-honor").uoj_honor();
$(this).find(".uoj-testcase").uoj_testcase();
$(this).find(".uoj-score").each(function() {