tagsToClasses.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // transformer les balises [...] en <div class="..."> si ça correspond aux classes prédéfinies
  2. if (debug) console.log('start tagToClass');
  3. (function() {
  4. let baliseWords = [
  5. 'labeur',
  6. 'free',
  7. 'temps',
  8. 'moment',
  9. 'pilote',
  10. 'free_left',
  11. 'citation',
  12. 'latour',
  13. 'latour_nohead',
  14. 'lampe',
  15. 'lampe_nohead',
  16. 'note',
  17. 'bibliographie',
  18. 'imgsmall',
  19. 'imgsmallsmall',
  20. 'imgsmall_bottom',
  21. 'fullpage2imgs',
  22. 'fullpageimage',
  23. 'tripleimgs',
  24. 'tripleimgs_bottom',
  25. 'tripleimgs2',
  26. 'tripleimgs2_bottom',
  27. 'bottomimg',
  28. 'imgfullspreadleft',
  29. 'imgfullspreadright',
  30. 'imgfullspreadright_bleedtop',
  31. 'imgfullspreadright_bleed',
  32. 'breakbefore',
  33. 'breakafter',
  34. `doublepage_bigright`,
  35. `doublepage_bigleft`,
  36. `screenshot`,
  37. ];
  38. let bodyContent = $('#body').html();
  39. bodyContent = bodyContent.replace(/\[([^\/\]]+)\]/g, function(match, word) {
  40. if (baliseWords.includes(word)) {
  41. return word === 'note' ? `<span class="${ word }">` : `<div class="${ word }">`;
  42. } else {
  43. return match;
  44. }
  45. }).replace(/\[\/([^\]]+)\]/g, function(match, word) {
  46. if (baliseWords.includes(word)) {
  47. return word === 'note' ? '</span>' : '</div>';
  48. } else {
  49. return match;
  50. }
  51. });
  52. $('#body').empty().append(bodyContent);
  53. })();
  54. if (debug) console.log('end tagToClass');