Skip to content

Commit 7197d9b

Browse files
committed
Add support for multiple tables per method to the documentation parser
1 parent ec7d2bb commit 7197d9b

File tree

3 files changed

+39
-29
lines changed

3 files changed

+39
-29
lines changed

docs/ElunaDoc/parser.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,34 @@ def __init__(self, name, data_type, description, default_value=None):
6868

6969
class MethodDoc(object):
7070
"""The documentation data of an Eluna method."""
71-
@params(self=object, name=str, description=str, table=TableDict, prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
72-
def __init__(self, name, description, table, prototypes, parameters, returned):
71+
@params(self=object, name=str, description=str, tables=[TableDict], prototypes=[str], parameters=[ParameterDoc], returned=[ParameterDoc])
72+
def __init__(self, name, description, tables, prototypes, parameters, returned):
7373
self.name = name
7474
self.prototypes = prototypes
75-
self.table = table
75+
self.tables = tables
7676
self.parameters = parameters
7777
self.returned = returned
78-
79-
if table:
80-
# Generate Markdown Table
81-
md_table = '| ' + ' | '.join(table['columns']) + ' |\n' # Header
82-
md_table += '| ' + ' | '.join(['---'] * len(table['columns'])) + ' |\n' # Separator
8378

84-
for row in table['values']:
85-
md_table += '| ' + ' | '.join(row) + ' |\n' # Rows
79+
if tables:
80+
html_tables = []
81+
82+
for table in tables:
83+
print("-------------")
84+
# Generate Markdown Table for each table
85+
md_table = '| ' + ' | '.join(table['columns']) + ' |\n' # Header
86+
md_table += '| ' + ' | '.join(['---'] * len(table['columns'])) + ' |\n' # Separator
87+
88+
for row in table['values']:
89+
md_table += '| ' + ' | '.join(row) + ' |\n' # Rows
90+
91+
# Convert the generated Markdown table to HTML
92+
html_table = markdown.markdown(md_table, extensions=['tables'])
8693

87-
self.table = markdown.markdown(md_table, extensions=['tables'])
94+
# Append the HTML table to the list
95+
html_tables.append(html_table)
96+
97+
# Combine all HTML tables into a single string (separated by two newlines)
98+
self.tables = ''.join(html_tables)
8899

89100
# Parse the description as Markdown.
90101
self.description = markdown.markdown(description)
@@ -182,7 +193,7 @@ def reset(self):
182193
self.returned = []
183194
self.method_name = None
184195
self.prototypes = []
185-
self.table = {}
196+
self.tables = []
186197

187198
def handle_class_body(self, match):
188199
text = match.group(1)
@@ -193,19 +204,20 @@ def handle_body(self, match):
193204
self.description += text + '\n'
194205

195206
def handle_table(self, line):
196-
self.table = {
207+
new_table = {
197208
"columns": [],
198209
"values": []
199210
}
211+
self.tables.append(new_table)
200212

201213
def handle_table_columns(self, match):
202-
if self.table:
203-
self.table["columns"] = match.group(1).split(", ")
214+
if self.tables:
215+
self.tables[-1]["columns"] = match.group(1).split(", ")
204216

205217
def handle_table_values(self, match):
206-
if self.table:
218+
if self.tables:
207219
values = re.findall(r'(?:[^,"]|"(?:\\.|[^"])*")+', match.group(1))
208-
self.table["values"].append([v.strip(' "') for v in values])
220+
self.tables[-1]["values"].append([v.strip(' "') for v in values])
209221

210222
def handle_param(self, match):
211223
data_type, name, default, description = match.group(1), match.group(2), match.group(3), match.group(4)
@@ -282,7 +294,7 @@ def make_prototype(parameters):
282294
# Format the method name into each prototype.
283295
self.prototypes = [proto.format(self.method_name) for proto in self.prototypes]
284296

285-
self.methods.append(MethodDoc(self.method_name, self.description, self.table, self.prototypes, self.params, self.returned))
297+
self.methods.append(MethodDoc(self.method_name, self.description, self.tables, self.prototypes, self.params, self.returned))
286298

287299
# Table of which handler is used to handle each regular expressions.
288300
regex_handlers = {
@@ -313,7 +325,7 @@ def make_prototype(parameters):
313325
proto_regex: [table_regex, param_regex, return_regex, proto_regex, comment_end_regex, body_regex],
314326
table_regex: [table_regex, table_columns_regex, param_regex, return_regex, comment_end_regex, body_regex],
315327
table_columns_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex],
316-
table_values_regex: [table_values_regex, param_regex, return_regex, comment_end_regex, body_regex],
328+
table_values_regex: [table_values_regex, table_regex, param_regex, return_regex, comment_end_regex, body_regex],
317329
param_regex: [table_regex, param_regex, return_regex, comment_end_regex, body_regex],
318330
return_regex: [return_regex, comment_end_regex],
319331
comment_end_regex: [end_regex],

docs/ElunaDoc/templates/method.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ <h2>{{ current_class.name }} Methods</h2>
4747
<p>For temporary documentation, please check the <a href="https://github.com/ElunaLuaEngine/Eluna/blob/master/LuaFunctions.cpp">LuaFunctions</a> source file.</p>
4848
{%- endif %}
4949

50-
{%- if current_method.table %}
50+
{%- if current_method.tables %}
5151
<div class="table-container">
52-
<p>
53-
{{ current_method.table }}
54-
</p>
52+
{{ current_method.tables }}
5553
</div>
5654
{%- endif %}
5755

methods/TrinityCore/PlayerMethods.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ namespace LuaPlayer
29392939
* Equips the given item or item entry to the given slot. Returns the equipped item or nil.
29402940
*
29412941
* @table
2942-
* @columns [Slot, ID]
2942+
* @columns [EquipSlot, ID]
29432943
* @values [EQUIPMENT_SLOT_HEAD, 0]
29442944
* @values [EQUIPMENT_SLOT_NECK, 1]
29452945
* @values [EQUIPMENT_SLOT_SHOULDERS, 2]
@@ -2960,11 +2960,10 @@ namespace LuaPlayer
29602960
* @values [EQUIPMENT_SLOT_RANGED, 17]
29612961
* @values [EQUIPMENT_SLOT_TABARD, 18]
29622962
*
2963-
* enum InventorySlots // 4 slots
2964-
* {
2965-
* INVENTORY_SLOT_BAG_START = 19,
2966-
* INVENTORY_SLOT_BAG_END = 23
2967-
* };
2963+
* @table
2964+
* @columns [BagSlot, ID]
2965+
* @values [INVENTORY_SLOT_BAG_START, 19]
2966+
* @values [INVENTORY_SLOT_BAG_END, 23]
29682967
*
29692968
* @proto equippedItem = (item, slot)
29702969
* @proto equippedItem = (entry, slot)
@@ -3859,6 +3858,7 @@ namespace LuaPlayer
38593858
player->SummonPet(entry, x, y, z, o, (PetType)petType, despwtime);
38603859
return 0;
38613860
}
3861+
38623862
/**
38633863
* Removes the [Player]'s active pet.
38643864
*

0 commit comments

Comments
 (0)