Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions website/scripts/sync-api-docs/generateMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,37 @@ function stringToInlineCodeForTable(str) {

// Formats information about a prop
function generateProp(propName, prop) {
let tableRows = '';

if (prop.rnTags && prop.rnTags.type) {
if (prop.rnTags.type.length) {
prop.rnTags.type.forEach(tag => {
const isMatch = tag.match(/{@platform [a-z]*}/);
if (isMatch) {
const platform = isMatch[0].match(/ [a-z]*/);
tag = tag.replace(/{@platform [a-z]*}/g, '');
tag =
tag +
'<div class="label ' +
platform[0].trim() +
'">' +
platform[0].trim() +
'</div>';
}
tableRows = tableRows + tag + '<hr/>';
});
tableRows = tableRows.replace(/<hr\/>$/, '');
} else {
tableRows = prop.rnTags.type.join('<hr/>');
}
} else tableRows = prop.flowType ? maybeLinkifyType(prop.flowType) : '';

const infoTable = generateTable([
{
Type: prop.flowType ? maybeLinkifyType(prop.flowType) : '',
Type: tableRows,
Required: prop.required ? 'Yes' : 'No',
...(prop.rnTags && prop.rnTags.platform
? {Platform: formatPlatformName(prop.rnTags.platform)}
...(prop.rnTags && prop.rnTags.default
? {Default: prop.rnTags.default}
: {}),
},
]);
Expand All @@ -68,6 +93,9 @@ function generateProp(propName, prop) {
'### `' +
propName +
'`' +
(prop.rnTags && prop.rnTags.platform
? formatPlatformName(prop.rnTags.platform)
: '') +
'\n' +
'\n' +
(prop.description ? prop.description + '\n\n' : '') +
Expand Down
18 changes: 18 additions & 0 deletions website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,33 @@ function joinDescriptionAndExamples(tokenized) {

function preprocessTagsInDescription(obj) {
if (obj && obj.description) {
obj.description = obj.description.split(' ').join('');
const descriptionTokenized = tokenizeComment(obj.description);
obj.description = joinDescriptionAndExamples(descriptionTokenized);

obj.rnTags = {};
const platformTag = descriptionTokenized.tags.find(
({key}) => key === 'platform'
);
const defaultTag = descriptionTokenized.tags.find(
({key}) => key === 'default'
);
const typeTag = descriptionTokenized.tags.filter(tag => {
return tag.key === 'type';
});

if (platformTag) {
obj.rnTags.platform = platformTag.value;
}
if (defaultTag) {
obj.rnTags.default = defaultTag.value;
}
if (typeTag.length) {
obj.rnTags.type = [];
typeTag.forEach(tag => {
obj.rnTags.type.push(tag.value);
});
}
}
}

Expand Down