zig-pug 4.0.6 → 4.0.8

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/binding.c CHANGED
@@ -23,6 +23,8 @@ extern void zigpug_free_string(char* str);
23
23
  extern const char* zigpug_version(void);
24
24
  extern size_t zigpug_get_error_count(ZigPugContext* ctx);
25
25
  extern int zigpug_get_error(ZigPugContext* ctx, size_t index, size_t* line_out, const char** message_out, const char** detail_out, const char** hint_out);
26
+ extern char* zigpug_pretty_print(const char* html, int include_comments);
27
+ extern char* zigpug_minify(const char* html);
26
28
 
27
29
  // Wrapper for ZigPugContext to store in JavaScript
28
30
  typedef struct {
@@ -601,6 +603,117 @@ static napi_value Version(napi_env env, napi_callback_info info) {
601
603
  return result;
602
604
  }
603
605
 
606
+ // Pretty-print HTML with optional comments
607
+ // JavaScript: const formatted = zigpug.prettyPrint(html, includeComments)
608
+ static napi_value PrettyPrint(napi_env env, napi_callback_info info) {
609
+ napi_status status;
610
+ size_t argc = 2;
611
+ napi_value args[2];
612
+
613
+ status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
614
+ if (status != napi_ok || argc < 2) {
615
+ napi_throw_error(env, NULL, "Expected 2 arguments: html, includeComments");
616
+ return NULL;
617
+ }
618
+
619
+ // Get HTML string
620
+ size_t html_len;
621
+ status = napi_get_value_string_utf8(env, args[0], NULL, 0, &html_len);
622
+ if (status != napi_ok) {
623
+ napi_throw_error(env, NULL, "Invalid HTML string");
624
+ return NULL;
625
+ }
626
+
627
+ char* html = malloc(html_len + 1);
628
+ status = napi_get_value_string_utf8(env, args[0], html, html_len + 1, &html_len);
629
+ if (status != napi_ok) {
630
+ free(html);
631
+ napi_throw_error(env, NULL, "Failed to get HTML string");
632
+ return NULL;
633
+ }
634
+
635
+ // Get includeComments boolean
636
+ bool include_comments;
637
+ status = napi_get_value_bool(env, args[1], &include_comments);
638
+ if (status != napi_ok) {
639
+ free(html);
640
+ napi_throw_error(env, NULL, "Invalid includeComments boolean");
641
+ return NULL;
642
+ }
643
+
644
+ // Call zig-pug pretty print
645
+ char* formatted = zigpug_pretty_print(html, include_comments ? 1 : 0);
646
+ free(html);
647
+
648
+ if (!formatted) {
649
+ napi_throw_error(env, NULL, "Failed to format HTML");
650
+ return NULL;
651
+ }
652
+
653
+ // Create JavaScript string
654
+ napi_value result;
655
+ status = napi_create_string_utf8(env, formatted, NAPI_AUTO_LENGTH, &result);
656
+ zigpug_free_string(formatted);
657
+
658
+ if (status != napi_ok) {
659
+ napi_throw_error(env, NULL, "Failed to create result string");
660
+ return NULL;
661
+ }
662
+
663
+ return result;
664
+ }
665
+
666
+ // Minify HTML
667
+ // JavaScript: const minified = zigpug.minify(html)
668
+ static napi_value Minify(napi_env env, napi_callback_info info) {
669
+ napi_status status;
670
+ size_t argc = 1;
671
+ napi_value args[1];
672
+
673
+ status = napi_get_cb_info(env, info, &argc, args, NULL, NULL);
674
+ if (status != napi_ok || argc < 1) {
675
+ napi_throw_error(env, NULL, "Expected 1 argument: html");
676
+ return NULL;
677
+ }
678
+
679
+ // Get HTML string
680
+ size_t html_len;
681
+ status = napi_get_value_string_utf8(env, args[0], NULL, 0, &html_len);
682
+ if (status != napi_ok) {
683
+ napi_throw_error(env, NULL, "Invalid HTML string");
684
+ return NULL;
685
+ }
686
+
687
+ char* html = malloc(html_len + 1);
688
+ status = napi_get_value_string_utf8(env, args[0], html, html_len + 1, &html_len);
689
+ if (status != napi_ok) {
690
+ free(html);
691
+ napi_throw_error(env, NULL, "Failed to get HTML string");
692
+ return NULL;
693
+ }
694
+
695
+ // Call zig-pug minify
696
+ char* minified = zigpug_minify(html);
697
+ free(html);
698
+
699
+ if (!minified) {
700
+ napi_throw_error(env, NULL, "Failed to minify HTML");
701
+ return NULL;
702
+ }
703
+
704
+ // Create JavaScript string
705
+ napi_value result;
706
+ status = napi_create_string_utf8(env, minified, NAPI_AUTO_LENGTH, &result);
707
+ zigpug_free_string(minified);
708
+
709
+ if (status != napi_ok) {
710
+ napi_throw_error(env, NULL, "Failed to create result string");
711
+ return NULL;
712
+ }
713
+
714
+ return result;
715
+ }
716
+
604
717
  // Initialize the N-API module
605
718
  static napi_value Init(napi_env env, napi_value exports) {
606
719
  napi_status status;
@@ -654,6 +767,18 @@ static napi_value Init(napi_env env, napi_value exports) {
654
767
  status = napi_set_named_property(env, exports, "version", fn);
655
768
  if (status != napi_ok) return NULL;
656
769
 
770
+ // prettyPrint
771
+ status = napi_create_function(env, NULL, 0, PrettyPrint, NULL, &fn);
772
+ if (status != napi_ok) return NULL;
773
+ status = napi_set_named_property(env, exports, "prettyPrint", fn);
774
+ if (status != napi_ok) return NULL;
775
+
776
+ // minify
777
+ status = napi_create_function(env, NULL, 0, Minify, NULL, &fn);
778
+ if (status != napi_ok) return NULL;
779
+ status = napi_set_named_property(env, exports, "minify", fn);
780
+ if (status != napi_ok) return NULL;
781
+
657
782
  return exports;
658
783
  }
659
784
 
package/index.js CHANGED
@@ -8,8 +8,14 @@ const path = require('path');
8
8
  const os = require('os');
9
9
 
10
10
  // Detect platform and architecture
11
- const platform = os.platform(); // 'linux', 'darwin', 'win32'
11
+ let platform = os.platform(); // 'linux', 'darwin', 'win32', 'android'
12
12
  const arch = os.arch(); // 'x64', 'arm64'
13
+
14
+ // Termux/Android reports 'android' but uses Linux binaries
15
+ if (platform === 'android') {
16
+ platform = 'linux';
17
+ }
18
+
13
19
  const platformKey = `${platform}-${arch}`;
14
20
 
15
21
  // Try to load prebuilt binary first
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zig-pug",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "High-performance Pug template engine powered by Zig and mujs. Native N-API addon with ES5.1 JavaScript support, full UTF-8 (emoji, accents), Builder API for dynamic data construction, comprehensive C/C++ API, and fast compilation. Compatible with Node.js and Bun.",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
Binary file