yanntrividic / ragadjustfr

A bit of JavaScript to fix your text rag for prepositions, small words, or emphasis, adapted to the French language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ragadjust

A bit of JavaScript to automatically fix the rag of any body of text. Where you allow your lines to break in a block of text can be very important for readability, and quite tricky within a fluid layout. With this script you can set how and where you want your lines to break, creating a much more pleasing text rag.

This repository is a fork of Nathan Ford's work and was adapted to french by implementing support for diacritics and french prepositions. Nicolas Taffin helped me a lot in solving the bugs around regex, and turning this script into a Pagedjs handler; because yes, it also works with Pagedjs!

Setup

With a regular webpage

First, link to the script in your HTML, you'll only need the main script.

<script src="./js/ragadjust.js" type="text/javascript"></script>

</body>
</html>

Then, in your own JavaScript, set the parameters:

<script src="./js/ragadjust.js" type="text/javascript"></script>
<script type="text/javascript">

	ragadjust('p, li, dd', ['articles', 'prepositions'], ['en', 'mon']);

</script>

</body>
</html>

With Pagedjs

After setting up a Pagedjs project, you have to link the script and the handler to your HTML at the end of your body tag.

<script src="./js/ragadjust.js" type="text/javascript"></script>
<script src="./js/ragadjust-hook.js" type="text/javascript"></script>

</body>
</html>

Then, you'll have to edit the parameters of the ragadjust-hook.js file in order for it to match your needs.

Parameters

There are only three parameters to set:

ragadjust(elements, method, exceptions);
  • Elements – A CSS selector list of the elements you wish to modify.
  • Method – Choose which rag-adjust method you want to employ.
    • all – Employs all methods.
    • emphasis – Text of three or less words in bold or italics does not break across lines.
    • small-words – Breaks lines before words of three or less characters.
    • articles – Breaks lines before articles.
    • conjunctions – Breaks lines before conjunctions.
    • determiners – Breaks lines before determiners.
    • short_prepositions – Breaks lines before short prepositions.
    • prepositions – Breaks lines before the other prepositions.
    • pronouns – Breaks lines before pronouns.
    • dashes – Breaks lines before hyphens and dashes.
  • Exceptions – Specify a list of exceptions among the words that were picked for processing.

Support

Rag Adjust will work in all modern browsers and IE8+.

Appendix: Semantic breaks matched

Articles

  • un
  • une
  • le
  • la
  • les
  • du
  • de
  • des
  • au
  • aux

Determiners

  • ce
  • ces
  • cet
  • cette
  • mes
  • tes
  • ses
  • mon
  • ton
  • ma
  • ta
  • son
  • sa
  • notre
  • votre
  • leur
  • nos
  • vos
  • leurs

Pronouns

  • je
  • tu
  • il
  • elle
  • on
  • nous
  • vous
  • ils
  • elles

Conjunctions

  • mais
  • et
  • donc
  • or
  • ni
  • car
  • ou

Short prepositions

  • à
  • y
  • en
  • de
  • sur
  • par

Other prepositions

  • après
  • avant
  • avec
  • chez
  • concernant
  • contre
  • dans
  • depuis
  • derrière
  • dès
  • durant
  • entre
  • hormis
  • jusqu'à
  • jusque
  • loin
  • malgré
  • moyennant
  • outre
  • parmi
  • pour
  • près
  • sans
  • selon
  • sous
  • suivant
  • touchant
  • très
  • vers

About

A bit of JavaScript to fix your text rag for prepositions, small words, or emphasis, adapted to the French language

License:GNU Affero General Public License v3.0


Languages

Language:HTML 48.8%Language:JavaScript 26.8%Language:CSS 24.3%