[ADF-2764] Added new type linker features and applied them to core docs (#3442)

* [ADF-2764] Added basic support for composite and external types

* [ADF-2764] Added new type linker features and applied to core docs
This commit is contained in:
Andy Stark
2018-06-06 12:21:31 +01:00
committed by Eugenio Romano
parent 47d7e59df4
commit 28ba09897e
56 changed files with 388 additions and 292 deletions

View File

@@ -66,10 +66,13 @@ function updatePhase(filenames, aggData) {
showErrors(pathname, errorMessages);
}
if (modified)
if (program.json) {
console.log(JSON.stringify(tree));
}
if (modified) {
fs.writeFileSync(filenames[i], remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false, gfm: false}).stringify(tree));
//console.log(JSON.stringify(tree));
}
}
}
@@ -128,6 +131,7 @@ function getAllDocFilePaths(docFolder, files) {
program
.usage("[options] <source>")
.option("-p, --profile [profileName]", "Select named config profile", "default")
.option("-j, --json", "Output JSON data for Markdown syntax tree")
.parse(process.argv);
var sourcePath;

View File

@@ -19,7 +19,8 @@
"toc"
],
"dev": [
"versionIndex"
"tsInfo",
"typeLinker"
]
}
}

View File

@@ -12,6 +12,19 @@ var includedNodeTypes = [
];
var docFolder = path.resolve("docs");
var adfLibNames = ["core", "content-services", "insights", "process-services"];
var externalTypes = {
'Blob': 'https://developer.mozilla.org/en-US/docs/Web/API/Blob',
'EventEmitter': 'https://angular.io/api/core/EventEmitter',
'MatSnackBarRef': 'https://material.angular.io/components/snack-bar/overview',
'TemplateRef': 'https://angular.io/api/core/TemplateRef',
'Observable': 'http://reactivex.io/documentation/observable.html',
'Subject': 'http://reactivex.io/documentation/subject.html',
'AppDefinitionRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/AppDefinitionRepresentation.md',
'NodeEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md',
'RelatedContentRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/RelatedContentRepresentation.md',
'SiteEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SiteEntry.md',
'SitePaging': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md'
};
function initPhase(aggData) {
aggData.docFiles = {};
aggData.nameLookup = new SplitNameLookup();
@@ -62,10 +75,10 @@ function updatePhase(tree, pathname, aggData) {
}
}
}
else if (node.type === "paragraph") {
else if ((node.type === "paragraph")) {
node.children.forEach(function (child, index) {
if (child.type === "text") {
var newNodes = handleLinksInBodyText(aggData, child.value);
if ((child.type === "text") || (child.type === "inlineCode")) {
var newNodes = handleLinksInBodyText(aggData, child.value, child.type === 'inlineCode');
(_a = node.children).splice.apply(_a, [index, 1].concat(newNodes));
}
else {
@@ -181,7 +194,7 @@ var SplitNameLookup = /** @class */ (function () {
var WordScanner = /** @class */ (function () {
function WordScanner(text) {
this.text = text;
this.separators = " \n\r\t.;:";
this.separators = " \n\r\t.;:<>[]&|";
this.index = 0;
this.nextSeparator = 0;
this.next();
@@ -214,7 +227,8 @@ var WordScanner = /** @class */ (function () {
};
return WordScanner;
}());
function handleLinksInBodyText(aggData, text) {
function handleLinksInBodyText(aggData, text, wrapInlineCode) {
if (wrapInlineCode === void 0) { wrapInlineCode = false; }
var result = [];
var currTextStart = 0;
var matcher = new SplitNameMatcher(aggData.nameLookup.root);
@@ -237,9 +251,23 @@ function handleLinksInBodyText(aggData, text) {
}
if (link) {
var linkText = text.substring(matchStart, scanner.nextSeparator);
var linkNode = unist.makeLink(unist.makeText(linkText), link);
var linkTitle = void 0;
if (wrapInlineCode) {
linkTitle = unist.makeInlineCode(linkText);
}
else {
linkTitle = unist.makeText(linkText);
}
var linkNode = unist.makeLink(linkTitle, link);
var prevText = text.substring(currTextStart, matchStart);
result.push(unist.makeText(prevText));
if (prevText) {
if (wrapInlineCode) {
result.push(unist.makeInlineCode(prevText));
}
else {
result.push(unist.makeText(prevText));
}
}
result.push(linkNode);
currTextStart = scanner.nextSeparator;
matcher.reset();
@@ -247,12 +275,20 @@ function handleLinksInBodyText(aggData, text) {
}
var remainingText = text.substring(currTextStart, text.length);
if (remainingText) {
result.push(unist.makeText(remainingText));
if (wrapInlineCode) {
result.push(unist.makeInlineCode(remainingText));
}
else {
result.push(unist.makeText(remainingText));
}
}
return result;
}
function resolveTypeLink(aggData, text) {
var possTypeName = cleanTypeName(text);
if (possTypeName === 'constructor') {
return "";
}
var ref = aggData.projData.findReflectionByName(possTypeName);
if (ref && isLinkable(ref.kind)) {
var kebabName = ngHelpers.kebabifyClassName(possTypeName);
@@ -263,6 +299,9 @@ function resolveTypeLink(aggData, text) {
}
return url;
}
else if (externalTypes[possTypeName]) {
return externalTypes[possTypeName];
}
else {
return "";
}
@@ -279,7 +318,8 @@ function cleanTypeName(text) {
function isLinkable(kind) {
return (kind === typedoc_1.ReflectionKind.Class) ||
(kind === typedoc_1.ReflectionKind.Interface) ||
(kind === typedoc_1.ReflectionKind.Enum);
(kind === typedoc_1.ReflectionKind.Enum) ||
(kind === typedoc_1.ReflectionKind.TypeAlias);
}
function convertNodeToTypeLink(node, text, url) {
var linkDisplayText = unist.makeInlineCode(text);

View File

@@ -33,6 +33,21 @@ const docFolder = path.resolve("docs");
const adfLibNames = ["core", "content-services", "insights", "process-services"];
const externalTypes = {
'Blob': 'https://developer.mozilla.org/en-US/docs/Web/API/Blob',
'EventEmitter': 'https://angular.io/api/core/EventEmitter',
'MatSnackBarRef': 'https://material.angular.io/components/snack-bar/overview',
'TemplateRef': 'https://angular.io/api/core/TemplateRef',
'Observable': 'http://reactivex.io/documentation/observable.html',
'Subject': 'http://reactivex.io/documentation/subject.html',
'AppDefinitionRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/AppDefinitionRepresentation.md',
'NodeEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/NodeEntry.md',
'RelatedContentRepresentation': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-activiti-rest-api/docs/RelatedContentRepresentation.md',
'SiteEntry': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SiteEntry.md',
'SitePaging': 'https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md'
};
export function initPhase(aggData) {
aggData.docFiles = {};
aggData.nameLookup = new SplitNameLookup();
@@ -98,10 +113,10 @@ export function updatePhase(tree, pathname, aggData) {
convertNodeToTypeLink(node, node.children[0].value, link);
}
}
} else if (node.type === "paragraph") {
} else if ((node.type === "paragraph")) {
node.children.forEach((child, index) => {
if (child.type === "text") {
let newNodes = handleLinksInBodyText(aggData, child.value);
if ((child.type === "text") || (child.type === "inlineCode")) {
let newNodes = handleLinksInBodyText(aggData, child.value, child.type === 'inlineCode');
node.children.splice(index, 1, ...newNodes);
} else {
traverseMDTree(child);
@@ -229,7 +244,7 @@ class WordScanner {
current: string;
constructor(public text: string) {
this.separators = " \n\r\t.;:";
this.separators = " \n\r\t.;:<>[]&|";
this.index = 0;
this.nextSeparator = 0;
this.next();
@@ -269,7 +284,7 @@ class WordScanner {
}
function handleLinksInBodyText(aggData, text: string): Node[] {
function handleLinksInBodyText(aggData, text: string, wrapInlineCode: boolean = false): Node[] {
let result = [];
let currTextStart = 0;
let matcher = new SplitNameMatcher(aggData.nameLookup.root);
@@ -296,9 +311,25 @@ function handleLinksInBodyText(aggData, text: string): Node[] {
if (link) {
let linkText = text.substring(matchStart, scanner.nextSeparator);
let linkNode = unist.makeLink(unist.makeText(linkText), link);
let linkTitle;
if (wrapInlineCode) {
linkTitle = unist.makeInlineCode(linkText);
} else {
linkTitle = unist.makeText(linkText);
}
let linkNode = unist.makeLink(linkTitle, link);
let prevText = text.substring(currTextStart, matchStart);
result.push(unist.makeText(prevText));
if (prevText) {
if (wrapInlineCode) {
result.push(unist.makeInlineCode(prevText));
} else {
result.push(unist.makeText(prevText));
}
}
result.push(linkNode);
currTextStart = scanner.nextSeparator;
matcher.reset();
@@ -308,7 +339,11 @@ function handleLinksInBodyText(aggData, text: string): Node[] {
let remainingText = text.substring(currTextStart, text.length);
if (remainingText) {
result.push(unist.makeText(remainingText));
if (wrapInlineCode) {
result.push(unist.makeInlineCode(remainingText));
} else {
result.push(unist.makeText(remainingText));
}
}
return result;
@@ -317,6 +352,11 @@ function handleLinksInBodyText(aggData, text: string): Node[] {
function resolveTypeLink(aggData, text): string {
let possTypeName = cleanTypeName(text);
if (possTypeName === 'constructor') {
return "";
}
let ref: Reflection = aggData.projData.findReflectionByName(possTypeName);
if (ref && isLinkable(ref.kind)) {
@@ -329,6 +369,8 @@ function resolveTypeLink(aggData, text): string {
}
return url;
} else if (externalTypes[possTypeName]) {
return externalTypes[possTypeName];
} else {
return "";
}
@@ -349,7 +391,8 @@ function cleanTypeName(text) {
function isLinkable(kind: ReflectionKind) {
return (kind === ReflectionKind.Class) ||
(kind === ReflectionKind.Interface) ||
(kind === ReflectionKind.Enum);
(kind === ReflectionKind.Enum) ||
(kind === ReflectionKind.TypeAlias);
}
function convertNodeToTypeLink(node, text, url) {

View File

@@ -132,5 +132,9 @@ module.exports = {
isText: function (node) {
return node.type === "text";
},
isLink: function (node) {
return node.type === "inlineCode";
}
}