简体   繁体   English

我应该使用哪个JavaScript库进行客户端连字?

[英]Which JavaScript library should I use for client-side hyphenation?

I would like to implement client-side hyphenation via JavaScript on some large texts on my site. 我想在我的网站上的一些大文本上通过JavaScript实现客户端连字。 (I know about CSS3 hyphenation and will use it instead when available, but it's usually not available.) (我知道CSS3连字符,并且会在可用时使用它,但它通常不可用。)

I have been using Hyphenator.js , and it works well but is very large (my optimized, compiled build with just English comes out to 106 KB) and pretty slow. 我一直在使用Hyphenator.js ,它运行良好,但是非常大(我的优化,编译版本只有英文版本达到106 KB)而且非常慢。 It's large and slow enough that I'm considering dropping hyphenation altogether. 它足够大而且速度慢,我正在考虑完全删除连字符。 It's just a luxury anyway. 无论如何,这只是一种奢侈品。

But recently I came across what seems to be an alternative: Hypher . 但最近我遇到了似乎是另一种选择: Hypher What baffles me is how Hypher can me so much smaller and do the same thing. 令我感到困惑的是,Hypher如何让我这么小,做同样的事情。 I'm wondering if anybody can explain this. 我想知道是否有人可以解释这一点。

Does Hypher work just as well? Hypher也能正常工作吗? Is there any reason to use Hyphenator.js instead? 是否有任何理由使用Hyphenator.js? Hypher's readme has a link to Hyphenator.js at the bottom of the page , but none of the text explains the connection between these projects. Hypher的自述文件在页面底部有一个指向Hyphenator.js的链接,但没有一个文本解释了这些项目之间的联系。

Does anybody have an opinion about the most efficient client-side hyphenation? 有没有人对最有效的客户端连字法有什么看法?

The primary reason Hypher's so small, comparatively, is that it relies on an externally-loaded jQuery for page integration. 相比之下,Hypher如此小的主要原因是它依赖于外部加载的jQuery来进行页面集成。 Hyphenator.js is completely standalone and thus has to include way more boilerplate for manipulating HTML across browsers. Hyphenator.js是完全独立的,因此必须包含更多样板来跨浏览器操作HTML。 (They even re-implement some jQuery functionality.) (他们甚至重新实现了一些jQuery功能。)

To be fair, Hyphenator.js is a relatively old project that hasn't been completely rewritten along the way to take advantage of substantial browser improvements. 公平地说,Hyphenator.js是一个相对较旧的项目,在利用浏览器大量改进的过程中还没有完全重写。 (Note that they proudly support Firefox 3.0.) And, more charitably, Hyphenator.js has many more finely-grained settings . (请注意,他们自豪地支持Firefox 3.0。)更重要的是,Hyphenator.js有更多细粒度的设置

If you're already using jQuery, and don't use Hyphenator.js's advanced API, switching to Hypher may be a worthwhile improvement. 如果您已经在使用jQuery,并且不使用Hyphenator.js的高级API,那么切换到Hypher可能是值得改进的。

I had a look at hyphenation in JavaScript and found the following four libraries: 我在JavaScript中看了一下连字符,发现了以下四个库:

  • hy-phen : Is a pure JavaScript library developed by Yevhen Tiurin since 2016 using the MIT license. hy-phen :是自2016年以来由Yevhen Tiurin使用MIT许可证开发的纯JavaScript库。 You are offered a JavaScript function that you can call to hyphenate strings. 您将获得一个JavaScript函数,您可以调用连字符串。 You only need to include the main JavaScript file and the desired language file to use it. 您只需要包含主JavaScript文件和所需的语言文件即可使用它。
  • Hypher : Is a pure JavaScript library developed by Bram Stein since 2011 using the "Three Clause BSD" license. Hypher :自2011年以来由Bram Stein使用“Three Clause BSD”许可证开发的纯JavaScript库。 You are offered two JavaScript methods that you can call to hyphenate strings. 您可以使用两种JavaScript方法来调用连字符串。 It can only be installed using Node.js or jQuery. 它只能使用Node.js或jQuery安装。
  • Hyphenator.js : Is a JavaScript/HTML implementation developed by Mathias Nater since 2008 using the MIT license. Hyphenator.js :自2008年以来由Mathias Nater使用MIT许可证开发的JavaScript / HTML实现。 The project is discontinued since 2018. It is not so simple to include into your project - you need to use the Merge&Pack tool first to create a JavaScript file that you can then include. 该项目自2018起停止使用。要包含在项目中并不是那么简单 - 首先需要使用Merge&Pack工具来创建一个可以包含的JavaScript文件。 It automatically scans the HTML page and adds hyphenation to selected HTML elements. 它会自动扫描HTML页面并为选定的HTML元素添加连字符。 There is no JavaScript function that you can call to manually hyphenate strings. 没有JavaScript函数可以调用手动连字符串。
  • Hyphenopoly.js : Is the follow-up project of Hyphenator.js and developed since 2016 by Mathias Nater using the MIT license. Hyphenopoly.js :是Hyphenator.js的后续项目,自2016年起由Mathias Nater使用MIT许可证开发。 It dropped some features of Hyphenator.js and is a bit simpler to use. 它删除了Hyphenator.js的一些功能,使用起来有点简单。 Nevertheless it works the same way meaning there is no JavaScript function that you can call to manually hyphenate strings. 然而它的工作方式相同,这意味着没有可以调用手动连字符串的JavaScript函数。

All four libraries are using the hyphenation algorithm developed by Franklin M. Liang that uses matching patterns to find hyphenation points in words. 所有四个库都使用由Franklin M. Liang开发的连字算法,该算法使用匹配模式来查找单词中的连字点。 This algorithm does not provide 100% correct hyphenations as stated by Liang in his thesis : 该算法没有提供梁在他的论文中所述的100%正确的连字符:

These patterns find 89% of the hyphens in a pocket dictionary word list, with essentially no error. 这些模式在口袋字典单词列表中找到89%的连字符,基本上没有错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 哪个JavaScript库可用于客户端表单检查? - What JavaScript library to use for client-side form checking? 可以将ExactTarget与客户端JavaScript一起使用吗? - Is it possible to use ExactTarget with client-side JavaScript? 将变量从服务器端控制器传递到客户端,以在客户端JavaScript中使用 - Pass variable from server-side controller to client-side to use in client-side JavaScript 您是否对WebSocket使用任何客户端javascript库或jQuery插件? - Do you use any client-side javascript library or jQuery plugin for WebSockets? 我可以在服务器端使用某些客户端Javascript API吗? - Can I use certain client-side Javascript APIs server-side? 我需要在javascript /服务器端和客户端冲突中使用php变量 - I need to use php variables in javascript/ server-side and client-side conflict 我应该使用哪个 javascript 库? - Which javascript library should I use? 如何今天打包客户端Javascript库? - How to package a client-side Javascript library today? 是否有一个javascript客户端库,用于排队具有存储支持的ajax请求 - Is there a javascript client-side library for queuing ajax requests with storage support 如何在客户端使用estraverse js库? - how to use estraverse js library on client-side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM