| ... | @@ -24,6 +24,7 @@ | ... | @@ -24,6 +24,7 @@ |
| 24 | | 24 | |
| 25 | const std = @import("std"); | 25 | const std = @import("std"); |
| 26 | const range = @import("range").range; | 26 | const range = @import("range").range; |
| | 27 | const htmlentities = @import("htmlentities"); |
| 27 | | 28 | |
| 28 | const tokenize = @import("./tokenize.zig"); | 29 | const tokenize = @import("./tokenize.zig"); |
| 29 | const astgen = @import("./astgen.zig"); | 30 | const astgen = @import("./astgen.zig"); |
| ... | @@ -75,7 +76,14 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -75,7 +76,14 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 75 | const TO = @TypeOf(x); | 76 | const TO = @TypeOf(x); |
| 76 | | 77 | |
| 77 | if (comptime std.meta.trait.isZigString(TO)) { | 78 | if (comptime std.meta.trait.isZigString(TO)) { |
| 78 | try writer.print("{s}", .{x}); | 79 | const s: []const u8 = x; |
| | 80 | for (s) |c| { |
| | 81 | if (entityLookupBefore(&[_]u8{c})) |ent| { |
| | 82 | try writer.writeAll(ent.entity); |
| | 83 | } else { |
| | 84 | try writer.writeAll(&[_]u8{c}); |
| | 85 | } |
| | 86 | } |
| 79 | return; | 87 | return; |
| 80 | } | 88 | } |
| 81 | @compileError("pek: compile: unsupported type: " ++ @typeName(TO)); | 89 | @compileError("pek: compile: unsupported type: " ++ @typeName(TO)); |
| ... | @@ -101,3 +109,15 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype | ... | @@ -101,3 +109,15 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 101 | fn search(comptime T: anytype, comptime args: []const []const u8) @TypeOf(if (args.len == 1) @field(T, args[0]) else search(@field(T, args[0]), args[1..])) { | 109 | fn search(comptime T: anytype, comptime args: []const []const u8) @TypeOf(if (args.len == 1) @field(T, args[0]) else search(@field(T, args[0]), args[1..])) { |
| 102 | return if (args.len == 1) @field(T, args[0]) else search(@field(T, args[0]), args[1..]); | 110 | return if (args.len == 1) @field(T, args[0]) else search(@field(T, args[0]), args[1..]); |
| 103 | } | 111 | } |
| | 112 | |
| | 113 | fn entityLookupBefore(in: []const u8) ?htmlentities.Entity { |
| | 114 | for (htmlentities.ENTITIES) |e| { |
| | 115 | if (!std.mem.endsWith(u8, e.entity, ";")) { |
| | 116 | continue; |
| | 117 | } |
| | 118 | if (std.mem.eql(u8, e.characters, in)) { |
| | 119 | return e; |
| | 120 | } |
| | 121 | } |
| | 122 | return null; |
| | 123 | } |