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
68 changes: 68 additions & 0 deletions test/doctool/test-doctool-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,74 @@ const testData = [
}
]
}
},
{
file: fixtures.path('doc_with_backticks_in_headings.md'),
json: {
type: 'module',
source: 'foo',
modules: [
{
textRaw: 'Fhqwhgads',
name: 'fhqwhgads',
properties: [
{
name: 'fullName',
textRaw: '`Fqhqwhgads.fullName`'
}
],
classMethods: [
{
name: 'again',
signatures: [
{
params: []
}
],
textRaw: 'Class Method: `Fhqwhgads.again()`',
type: 'classMethod'
}
],
classes: [
{
textRaw: 'Class: `ComeOn`',
type: 'class',
name: 'ComeOn'
}
],
ctors: [
{
name: 'Fhqwhgads',
signatures: [
{
params: []
}
],
textRaw: 'Constructor: `new Fhqwhgads()`',
type: 'ctor'
}
],
methods: [
{
textRaw: '`everybody.to(limit)`',
type: 'method',
name: 'to',
signatures: [{ params: [] }]
}
],
events: [
{
textRaw: "Event: `'FHQWHfest'`",
type: 'event',
name: 'FHQWHfest',
params: []
}
],
type: 'module',
displayName: 'Fhqwhgads'
}
]
}
}
];

Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/doc_with_backticks_in_headings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Fhqwhgads

## Class: `ComeOn`

## `everybody.to(limit)`

## Event: `'FHQWHfest'`

## Constructor: `new Fhqwhgads()`

## Class Method: `Fhqwhgads.again()`

## `Fqhqwhgads.fullName`
18 changes: 11 additions & 7 deletions tools/doc/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,15 @@ const r = String.raw;

const eventPrefix = '^Event: +';
const classPrefix = '^[Cc]lass: +';
const ctorPrefix = '^(?:[Cc]onstructor: +)?new +';
const ctorPrefix = '^(?:[Cc]onstructor: +)?`?new +';
const classMethodPrefix = '^Class Method: +';
const maybeClassPropertyPrefix = '(?:Class Property: +)?';

const maybeQuote = '[\'"]?';
const notQuotes = '[^\'"]+';

const maybeBacktick = '`?';

// To include constructs like `readable\[Symbol.asyncIterator\]()`
// or `readable.\_read(size)` (with Markdown escapes).
const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`;
Expand All @@ -458,25 +460,27 @@ const noCallOrProp = '(?![.[(])';

const maybeExtends = `(?: +extends +${maybeAncestors}${classId})?`;

/* eslint-disable max-len */
const headingExpressions = [
{ type: 'event', re: RegExp(
`${eventPrefix}${maybeQuote}(${notQuotes})${maybeQuote}$`, 'i') },
`${eventPrefix}${maybeBacktick}${maybeQuote}(${notQuotes})${maybeQuote}${maybeBacktick}$`, 'i') },

{ type: 'class', re: RegExp(
`${classPrefix}(${maybeAncestors}${classId})${maybeExtends}$`, '') },
`${classPrefix}${maybeBacktick}(${maybeAncestors}${classId})${maybeExtends}${maybeBacktick}$`, '') },

{ type: 'ctor', re: RegExp(
`${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}$`, '') },
`${ctorPrefix}(${maybeAncestors}${classId})${callWithParams}${maybeBacktick}$`, '') },

{ type: 'classMethod', re: RegExp(
`${classMethodPrefix}${maybeAncestors}(${id})${callWithParams}$`, 'i') },
`${classMethodPrefix}${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`, 'i') },

{ type: 'method', re: RegExp(
`^${maybeAncestors}(${id})${callWithParams}$`, 'i') },
`^${maybeBacktick}${maybeAncestors}(${id})${callWithParams}${maybeBacktick}$`, 'i') },

{ type: 'property', re: RegExp(
`^${maybeClassPropertyPrefix}${ancestors}(${id})${noCallOrProp}$`, 'i') },
`^${maybeClassPropertyPrefix}${maybeBacktick}${ancestors}(${id})${maybeBacktick}${noCallOrProp}$`, 'i') },
];
/* eslint-enable max-len */

function newSection(header, file) {
const text = textJoin(header.children, file);
Expand Down