[ADF-2456] Fixed property table formatting (#3051)

This commit is contained in:
Andy Stark
2018-03-08 19:41:38 +00:00
committed by Eugenio Romano
parent 8a70e026cd
commit 606009cac2
5 changed files with 38 additions and 21 deletions

View File

@@ -51,7 +51,7 @@ function updatePhase(srcFolder, destFolder, filenames, aggData) {
var pathname = path.resolve(srcFolder, filenames[i]);
var src = fs.readFileSync(pathname);
var tree = remark().parse(src)
var tree = remark().use(frontMatter, ["yaml"]).parse(src)
var modified = false;
@@ -60,7 +60,7 @@ function updatePhase(srcFolder, destFolder, filenames, aggData) {
});
if (modified)
fs.writeFileSync(path.resolve(destFolder, filenames[i]), remark().data("settings", {paddedTable: false}).stringify(tree));
fs.writeFileSync(path.resolve(destFolder, filenames[i]), remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false}).stringify(tree));
//console.log(JSON.stringify(tree));
}
}

View File

@@ -6,6 +6,8 @@ var heading = require("mdast-util-heading-range");
var remark = require("remark");
var unist = require("../unistHelpers");
var typescript_1 = require("typescript");
// Max number of characters in the text for the default value column.
var maxDefaultTextLength = 20;
function initPhase(aggData) {
}
exports.initPhase = initPhase;
@@ -284,15 +286,20 @@ function buildPropsTable(props, includeInitializer) {
for (var i = 0; i < props.length; i++) {
var pName = props[i].name;
var pType = props[i].type;
var pDefault = props[i].initializer || "";
var pDesc = props[i].docText || "";
if (pDesc) {
pDesc = pDesc.replace(/[\n\r]+/, " ");
}
var descCellContent = remark().parse(pDesc).children;
var pDefault = props[i].initializer || "";
var defaultCellContent;
if (pDefault) {
defaultCellContent = unist.makeInlineCode(pDefault);
if (pDefault.length > maxDefaultTextLength) {
defaultCellContent = unist.makeText("See description");
console.log("Warning: property \"" + pName + "\" default value substituted (> " + maxDefaultTextLength + " chars)");
}
else
defaultCellContent = unist.makeInlineCode(pDefault);
}
else {
defaultCellContent = unist.makeText("");

View File

@@ -1,7 +1,6 @@
import * as ts from "typescript";
import * as fs from "fs";
import * as path from "path";
import * as program from "commander";
import * as heading from "mdast-util-heading-range";
import * as remark from "remark";
@@ -9,6 +8,10 @@ import * as remark from "remark";
import * as unist from "../unistHelpers";
import { JsxEmit, isClassDeclaration, PropertyDeclaration } from "typescript";
// Max number of characters in the text for the default value column.
const maxDefaultTextLength = 20;
export function initPhase(aggData) {
}
@@ -397,7 +400,6 @@ function buildPropsTable(props: PropData[], includeInitializer: boolean = true)
for (var i = 0; i < props.length; i++) {
var pName = props[i].name;
var pType = props[i].type;
var pDefault = props[i].initializer || "";
var pDesc = props[i].docText || "";
if (pDesc) {
@@ -406,10 +408,16 @@ function buildPropsTable(props: PropData[], includeInitializer: boolean = true)
var descCellContent = remark().parse(pDesc).children;
var pDefault = props[i].initializer || "";
var defaultCellContent;
if (pDefault) {
defaultCellContent = unist.makeInlineCode(pDefault);
if (pDefault.length > maxDefaultTextLength) {
defaultCellContent = unist.makeText("See description");
console.log(`Warning: property "${pName}" default value substituted (> ${maxDefaultTextLength} chars)`);
} else
defaultCellContent = unist.makeInlineCode(pDefault);
} else {
defaultCellContent = unist.makeText("");
}