From 47f863c4daa897b511b7529bb558073410a50ebc Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 27 Jan 2016 17:08:11 -0800 Subject: [PATCH] Single quotes in enum values Summary: This was driving me crazy :p Turns out that if the value is `'auto' /* default */`, then the docparser will not only trim the comment but also normalize the quote to double quote. This is not pretty but does the job. Closes https://github.com/facebook/react-native/pull/5509 Reviewed By: svcscm Differential Revision: D2872482 Pulled By: vjeux fb-gh-sync-id: 8ba5dad695f747f82b7680ee26bdc0792e21ea8f --- website/layout/AutodocsLayout.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/website/layout/AutodocsLayout.js b/website/layout/AutodocsLayout.js index 13be4808a..d3b223449 100644 --- a/website/layout/AutodocsLayout.js +++ b/website/layout/AutodocsLayout.js @@ -20,12 +20,20 @@ var slugify = require('slugify'); var styleReferencePattern = /^[^.]+\.propTypes\.style$/; +function renderEnumValue(value) { + // Use single quote strings even when we are given double quotes + if (value.match(/^"(.+)"$/)) { + return "'" + value.slice(1, -1) + "'"; + } + return value; +} + function renderType(type) { if (type.name === 'enum') { if (typeof type.value === 'string') { return type.value; } - return 'enum(' + type.value.map((v) => v.value).join(', ') + ')'; + return 'enum(' + type.value.map((v) => renderEnumValue(v.value)).join(', ') + ')'; } if (type.name === 'shape') {