Simple text editor based on tiptap. HTML format.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

136 lines
3.4 KiB

  1. const defaultEnvName = "ar";
  2. export default class Environment {
  3. constructor(options = {}) {
  4. this.name = options.name ? options.name : defaultEnvName;
  5. this.defaultOptions = {
  6. paragraphs: {
  7. T1: true,
  8. T2: true,
  9. T3: true,
  10. T4: true,
  11. quote: true
  12. },
  13. characters: [
  14. {
  15. label: "mot",
  16. styles: [
  17. {
  18. "label": "étranger",
  19. "class": "foreign"
  20. },
  21. {
  22. "label": "accronyme",
  23. "class": "acronym"
  24. }
  25. ]
  26. },
  27. {
  28. label: "nom",
  29. styles: [
  30. {
  31. "label": "Auteur - Citation",
  32. "class": "author-quotation"
  33. },
  34. {
  35. "label": "Auteur - Œuvre",
  36. "class": "author-work"
  37. },
  38. {
  39. "label": "Marque",
  40. "class": "brand"
  41. },
  42. {
  43. "label": "Nom œuvre",
  44. "class": "work"
  45. },
  46. {
  47. "label": "Nom propre",
  48. "class": "proper-noun"
  49. }
  50. ]
  51. },
  52. {
  53. label: "numéral",
  54. styles: [
  55. {
  56. "label": "siècle",
  57. "class": "century"
  58. },
  59. {
  60. "label": "date",
  61. "class": "date"
  62. }
  63. ]
  64. },
  65. {
  66. label: "typo",
  67. styles: [
  68. {
  69. "label": "indice",
  70. "class": "subscript"
  71. },
  72. {
  73. "label": "exposant",
  74. "class": "superscript"
  75. }
  76. ]
  77. }
  78. ],
  79. };
  80. this.setOptions({
  81. ...this.defaultOptions,
  82. ...options,
  83. })
  84. }
  85. setOptions(options) {
  86. this.options = {
  87. ...this.options,
  88. ...options,
  89. }
  90. }
  91. hasParagraphOption(optionKey) {
  92. return this.options.paragraphs[optionKey] | false;
  93. }
  94. getCharacterOptions() {
  95. return this.options.characters;
  96. }
  97. static async loadEnvironment(envName) {
  98. if (envName === defaultEnvName)
  99. return new Environment();
  100. else
  101. return Environment.loadEnvironmentFromJSONFile('/dedediteur/env/' + envName + '.json')
  102. }
  103. static async loadEnvironmentFromJSONFile(filePath) {
  104. let res = await fetch(filePath);
  105. let json = await res.json();
  106. return Environment.loadEnvironmentFromJSON(json);
  107. }
  108. static loadEnvironmentFromJSON(json) {
  109. return new Environment(json);
  110. }
  111. }