mirror of
https://github.com/typecho/typecho.git
synced 2025-04-21 18:21:53 +02:00
fix #1034
This commit is contained in:
parent
1cc3066569
commit
f9dfb1bb85
File diff suppressed because one or more lines are too long
@ -291,7 +291,7 @@
|
||||
};
|
||||
|
||||
Parser.prototype.parseInline = function(text, whiteList, clearHolders, enableAutoLink) {
|
||||
var parseBackSlash, regex;
|
||||
var regex;
|
||||
if (whiteList == null) {
|
||||
whiteList = '';
|
||||
}
|
||||
@ -301,20 +301,7 @@
|
||||
if (enableAutoLink == null) {
|
||||
enableAutoLink = true;
|
||||
}
|
||||
parseBackSlash = (function(_this) {
|
||||
return function(text) {
|
||||
return text.replace(/\\{1,}/g, function(str) {
|
||||
return str.length % 2 > 0 && '' + str + '\\' || str;
|
||||
});
|
||||
};
|
||||
})(this);
|
||||
text = this.call('beforeParseInline', text);
|
||||
text = String.raw`` + text + '';
|
||||
text = text.split(/(`.+?`)/g).reduce(function(str, cur) {
|
||||
str = str || '';
|
||||
cur = cur || '';
|
||||
return ((str.match(/`.+?`/g)) && str || parseBackSlash(str)) + ((cur.match(/`.+?`/g)) && cur || parseBackSlash(cur));
|
||||
});
|
||||
text = text.replace(/(^|[^\\])(`+)(.+?)\2/mg, (function(_this) {
|
||||
return function() {
|
||||
var matches;
|
||||
@ -331,11 +318,12 @@
|
||||
})(this));
|
||||
text = text.replace(/\\(.)/g, (function(_this) {
|
||||
return function() {
|
||||
var escaped, matches;
|
||||
var escaped, matches, prefix;
|
||||
matches = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
prefix = matches[1].match(/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/) ? '' : '\\';
|
||||
escaped = htmlspecialchars(matches[1]);
|
||||
escaped = escaped.replace(/\$/g, '$');
|
||||
return _this.makeHolder(escaped);
|
||||
return _this.makeHolder(prefix + escaped);
|
||||
};
|
||||
})(this));
|
||||
text = text.replace(/<(https?:\/\/.+)>/ig, (function(_this) {
|
||||
|
@ -380,25 +380,6 @@ class HyperDown
|
||||
$self = $this;
|
||||
$text = $this->call('beforeParseInline', $text);
|
||||
|
||||
// 处理``之外的\字符
|
||||
preg_match_all('/`.+?`/', $text, $matches);
|
||||
$delimiters = $matches[0];
|
||||
$lineTextArray = preg_split('/`.+?`/', $text);
|
||||
$lineTextArray = array_map(function ($str) {
|
||||
return preg_replace_callback("/\\\+/", function ($matches) {
|
||||
$str = $matches[0];
|
||||
if (mb_strlen($str) % 2 > 0) {
|
||||
return $str . '\\';
|
||||
} else {
|
||||
return $str;
|
||||
}
|
||||
}, $str);
|
||||
}, $lineTextArray);
|
||||
$text = '';
|
||||
do {
|
||||
$text .= array_shift($lineTextArray) . array_shift($delimiters);
|
||||
} while ($lineTextArray);
|
||||
|
||||
// code
|
||||
$text = preg_replace_callback(
|
||||
"/(^|[^\\\])(`+)(.+?)\\2/",
|
||||
@ -425,9 +406,10 @@ class HyperDown
|
||||
$text = preg_replace_callback(
|
||||
"/\\\(.)/u",
|
||||
function ($matches) use ($self) {
|
||||
$prefix = preg_match("/^[-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]$/", $matches[1]) ? '' : '\\';
|
||||
$escaped = htmlspecialchars($matches[1]);
|
||||
$escaped = str_replace('$', '$', $escaped);
|
||||
return $self->makeHolder($escaped);
|
||||
return $self->makeHolder($prefix . $escaped);
|
||||
},
|
||||
$text
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user