moxygen
Version:
Doxygen XML to Markdown converter
186 lines • 6.18 kB
JavaScript
export function createCompound(parent = null, id = '', name = '') {
return {
parent,
id,
name,
kind: '',
refid: '',
fullname: '',
shortname: '',
compounds: {},
members: [],
basecompoundref: [],
derivedcompoundref: [],
inheritedMemberGroups: [],
allMembers: [],
filtered: { compounds: [], members: [], sections: [] },
briefdescription: '',
detaileddescription: '',
summary: '',
proto: '',
namespace: '',
templateParams: [],
};
}
export function findCompound(root, id, name, create) {
let compound = root.compounds[id];
if (!compound && create) {
compound = createCompound(root, id, name);
root.compounds[id] = compound;
}
return compound;
}
/**
* Recursively collect compounds (and optionally filter by kind) into a flat array.
*/
export function toArray(compound, type = 'compounds', kind) {
if (type === 'members') {
return [...compound.members];
}
const entries = Object.values(compound.compounds);
const result = [];
for (const child of entries) {
if (!kind || child.kind === kind) {
result.push(child);
result.push(...toArray(child, type, kind));
}
}
return result;
}
/**
* Recursively collect filtered compounds into a flat array.
*/
export function toFilteredArray(compound, type = 'compounds') {
const items = (type === 'compounds'
? compound.filtered.compounds
: []);
const result = [];
for (const item of items) {
result.push(item);
result.push(...toFilteredArray(item, type));
}
return result;
}
/**
* Filter a collection by a key matching allowed categories, optionally scoped to a group.
*/
export function filterCollection(collection, key, allowedCategories, groupid) {
const categories = {};
const items = Array.isArray(collection)
? collection
: Object.values(collection);
for (const item of items) {
if (!item)
continue;
// Skip empty namespaces
if ('filtered' in item &&
item.kind === 'namespace') {
const c = item;
if ((!c.filtered.compounds || c.filtered.compounds.length === 0) &&
(!c.filtered.members || c.filtered.members.length === 0)) {
continue;
}
}
// Skip items not belonging to current group. Nested groups own their
// own groupid, but still belong in the parent group's topic list.
if (groupid) {
if ('filtered' in item) {
const compound = item;
const parent = compound.parent;
if (compound.groupid !== groupid && !(compound.kind === 'group' && parent?.id === groupid)) {
continue;
}
}
else if (item.groupid !== groupid) {
continue;
}
}
const categoryKey = item[key];
if (!categories[categoryKey]) {
categories[categoryKey] = [];
}
categories[categoryKey].push(item);
}
const result = [];
for (const category of allowedCategories) {
if (categories[category]) {
result.push(...categories[category]);
}
}
return result;
}
/**
* Apply filters recursively to a compound and all its children.
*/
export function filterChildren(compound, filters, groupid) {
const allCompounds = toArray(compound, 'compounds');
for (const child of allCompounds) {
child.filtered.members = filterCollection(child.members, 'section', filters.members, groupid);
child.filtered.compounds = filterCollection(child.compounds, 'kind', filters.compounds, groupid);
}
compound.filtered.members = filterCollection(compound.members, 'section', filters.members, groupid);
compound.filtered.compounds = filterCollection(compound.compounds, 'kind', filters.compounds, groupid);
}
const SECTION_LABELS = {
'public-type': 'Public Types',
'public-func': 'Public Methods',
'public-static-func': 'Public Static Methods',
'protected-func': 'Protected Methods',
'private-func': 'Private Methods',
'private-static-func': 'Private Static Methods',
'public-attrib': 'Public Attributes',
'public-static-attrib': 'Public Static Attributes',
'protected-attrib': 'Protected Attributes',
'private-attrib': 'Private Attributes',
'private-static-attrib': 'Private Static Attributes',
'signal': 'Signals',
'public-slot': 'Public Slots',
'protected-slot': 'Protected Slots',
'private-slot': 'Private Slots',
'property': 'Properties',
'enum': 'Enumerations',
'typedef': 'Typedefs',
'friend': 'Friends',
'define': 'Macros',
'func': 'Functions',
'var': 'Variables',
};
const NOISE_RE = /^(TYPE|BREAK|DEG|SEP|IMPL)_\d+$/;
/**
* Remove noisy members: undocumented destructors, internal macros,
* undocumented copy/move operators.
*/
export function filterNoise(members) {
return members.filter((m) => {
if (m.section === 'define' && !m.briefdescription && !m.detaileddescription)
return false;
if (m.name.startsWith('~') && !m.briefdescription && !m.detaileddescription)
return false;
if (NOISE_RE.test(m.name))
return false;
if (m.name === 'operator=' && !m.briefdescription && !m.detaileddescription)
return false;
return true;
});
}
/**
* Group filtered members by their section kind for structured output.
*/
export function groupMembersBySection(compound) {
const groups = {};
const order = [];
for (const member of compound.filtered.members) {
const key = member.section || 'func';
if (!groups[key]) {
groups[key] = [];
order.push(key);
}
groups[key].push(member);
}
return order.map((section) => ({
section,
label: SECTION_LABELS[section] || section,
members: groups[section],
}));
}
//# sourceMappingURL=compound.js.map