mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
refactor(gen_vimdoc): put defgroup handling in a function
This commit is contained in:
@@ -46,6 +46,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
Element = minidom.Element
|
Element = minidom.Element
|
||||||
|
Document = minidom.Document
|
||||||
|
|
||||||
MIN_PYTHON_VERSION = (3, 6)
|
MIN_PYTHON_VERSION = (3, 6)
|
||||||
MIN_DOXYGEN_VERSION = (1, 9, 0)
|
MIN_DOXYGEN_VERSION = (1, 9, 0)
|
||||||
@@ -1089,6 +1090,42 @@ def delete_lines_below(filename, tokenstr):
|
|||||||
fp.writelines(lines[0:i])
|
fp.writelines(lines[0:i])
|
||||||
|
|
||||||
|
|
||||||
|
def extract_defgroups(base: str, dom: Document):
|
||||||
|
'''Generate module-level (section) docs (@defgroup).'''
|
||||||
|
section_docs = {}
|
||||||
|
|
||||||
|
for compound in dom.getElementsByTagName('compound'):
|
||||||
|
if compound.getAttribute('kind') != 'group':
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Doxygen "@defgroup" directive.
|
||||||
|
groupname = get_text(find_first(compound, 'name'))
|
||||||
|
groupxml = os.path.join(base, '%s.xml' %
|
||||||
|
compound.getAttribute('refid'))
|
||||||
|
|
||||||
|
group_parsed = minidom.parse(groupxml)
|
||||||
|
doc_list = []
|
||||||
|
brief_desc = find_first(group_parsed, 'briefdescription')
|
||||||
|
if brief_desc:
|
||||||
|
for child in brief_desc.childNodes:
|
||||||
|
doc_list.append(fmt_node_as_vimhelp(child))
|
||||||
|
|
||||||
|
desc = find_first(group_parsed, 'detaileddescription')
|
||||||
|
if desc:
|
||||||
|
doc = fmt_node_as_vimhelp(desc)
|
||||||
|
|
||||||
|
if doc:
|
||||||
|
doc_list.append(doc)
|
||||||
|
|
||||||
|
# Can't use '.' in @defgroup, so convert to '--'
|
||||||
|
# "vim.json" => "vim-dot-json"
|
||||||
|
groupname = groupname.replace('-dot-', '.')
|
||||||
|
|
||||||
|
section_docs[groupname] = "\n".join(doc_list)
|
||||||
|
|
||||||
|
return section_docs
|
||||||
|
|
||||||
|
|
||||||
def main(doxygen_config, args):
|
def main(doxygen_config, args):
|
||||||
"""Generates:
|
"""Generates:
|
||||||
|
|
||||||
@@ -1130,41 +1167,12 @@ def main(doxygen_config, args):
|
|||||||
|
|
||||||
fn_map_full = {} # Collects all functions as each module is processed.
|
fn_map_full = {} # Collects all functions as each module is processed.
|
||||||
sections = {}
|
sections = {}
|
||||||
section_docs = {}
|
|
||||||
sep = '=' * text_width
|
sep = '=' * text_width
|
||||||
|
|
||||||
base = os.path.join(output_dir, 'xml')
|
base = os.path.join(output_dir, 'xml')
|
||||||
dom = minidom.parse(os.path.join(base, 'index.xml'))
|
dom = minidom.parse(os.path.join(base, 'index.xml'))
|
||||||
|
|
||||||
# Generate module-level (section) docs (@defgroup).
|
section_docs = extract_defgroups(base, dom)
|
||||||
for compound in dom.getElementsByTagName('compound'):
|
|
||||||
if compound.getAttribute('kind') != 'group':
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Doxygen "@defgroup" directive.
|
|
||||||
groupname = get_text(find_first(compound, 'name'))
|
|
||||||
groupxml = os.path.join(base, '%s.xml' %
|
|
||||||
compound.getAttribute('refid'))
|
|
||||||
|
|
||||||
group_parsed = minidom.parse(groupxml)
|
|
||||||
doc_list = []
|
|
||||||
brief_desc = find_first(group_parsed, 'briefdescription')
|
|
||||||
if brief_desc:
|
|
||||||
for child in brief_desc.childNodes:
|
|
||||||
doc_list.append(fmt_node_as_vimhelp(child))
|
|
||||||
|
|
||||||
desc = find_first(group_parsed, 'detaileddescription')
|
|
||||||
if desc:
|
|
||||||
doc = fmt_node_as_vimhelp(desc)
|
|
||||||
|
|
||||||
if doc:
|
|
||||||
doc_list.append(doc)
|
|
||||||
|
|
||||||
# Can't use '.' in @defgroup, so convert to '--'
|
|
||||||
# "vim.json" => "vim-dot-json"
|
|
||||||
groupname = groupname.replace('-dot-', '.')
|
|
||||||
|
|
||||||
section_docs[groupname] = "\n".join(doc_list)
|
|
||||||
|
|
||||||
# Generate docs for all functions in the current module.
|
# Generate docs for all functions in the current module.
|
||||||
for compound in dom.getElementsByTagName('compound'):
|
for compound in dom.getElementsByTagName('compound'):
|
||||||
|
Reference in New Issue
Block a user