-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgen_entities.py
More file actions
36 lines (25 loc) · 755 Bytes
/
gen_entities.py
File metadata and controls
36 lines (25 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""
Converts entity WHATWG HTML5 entity summary into
Text.HTML.Parser.Entities module.
Usage:
curl https://html.spec.whatwg.org/entities.json | python3 gen_entities.py > src/Text/HTML/Parser/Entities.hs
"""
import sys
import json
entities = json.load(sys.stdin)
def escape(details):
return ''.join(f'\\x{cp:04x}' for cp in details['codepoints'])
print('''
{-# LANGUAGE OverloadedStrings #-}
-- | N.B. This file is generated by @gen_entities.py@. Do not edit.
module Text.HTML.Parser.Entities (entities) where
import Data.Text (Text)
entities :: [(Text, Text)]
entities = [
'''.strip())
print(',\n'.join(
f''' ("{name[1:-1]}", "{escape(details)}")'''
for name, details in entities.items()
))
print(' ]')