自动插入 LTR 标记 [英] Inserting LTR marks automatically

查看:24
本文介绍了自动插入 LTR 标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个项目处理双向文本(混合英语和希伯来语).文本以 HTML 格式显示,因此有时需要 LTR 或 RTL 标记(‎‏)来制作弱字符",如标点符号显示适当地.由于技术限制,这些标记在源文本中不存在,因此我们需要添加它们以使最终显示的文本正确显示.

I am working with bidirectional text (mixed English and Hebrew) for a project. The text is displayed in HTML, so sometimes a LTR or RTL mark (‎ or ‏) is required to make 'weak characters' like punctuation display properly. These marks are not present in the source text due to technical limitations, so we need to add them in order for the final displayed text to appear correct.

例如,以下文本:(example: מדגם) sample 在从右到左模式下呈现为 sample (מדגם :example).更正后的字符串看起来像 ‎(example:‎ מדגם) sample 并将呈现为 sample (מדגם (example:.

For instance, the following text: (example: מדגם) sample renders as sample (מדגם :example) in right-to-left mode. The corrected string would look like ‎(example:‎ מדגם) sample and would render as sample (מדגם (example:.

我们希望即时插入这些标记,而不是重新创作所有文本.起初这看起来很简单:只需在每个标点符号实例后附加一个 ‎ 即可.但是,一些需要即时修改的文本包含 HTML 和 CSS.造成这种情况的原因令人遗憾且不可避免.

We'd like to do on-the-fly insertion of these marks rather than re-authoring all the text. At first this seems simple: just append an ‎ to each instance of punctuation. However, some of the text that needs to get modified on-the-fly contains HTML and CSS. The reasons for this are unfortunate and unavoidable.

解析 HTML/CSS 的短文,是否有一种已知的算法来即时插入 Unicode 方向标记(伪强字符)?

推荐答案

我不知道有什么算法可以安全地将方向标记插入 HTML 字符串而不对其进行解析.将 HTML 解析为 DOM 并操作文本节点是确保您不会意外地向

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆