Skip to content

Commit 362dd6e

Browse files
committed
Repair of more invalid XML to allow for newlines in description output
Minor config formatting
1 parent 47026be commit 362dd6e

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

config.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,36 @@ Interface:
44
# Interface options
55
Initial expansion targets:
66
# These object category IDs will be expanded when the tree is initialized:
7-
[Food, MeleeWeapon, MissileWeapon, Armor, Shield, Token, LightSource, Tool, Tonic, Trinket, Energy Cell, Security Card, Barathrumite, SapientMutatedFlower]
7+
[Food, MeleeWeapon, MissileWeapon, Armor, Shield, Token, LightSource, Tool, Tonic, Trinket,
8+
Energy Cell, Security Card, Barathrumite, SapientMutatedFlower]
89

910
Templates:
1011
# Options controlling the generation of wiki infobox templates
1112
Fields:
1213
# The fields that (if applicable) will be generated for each item, in this order:
1314
# (title comes first, but is not listed here)
14-
[image, lv, pv, maxpv, vibro, pvpowered, hp, av, dv,
15-
ma, tohit, ammo, accuracy, shots, maxammo, maxvol,
16-
liquidgen, liquidtype, maxcharge, charge, weight, commerce,
17-
complexity, tier, bits, canbuild, skill, colorstr, renderstr, id,
18-
bookid, lightradius, hunger, thirst, twohanded, metal,
19-
lightprojectile, extra, strength, agility, toughness,
20-
intelligence, willpower, ego, acid, electric, cold, heat,
21-
desc]
15+
[image, lv, pv, maxpv, vibro, pvpowered, hp, av, dv, ma, tohit, ammo, accuracy, shots, maxammo,
16+
maxvol, liquidgen, liquidtype, maxcharge, charge, weight, commerce, complexity, tier, bits,
17+
canbuild, skill, colorstr, renderstr, id, bookid, lightradius, hunger, thirst, twohanded,
18+
metal, lightprojectile, extra, strength, agility, toughness, intelligence, willpower, ego,
19+
acid, electric, cold, heat, desc]
2220
Image overrides:
2321
# If the image for an object was uploaded under a different name than in the
2422
# game data, override it here:
2523
Asphodel: Earl_asphodel.png
2624

2725
Wiki:
2826
Categories:
27+
# Each wiki category is followed by a list of nodes in the inheritance tree whose child objects
28+
# should be in that category. Objects may also be explicitly specified.
2929
Items: [Item]
3030
Weapons: [MeleeWeapon, MissileWeapon]
3131
Equipment: [Armor, Shield]
3232
Energy cells: [Energy Cell]
3333
Thrown weapons: [BaseThrownWeapon]
3434
Plants: [Plant]
3535
Creatures: [Creature]
36-
Characters: [Phinae Hoshaiah, Barathrumite, Argyve, ElderBob, Mehmet, Warden Ualraig, Warden Esthers,
37-
Eskhind, Meyehind, Liihart, Isahind, Neelahind, Keh, Kesehind, Angohind, Lulihart, AgateSeveranceStar,
38-
Mayor Nuntu, Oboroqoru, Asphodel, Yurl, Euclid]
36+
Characters: [Phinae Hoshaiah, Barathrumite, Argyve, ElderBob, Mehmet, Warden Ualraig,
37+
Warden Esthers, Eskhind, Meyehind, Liihart, Isahind, Neelahind, Keh, Kesehind,
38+
Angohind, Lulihart, AgateSeveranceStar, Mayor Nuntu, Oboroqoru, Asphodel, Yurl,
39+
Euclid]

qud_object_tree.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@
1111

1212
def load(path):
1313
"""Load ObjectBlueprints.xml from the specified filepath and return a reference to the root."""
14-
# Do some repair of invalid XML
15-
pattern = re.compile("()|()")
16-
repaired = []
14+
# Do some repair of invalid XML:
15+
# First, delete some invalid characters
16+
pat_invalid = re.compile("()|()")
1717
with open(path, 'r', encoding='utf-8') as f:
18-
for line in f:
19-
repaired.append(pattern.sub('', line))
20-
raw = et.fromstringlist(repaired)
18+
contents = f.read()
19+
contents = re.sub(pat_invalid, '', contents)
20+
21+
# Second, replace line breaks inside attributes with proper XML line breaks
22+
# ^\s*<[^!][^>]*\n[^>]*>
23+
pat_linebreaks = r"^\s*<[^!][^>]*\n.*?>"
24+
match = re.search(pat_linebreaks, contents, re.MULTILINE)
25+
while match:
26+
before = match.string[:match.start()]
27+
fixed = match.string[match.start():match.end()].replace('\n', '&#10;')
28+
after = match.string[match.end():]
29+
contents = before + fixed + after
30+
match = re.search(pat_linebreaks, contents, re.MULTILINE)
31+
# Uncomment to have a diff-able file to double check XML repairs.
32+
# with open('test_output.xml', 'w', encoding='utf-8') as f:
33+
# f.write(contents)
34+
35+
raw = et.fromstring(contents)
2136

2237
# Build the Qud object hierarchy from the XML data
2338
for element in raw:

0 commit comments

Comments
 (0)