这段HTML代码
<html dir="rtl">
<p>hello (world)</p>
</html>
您将看到这样的页面:
(hello (world
然而,如果我将HTML代码更改为
<html dir="rtl">
<p>hello (world) again</p>
</html>
然后文本会正常显示:
hello (world) again
有人能解释一下为什么会发生这种情况吗?如何修复第一个示例?
我的浏览器是Chrome。
这段HTML代码
<html dir="rtl">
<p>hello (world)</p>
</html>
您将看到这样的页面:
(hello (world
然而,如果我将HTML代码更改为
<html dir="rtl">
<p>hello (world) again</p>
</html>
然后文本会正常显示:
hello (world) again
有人能解释一下为什么会发生这种情况吗?如何修复第一个示例?
我的浏览器是Chrome。
你只需要在最后一个括号后面加上LRM字符。HTML实体:‎
<html dir="rtl">
<body>
<p>hello (world)‎</p>
</body></html>
这告诉浏览器把方括号解释为从左到右的阅读方式。
‎
很适合我。谢谢 :) - Kushal Jayswal或者更好的是您可以尝试使用CSS
*:after {
content: "\200E";
}
*:after {
content: "\200E";
}
*:before {
content: "\200E";
}
在(
前使用‏
。
例如:
<html dir="rtl">
<body>
<p>hello ‏(world)</p>
</body></html>
如果您正在使用JavaScript / SVG DOM,则
aText = $('<span>').html(aText.replace("(","‏(")).text();
$("<p>").html(aText);
对于其他特殊字符
function getRTLText(aText,aChar) {
if ( aText != undefined && aText.replace){
aChar = (aChar === undefined )?"(":aChar;
aText = $('<span>').html(aText.replace(aChar,"‏"+aChar)).text();
}
return aText;
}
并调用函数
getRTLText("三月 / 2018","/");
这是正确的从右到左文本括号呈现方式(显然)。这篇文章提供了更多信息。
http://www.i18nguy.com/markup/right-to-left.html
dir
属性现在已经不推荐使用了。
https://gist.github.com/dtbaker/b532e0e84a8cb7f22f26
function dtbaker_rtl_bracket_hack($content){
if(is_rtl()){
$content = preg_replace('#<p>([^<]+)\)\s*</p>#','<p>$1)‎</p>',$content);
$content = preg_replace('#<p>\s*\(([^<]+)</p>#','<p>‎($1</p>',$content);
}
return $content;
}
add_filter('the_content','dtbaker_rtl_bracket_hack',100,1);