graphql-markdown
Advanced tools
Comparing version 1.3.0 to 2.0.0
{ | ||
"name": "graphql-markdown", | ||
"version": "1.3.0", | ||
"version": "2.0.0", | ||
"description": "Generate documentation for your GraphQL schema in Markdown", | ||
@@ -20,3 +20,2 @@ "main": "src/index.js", | ||
"graphql": "^0.9.1", | ||
"marked": "^0.3.6", | ||
"minimist": "^1.2.0", | ||
@@ -23,0 +22,0 @@ "node-fetch": "^1.6.3", |
@@ -67,9 +67,6 @@ # graphql-markdown | ||
Output is optimized for display on GitHub, using GitHub's Markdown renderer. | ||
Output is optimized for display on GitHub, using GitHub Flavored Markdown. | ||
Due to the complexity of the tables in the generated document, much of the | ||
output is HTML (as allowed by Markdown). Some of your GraphQL descriptions may | ||
be printed as-is (for GitHub to render) while others are pre-rendered by | ||
`graphql-markdown` (if they need to be included in certain HTML tags – GitHub | ||
will not render such content as Markdown). | ||
Due to the complexity of the tables in the generated document, much of the table | ||
output is HTML (as allowed by Markdown). | ||
@@ -76,0 +73,0 @@ |
'use strict' | ||
const marked = require('marked') | ||
// Ideally, we could just spit out the existing description Markdown everywhere | ||
// and leave it to be rendered by whatever processes the output. But some | ||
// Markdown renderers, including GitHub's, don't process Markdown if it's within | ||
// an HTML tag. So in some places (like descriptions of the types themselves) we | ||
// just output the raw description. In other places, like table cells, we need | ||
// to output pre-rendered Markdown, otherwise GitHub won't interpret it. | ||
marked.setOptions({ gfm: true }) | ||
function markdown (markup) { | ||
let output = marked(markup || '') | ||
// Join lines, unless the next line starts with a tag. | ||
.replace(/\n(?!<)/g, ' ') | ||
// Wrap after 80 characters. | ||
.replace(/([^\n]{80,}?) /g, '$1\n') | ||
.trim() | ||
// If there's only one paragraph, unwrap it. | ||
if (output.lastIndexOf('<p>') === 0 && output.endsWith('</p>')) { | ||
output = output.slice(3, -4) | ||
} | ||
return output | ||
} | ||
function sortBy (arr, property) { | ||
@@ -43,3 +20,3 @@ arr.sort((a, b) => { | ||
} | ||
return `[${type.name}](#${type.name.toLowerCase()})` | ||
return `<a href="#${type.name.toLowerCase()}">${type.name}</a>` | ||
} | ||
@@ -58,37 +35,52 @@ | ||
} | ||
printer('<table><thead>') | ||
printer(' <tr>') | ||
printer(' <th align="left">Field</th>') | ||
printer(' <th align="right">Argument</th>') | ||
printer(' <th align="left">Type</th>') | ||
printer(' <th align="left">Description</th>') | ||
printer(' </tr>') | ||
printer('</thead><tbody>') | ||
printer('<table>') | ||
printer('<thead>') | ||
printer('<tr>') | ||
printer('<th align="left">Field</th>') | ||
printer('<th align="right">Argument</th>') | ||
printer('<th align="left">Type</th>') | ||
printer('<th align="left">Description</th>') | ||
printer('</tr>') | ||
printer('</thead>') | ||
printer('<tbody>') | ||
type.fields.forEach(field => { | ||
printer(' <tr>') | ||
printer(` <td colspan="2" valign="top"><strong>${field.name}</strong>${field.isDeprecated ? ' ⚠️' : ''}</td>`) | ||
printer(` <td valign="top">${markdown(renderType(field.type))}</td>`) | ||
printer(' <td>') | ||
if (field.description) { | ||
// If we were to print an empty, indented line here, the Markdown renderer | ||
// would think the </td> is a code block. | ||
printer(`${markdown(field.description)}`) | ||
printer('<tr>') | ||
printer(`<td colspan="2" valign="top"><strong>${field.name}</strong>${field.isDeprecated ? ' ⚠️' : ''}</td>`) | ||
printer(`<td valign="top">${renderType(field.type)}</td>`) | ||
if (field.description || field.isDeprecated) { | ||
printer('<td>') | ||
if (field.description) { | ||
printer(`\n${field.description}\n`) | ||
} | ||
if (field.isDeprecated) { | ||
printer('<p>⚠️ <strong>DEPRECATED</strong></p>') | ||
if (field.deprecationReason) { | ||
printer('<blockquote>') | ||
printer(`\n${field.deprecationReason}\n`) | ||
printer('</blockquote>') | ||
} | ||
} | ||
printer('</td>') | ||
} else { | ||
printer('<td></td>') | ||
} | ||
if (field.isDeprecated) { | ||
printer(' <br/><br/><p>⚠️ <strong>DEPRECATED</strong></p>') | ||
printer(` <blockquote>${markdown(field.deprecationReason)}</blockquote>`) | ||
} | ||
printer(' </td>') | ||
printer(' </tr>') | ||
printer('</tr>') | ||
if (field.args.length) { | ||
field.args.forEach((arg, i) => { | ||
printer(' <tr>') | ||
printer(` <td colspan="2" align="right" valign="top">${arg.name}</td>`) | ||
printer(` <td valign="top">${markdown(renderType(arg.type))}</td>`) | ||
printer(` <td>${markdown(arg.description)}</td>`) | ||
printer(' </tr>') | ||
printer('<tr>') | ||
printer(`<td colspan="2" align="right" valign="top">${arg.name}</td>`) | ||
printer(`<td valign="top">${renderType(arg.type)}</td>`) | ||
if (arg.description) { | ||
printer('<td>') | ||
printer(`\n${arg.description}\n`) | ||
printer('</td>') | ||
} else { | ||
printer(`<td></td>`) | ||
} | ||
printer('</tr>') | ||
}) | ||
} | ||
}) | ||
printer('</tbody></table>') | ||
printer('</tbody>') | ||
printer('</table>') | ||
} | ||
@@ -159,23 +151,32 @@ | ||
} | ||
printer('<table><thead>') | ||
printer(' <th align="left">Value</th>') | ||
printer(' <th align="left">Description</th>') | ||
printer('</thead><tbody>') | ||
printer('<table>') | ||
printer('<thead>') | ||
printer('<th align="left">Value</th>') | ||
printer('<th align="left">Description</th>') | ||
printer('</thead>') | ||
printer('<tbody>') | ||
type.enumValues.forEach(value => { | ||
printer(' <tr>') | ||
printer(` <td valign="top"><strong>${value.name}</strong>${value.isDeprecated ? ' ⚠️' : ''}</td>`) | ||
printer(' <td>') | ||
if (value.description) { | ||
// If we were to print an empty, indented line here, the Markdown renderer | ||
// would think the </td> is a code block. | ||
printer(`${markdown(value.description)}`) | ||
printer('<tr>') | ||
printer(`<td valign="top"><strong>${value.name}</strong>${value.isDeprecated ? ' ⚠️' : ''}</td>`) | ||
if (value.description || value.isDeprecated) { | ||
printer('<td>') | ||
if (value.description) { | ||
printer(`\n${value.description}\n`) | ||
} | ||
if (value.isDeprecated) { | ||
printer('<p>⚠️ <strong>DEPRECATED</strong></p>') | ||
if (value.deprecationReason) { | ||
printer('<blockquote>') | ||
printer(`\n${value.deprecationReason}\n`) | ||
printer('</blockquote>') | ||
} | ||
} | ||
printer('</td>') | ||
} else { | ||
printer('<td></td>') | ||
} | ||
if (value.isDeprecated) { | ||
printer(' <br/><br/><p>⚠️ <strong>DEPRECATED</strong></p>') | ||
printer(` <blockquote>${markdown(value.deprecationReason)}</blockquote>`) | ||
} | ||
printer(' </td>') | ||
printer(' </tr>') | ||
printer('</tr>') | ||
}) | ||
printer('</tbody></table>') | ||
printer('</tbody>') | ||
printer('</table>') | ||
}) | ||
@@ -182,0 +183,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
314
54159
75
- Removedmarked@^0.3.6
- Removedmarked@0.3.19(transitive)