Skip to content

Commit d35e4ed

Browse files
committed
feat(markdown): highlight keyword usage for documentation
see #100
1 parent c6fbe81 commit d35e4ed

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lib/formatInfo.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const parse = require('remark-parse');
1717
const stringify = require('mdast-util-to-string');
1818
const { formatname } = require('./formatname');
1919
const s = require('./symbols');
20+
const { keyword } = require('./keywords');
2021

2122

2223
function isabstract(schema) {
@@ -25,14 +26,14 @@ function isabstract(schema) {
2526
}
2627

2728
function isextensible(schema) {
28-
return schema.definitions !== undefined || schema['meta:extensible'] === true;
29+
return schema.definitions !== undefined || schema[keyword`meta:extensible`] === true;
2930
}
3031

3132
function isidentifiable(schema) {
3233
if (!schema.properties) {
3334
return 'undefined';
3435
}
35-
if (schema.properties['@id'] && schema.properties['@id'].type === 'string' && schema.properties['@id'].format === 'uri') {
36+
if (schema.properties[keyword`@id`] && schema.properties[keyword`@id`].type === 'string' && schema.properties[keyword`@id`].format === 'uri') {
3637
return 'true';
3738
} else {
3839
return 'false';
@@ -128,7 +129,7 @@ function formatmeta(schema) {
128129
type: gettype(schema),
129130
abstract: isabstract(schema),
130131
extensible: isextensible(schema),
131-
status: schema['meta:status'] || undefined,
132+
status: schema[keyword`meta:status`] || undefined,
132133
identifiable: isidentifiable(schema),
133134
custom: iscustom(schema),
134135
additional: schema.additionalProperties !== false,

lib/markdownBuilder.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const i18n = require('es2015-i18n-tag').default;
2020
const ghslugger = require('github-slugger');
2121
const s = require('./symbols');
2222
const { gentitle } = require('./formattingTools');
23+
const { keyword } = require('./keywords');
2324

2425
function build({ header, links = {}, includeproperties = [] } = {}) {
2526
const formats = {
@@ -253,7 +254,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
253254

254255
function nullable(property) {
255256
const types = Array.isArray(property.type) ? property.type : [property.type];
256-
const nulltypes = flist(filter(types, mytype => mytype === 'null'));
257+
const nulltypes = flist(filter(types, mytype => mytype === keyword`null`));
257258
if (size(nulltypes)) {
258259
return text(i18n`can be null`);
259260
}
@@ -299,16 +300,16 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
299300
function maketypefact(definition, isarray = '') {
300301
const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type];
301302
// filter out types that are null
302-
const realtypes = alltypes.filter(mytype => mytype !== 'null');
303+
const realtypes = alltypes.filter(mytype => mytype !== keyword`null`);
303304
// can the type be `null`
304-
const isnullable = alltypes.filter(mytype => mytype === 'null').length > 0;
305+
const isnullable = alltypes.filter(mytype => mytype === keyword`null`).length > 0;
305306
// is there only a single type or can there be multiple types
306307
const singletype = realtypes.length <= 1;
307308
const [firsttype] = realtypes;
308309
// is `null` the only allowed value
309310
const nulltype = isnullable && realtypes.length === 0;
310311

311-
const array = firsttype === 'array';
312+
const array = firsttype === keyword`array`;
312313
const merged = !!(definition.allOf || definition.anyOf || definition.oneOf || definition.not);
313314

314315
if (array && definition.items) {
@@ -333,7 +334,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
333334
if (definition.title) {
334335
// if the type has a title, always create a link to the schema
335336
return [text(' ('), link(`${definition[s.slug]}.md`, '', text(definition.title)), text(')')];
336-
} else if (!singletype || firsttype === 'object' || merged) {
337+
} else if (!singletype || firsttype === keyword`object` || merged) {
337338
return [text(' ('), link(`${definition[s.slug]}.md`, '', text(i18n`Details`)), text(')')];
338339
}
339340
return [];
@@ -345,7 +346,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
345346
function makenullablefact(definition) {
346347
const alltypes = Array.isArray(definition.type) ? definition.type : [definition.type];
347348
// can the type be `null`
348-
const isnullable = alltypes.filter(mytype => mytype === 'null').length > 0;
349+
const isnullable = alltypes.filter(mytype => mytype === keyword`null`).length > 0;
349350

350351
if (isnullable) {
351352
return listItem(paragraph(text(i18n`can be null`)));
@@ -452,7 +453,7 @@ function build({ header, links = {}, includeproperties = [] } = {}) {
452453

453454
if (schema.enum) {
454455
console.log('enum!', schema[s.filename], schema[s.pointer]);
455-
const metas = schema['meta:enum'] || {};
456+
const metas = schema[keyword`meta:enum`] || {};
456457
constraints.push(paragraph([strong(text(i18n`constant`)), text(': '), text(i18n`the value of this property must be equal to one of the following values:`)]));
457458
constraints.push(table('left', [
458459
tableRow([

0 commit comments

Comments
 (0)