diff --git a/website/scripts/sync-api-docs/generateMarkdown.js b/website/scripts/sync-api-docs/generateMarkdown.js index 4b16464b307..4021f484f93 100644 --- a/website/scripts/sync-api-docs/generateMarkdown.js +++ b/website/scripts/sync-api-docs/generateMarkdown.js @@ -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 + + '
' + + platform[0].trim() + + '
'; + } + tableRows = tableRows + tag + '
'; + }); + tableRows = tableRows.replace(/$/, ''); + } else { + tableRows = prop.rnTags.type.join('
'); + } + } 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} : {}), }, ]); @@ -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' : '') + diff --git a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js index 3732e45fa0e..fa2c7ae93a9 100644 --- a/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js +++ b/website/scripts/sync-api-docs/preprocessGeneratedApiDocs.js @@ -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); + }); + } } }