pagedown icon indicating copy to clipboard operation
pagedown copied to clipboard

New feature: hyphenation support using Hyphenopoly.js

Open RLesur opened this issue 5 years ago • 0 comments

Here's a proposal for #33 . It uses the Hyphenopoly.js library.

Hyphenopoly.js integration was not straightforward for many reasons:

  • Hyphenopoly.js must run first. In our context, this means before MathJax. Since MathJax is configured in the Pandoc template, we also have to configure Hyphenopoly.js in this template. Moreover, elements with a math class must not be hyphenated (otherwise, MathJax does not work properly). See /inst/resources/html/paged.html.
  • In the PR, I've deactivated hyphenation for titles (because I don't like hyphenated titles). Following the documentation, we have to declare a huge Hyphenopoly.setup.dontHyphenate object.
  • Hyphenopoly.js uses asm.js and WebAssembly. I did not find any implementation that would be compatible with self_contained = TRUE (but I am not familiar with these technologies). However, it seems that it is not yet possible. In this PR, the user cannot use self_contained = TRUE with hyphenation. Be careful, I've inverted the default value for self_contained (it could be confusing for users, tell me what do you prefer).
  • Hyphenopoly.js needs to know where its resource files are located. By default, Hyphenopoly.js search in these paths. Obviously, it does not work with rmarkdown. So, I had to write a script to dynamically find these paths. See inst/resources/js/Hyphenopoly/configHyphenopoly.js.
  • Language support. We have to declare which languages are used in the html file and provide a long word for each of these languages. I am not satisfied by what I've done with the Hyphenopoly.require object: I've forced the use of 6 languages. I think it would be better if the user could declare the languages with something like html_paged(lang = c('en-us', 'pt'), ...). But I did not find the way to implement such a solution. You can find the languages supported by Hyphenopoly.js in inst/resources/js/Hyphenopoly/patterns/.

RLesur avatar Dec 12 '18 01:12 RLesur