" + ... + blockCount = blockCount + 1; + blocks(blockCount, 1) = "
" + ... renderApiText(value, api, item, outputPath) + "
"; end end - html = strjoin(blocks, newline); + html = strjoin(blocks(1:blockCount), newline); end function html = renderApiText(text, api, item, outputPath) protected = string(text); - replacements = strings(0, 1); + replacements = strings(strlength(protected), 1); + replacementCount = 0; symbols = string({api.symbol}); symbols(symbols == string(item.symbol)) = []; [~, order] = sort(strlength(symbols), "descend"); @@ -251,15 +273,17 @@ end target = "reference/api/" + replace(symbol, ".", "/") + ... ".html"; - replacements(end + 1, 1) = ... + replacementCount = replacementCount + 1; + replacements(replacementCount, 1) = ... "" + ...
htmlEscape(symbol) + "";
- marker = "@@LABKITAPILINK" + string(numel(replacements)) + "@@";
+ marker = "@@LABKITAPILINK" + string(replacementCount) + "@@";
protected = extractBefore(protected, first) + marker + ...
extractAfter(protected, last);
end
end
+ replacements = replacements(1:replacementCount);
html = htmlEscape(protected);
for k = 1:numel(replacements)
marker = "@@LABKITAPILINK" + string(k) + "@@";
@@ -363,7 +387,8 @@
'[A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z][A-Za-z0-9_]*)*', ...
'match'));
symbols = string({api.symbol});
- indices = zeros(1, 0);
+ indices = zeros(1, numel(tokens));
+ indexCount = 0;
for k = 1:numel(tokens)
token = tokens(k);
index = find(symbols == token, 1);
@@ -372,15 +397,16 @@
end
if isempty(index) && ~contains(token, ".")
suffixMatches = find(endsWith(symbols, "." + token));
- if numel(suffixMatches) == 1
+ if isscalar(suffixMatches)
index = suffixMatches;
end
end
if ~isempty(index)
- indices(end + 1) = index;
+ indexCount = indexCount + 1;
+ indices(indexCount) = index;
end
end
- indices = unique(indices, "stable");
+ indices = unique(indices(1:indexCount), "stable");
end
function value = displaySectionTitle(value)
diff --git a/tools/docs/private/renderLabKitApiIndex.m b/tools/docs/private/renderLabKitApiIndex.m
index b3d1c6199..9f20e7f0c 100644
--- a/tools/docs/private/renderLabKitApiIndex.m
+++ b/tools/docs/private/renderLabKitApiIndex.m
@@ -6,16 +6,16 @@
api = model.api;
groups = apiGroups(api);
- blocks = strings(0, 1);
- words = strings(0, 1);
+ blocks = strings(numel(groups), 1);
+ words = strings(numel(groups), 1);
for k = 1:numel(groups)
items = api(groups(k).indices);
[target, label] = categoryTarget(model, items, groups(k));
rows = "" + htmlEscape(groups(k).description) + ... "
| Function | " + ... @@ -49,8 +49,6 @@ end function groups = apiGroups(api) - groups = repmat(struct("id", "", "title", "", "description", "", ... - "indices", []), 0, 1); symbols = string({api.symbol}); origin = string({api.origin}); libraryIndices = find(origin == "library" & ... @@ -62,25 +60,31 @@ libraryKeys(k) = strjoin(parts(1:depth), "."); end keys = unique(libraryKeys, "stable"); + appIndices = find(origin == "app"); + owners = string({api(appIndices).owner}); + ownerKeys = unique(owners, "stable"); + template = struct("id", "", "title", "", "description", "", ... + "indices", []); + groups = repmat(template, numel(keys) + numel(ownerKeys), 1); + groupCount = 0; for k = 1:numel(keys) key = keys(k); indices = libraryIndices(libraryKeys == key); - groups(end + 1, 1) = struct( ... + groupCount = groupCount + 1; + groups(groupCount, 1) = struct( ... "id", slug(key), ... "title", libraryTitle(key), ... "description", libraryDescription(key), ... "indices", indices(:).'); end - appIndices = find(origin == "app"); if ~isempty(appIndices) - owners = string({api(appIndices).owner}); - ownerKeys = unique(owners, "stable"); for k = 1:numel(ownerKeys) owner = ownerKeys(k); indices = appIndices(owners == owner); family = string(api(indices(1)).family); - groups(end + 1, 1) = struct( ... + groupCount = groupCount + 1; + groups(groupCount, 1) = struct( ... "id", "app-" + slug(owner), ... "title", humanize(owner) + " App API", ... "description", "Supported GUI-free operations owned by the " + ... @@ -88,6 +92,7 @@ "indices", indices(:).'); end end + groups = groups(1:groupCount); end function title = libraryTitle(key) @@ -158,11 +163,6 @@ end end -function value = cleanSummary(value) - value = string(value); - value = regexprep(value, '^[A-Z][A-Z0-9_]*\s+', ''); -end - function value = humanize(value) value = replace(string(value), "_", " "); words = split(value); diff --git a/tools/docs/private/renderLabKitMarkdown.m b/tools/docs/private/renderLabKitMarkdown.m index 84f2e5e0d..0b615ee2f 100644 --- a/tools/docs/private/renderLabKitMarkdown.m +++ b/tools/docs/private/renderLabKitMarkdown.m @@ -2,63 +2,79 @@ %RENDERLABKITMARKDOWN Render the repository's documented Markdown subset. lines = readlines(page.sourcePath, "EmptyLineRule", "read"); - output = strings(0, 1); - plain = strings(0, 1); + output = strings(2 * numel(lines) + 2, 1); + plain = strings(numel(lines), 1); + outputCount = 0; + plainCount = 0; index = 1; listType = ""; inCode = false; codeLanguage = ""; - codeLines = strings(0, 1); + codeLines = strings(numel(lines), 1); + codeLineCount = 0; while index <= numel(lines) line = lines(index); trimmed = strtrim(line); if inCode if startsWith(trimmed, "```") - output(end + 1, 1) = "
|---|