| ... | ... | @@ -24,6 +24,7 @@ |
| 24 | 24 | |
| 25 | 25 | const std = @import("std"); |
| 26 | 26 | const range = @import("range").range; |
| 27 | const htmlentities = @import("htmlentities"); |
| 27 | 28 | |
| 28 | 29 | const tokenize = @import("./tokenize.zig"); |
| 29 | 30 | const astgen = @import("./astgen.zig"); |
| ... | ... | @@ -75,7 +76,14 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype |
| 75 | 76 | const TO = @TypeOf(x); |
| 76 | 77 | |
| 77 | 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 | 87 | return; |
| 80 | 88 | } |
| 81 | 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 | 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 | 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 | } |