ether-code 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/compiler.js CHANGED
@@ -126,11 +126,15 @@ class EtherCompiler {
126
126
  }
127
127
 
128
128
  parse(content, target) {
129
+ const normalizedTarget = this.normalizeTarget(target)
130
+
131
+ if (normalizedTarget === 'html') {
132
+ return this.parseHTML(content)
133
+ }
134
+
129
135
  const lexer = new EtherLexer(content)
130
136
  const tokens = lexer.tokenize()
131
137
 
132
- const normalizedTarget = this.normalizeTarget(target)
133
-
134
138
  try {
135
139
  const ParserClass = this.loadParser(normalizedTarget)
136
140
  if (ParserClass) {
@@ -143,6 +147,13 @@ class EtherCompiler {
143
147
  return this.buildGenericAST(tokens, target)
144
148
  }
145
149
 
150
+ parseHTML(content) {
151
+ const { HTMLParser } = require('../parsers/html-parser')
152
+ const i18nPath = path.join(__dirname, '..', 'i18n', 'i18n-html.json')
153
+ const parser = new HTMLParser(i18nPath)
154
+ return parser.parse(content)
155
+ }
156
+
146
157
  loadParser(target) {
147
158
  try {
148
159
  const parserPath = path.join(__dirname, '..', 'parsers', `${target}-parser.js`)
@@ -212,8 +223,9 @@ class EtherCompiler {
212
223
  inferTargetFromContent(content) {
213
224
  const patterns = {
214
225
  html: [
215
- /\b(page|document|entête|corps|section|div|paragraphe|titre|lien|image|formulaire|bouton)\b/i,
216
- /\b(balise|élément|attribut)\b/i
226
+ /^html\b/im,
227
+ /\b(html|page|document|entête|entete|corps|section|div|paragraphe|titre|lien|image|formulaire|bouton)\b/i,
228
+ /\b(balise|élément|element|attribut)\b/i
217
229
  ],
218
230
  css: [
219
231
  /\b(style|couleur|taille|marge|bordure|fond|police|largeur|hauteur)\s*[:=]/i,
package/cli/ether.js CHANGED
@@ -6,7 +6,7 @@ const http = require('http')
6
6
  const { EtherCompiler } = require('./compiler')
7
7
  const { Watcher } = require('./watcher')
8
8
 
9
- const VERSION = '0.1.4'
9
+ const VERSION = '0.1.6'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
@@ -489,10 +489,48 @@ class HTMLGenerator {
489
489
  generateDocument(node) {
490
490
  this.writeLine('<!DOCTYPE html>')
491
491
  if (node.html) {
492
- this.generateNode(node.html)
492
+ this.generateNodeWithCharset(node.html)
493
493
  }
494
494
  }
495
495
 
496
+ generateNodeWithCharset(node) {
497
+ if (node.type === 'Element' && node.htmlTag === 'html') {
498
+ const tag = 'html'
499
+ const attributes = this.generateAttributes(node.attributes || [])
500
+ this.writeLine(`<${tag}${attributes}>`)
501
+ this.indent++
502
+
503
+ for (const child of (node.children || [])) {
504
+ if (child.htmlTag === 'head') {
505
+ this.generateHeadWithCharset(child)
506
+ } else {
507
+ this.generateNode(child)
508
+ }
509
+ }
510
+
511
+ this.indent--
512
+ this.writeLine(`</${tag}>`)
513
+ } else {
514
+ this.generateNode(node)
515
+ }
516
+ }
517
+
518
+ generateHeadWithCharset(node) {
519
+ const tag = 'head'
520
+ const attributes = this.generateAttributes(node.attributes || [])
521
+ this.writeLine(`<${tag}${attributes}>`)
522
+ this.indent++
523
+
524
+ this.writeLine('<meta charset="UTF-8">')
525
+
526
+ for (const child of (node.children || [])) {
527
+ this.generateNode(child)
528
+ }
529
+
530
+ this.indent--
531
+ this.writeLine(`</${tag}>`)
532
+ }
533
+
496
534
  generateTextNode(node) {
497
535
  if (node.value || node.content) {
498
536
  this.writeLine(this.escapeHtml(node.value || node.content))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {