add ->docs_render() method on Pictures `(instead of {pic;...})` and Documents (instead of `[foo] (http;\....)`)
This commit is contained in:
Родитель
24867f49e5
Коммит
f017cbb714
40
ast/ast.ts
40
ast/ast.ts
|
@ -277,6 +277,8 @@ module TDev.AST {
|
|||
if (n.tokens[i].matches(d)) return true;
|
||||
return false
|
||||
}
|
||||
|
||||
public docText():string { return null }
|
||||
}
|
||||
|
||||
export class Comment
|
||||
|
@ -295,6 +297,7 @@ module TDev.AST {
|
|||
tw.comment(this.text);
|
||||
}
|
||||
public forSearch() { return this.text.toLowerCase(); }
|
||||
public docText() { return this.text }
|
||||
}
|
||||
|
||||
export class FieldComment
|
||||
|
@ -889,6 +892,30 @@ module TDev.AST {
|
|||
}
|
||||
|
||||
public forSearch() { return (this.isVarDef() ? "var " : "") + this.expr.forSearch(); }
|
||||
|
||||
public docText():string
|
||||
{
|
||||
var prop = this.expr.parsed ? this.expr.parsed.getCalledProperty() : null
|
||||
if (!prop || prop.getName() != "docs render") return null
|
||||
var c = <Call>this.expr.parsed
|
||||
var arg0 = <GlobalDef>c.args[0].getCalledProperty()
|
||||
if (arg0 instanceof GlobalDef) {
|
||||
var url = arg0.url
|
||||
}
|
||||
if (!url) return null
|
||||
if (arg0.getKind() == api.core.Picture) {
|
||||
var h = c.args[1].getNumberLiteral() || 12
|
||||
var cap = c.args[2].getStringLiteral() || ""
|
||||
return "{pic:" + arg0.getName() + ":" + h + "x" + h + (cap ? ":" + cap : "") + "}"
|
||||
}
|
||||
|
||||
if (arg0.getKind().getName() == "Document") {
|
||||
var cap = c.args[1].getStringLiteral() || arg0.getName()
|
||||
return "[" + cap + "] (" + url + ")"
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export class InlineActionBase
|
||||
|
@ -1665,10 +1692,9 @@ module TDev.AST {
|
|||
|
||||
if (this.body)
|
||||
for (var i = 0; i < this.body.stmts.length; ++i) {
|
||||
var s = this.body.stmts[i]
|
||||
if (s instanceof Comment) {
|
||||
var t = (<Comment>s).text
|
||||
if (/{action:ignoreReturn}/i.test(t)) {
|
||||
var s = this.body.stmts[i].docText()
|
||||
if (s != null) {
|
||||
if (/{action:ignoreReturn}/i.test(s)) {
|
||||
flags |= PropertyFlags.IgnoreReturnValue
|
||||
}
|
||||
} else {
|
||||
|
@ -3062,6 +3088,12 @@ module TDev.AST {
|
|||
return this.getLiteral()
|
||||
return null
|
||||
}
|
||||
public getNumberLiteral():number
|
||||
{
|
||||
if (typeof this.getLiteral() == "number")
|
||||
return this.getLiteral()
|
||||
return null
|
||||
}
|
||||
public getThing():Decl { return null; }
|
||||
public getLocalDef():LocalDef {
|
||||
var r = this.getThing()
|
||||
|
|
|
@ -1056,10 +1056,10 @@ module TDev.AST
|
|||
if (this.options.usedProperties.hasOwnProperty("appconsumerenderedcomments")) {
|
||||
var par = (<CodeBlock>c.parent).stmts
|
||||
var idx = par.indexOf(c)
|
||||
if (par[idx - 1] instanceof Comment)
|
||||
if (par[idx - 1] && par[idx - 1].docText() != null)
|
||||
return []; // not first
|
||||
var end = idx
|
||||
while (par[end] instanceof Comment)
|
||||
while (par[end] && par[end].docText() != null)
|
||||
end++
|
||||
var d = Step.renderDocs(par.slice(idx, end))
|
||||
return [new JsExprStmt(JsCall.direct("s.rt.saveComment", [new JsLiteral(this.stringLiteral(d))]))]
|
||||
|
|
36
ast/help.ts
36
ast/help.ts
|
@ -697,8 +697,8 @@ module TDev {
|
|||
if (m) {
|
||||
var url = m[2];
|
||||
var artId = m[3];
|
||||
var width = parseFloat(m[4] || "12");
|
||||
var height = parseFloat(m[5] || "12");
|
||||
var width = parseFloat(m[5] || "12");
|
||||
var height = parseFloat(m[6] || "12");
|
||||
if (width > 30) {
|
||||
height = 30 / width * height;
|
||||
width = 30;
|
||||
|
@ -707,7 +707,7 @@ module TDev {
|
|||
width = 20 / height * width;
|
||||
height = 20;
|
||||
}
|
||||
var caption = m[6];
|
||||
var caption = m[7];
|
||||
if (artId && !url) {
|
||||
artId = MdComments.findArtId(artId);
|
||||
url = Cloud.artUrl(artId);
|
||||
|
@ -1175,7 +1175,7 @@ module TDev {
|
|||
{
|
||||
function isEmptyComment(s:AST.Stmt)
|
||||
{
|
||||
return s instanceof AST.Comment && !(<AST.Comment>s).text;
|
||||
return s.docText() == ""
|
||||
}
|
||||
|
||||
this.init();
|
||||
|
@ -1184,40 +1184,34 @@ module TDev {
|
|||
var currBox = null;
|
||||
|
||||
for (var i = 0; i < stmts.length; ) {
|
||||
if (stmts[i] instanceof AST.Comment) {
|
||||
var cmt = <AST.Comment>stmts[i]
|
||||
} else {
|
||||
cmt = null;
|
||||
}
|
||||
var cmt = stmts[i].docText()
|
||||
|
||||
if (cmt) {
|
||||
var m = /^\s*\{hide(:[^{}]*)?\}\s*$/.exec(cmt.text);
|
||||
if (cmt != null) {
|
||||
var m = /^\s*\{hide(:[^{}]*)?\}\s*$/.exec(cmt);
|
||||
if (m) {
|
||||
if (m[1]) output += this.formatText(m[1]);
|
||||
var j = i + 1;
|
||||
while (j < stmts.length) {
|
||||
if (stmts[j] instanceof AST.Comment &&
|
||||
/^\s*\{\/hide\}\s*$/.test((<AST.Comment>stmts[j]).text)) {
|
||||
if (/^\s*\{\/hide\}\s*$/.test(stmts[j].docText())) {
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i = j;
|
||||
} else if (i == 0 && cmt.text == '{var:apihelp}') {
|
||||
} else if (i == 0 && cmt == '{var:apihelp}') {
|
||||
i++;
|
||||
} else if ((m = /^\s*(\{code}|````)\s*$/.exec(cmt.text)) != null) {
|
||||
} else if ((m = /^\s*(\{code}|````)\s*$/.exec(cmt)) != null) {
|
||||
var j = i + 1;
|
||||
var seenStmt = false;
|
||||
while (j < stmts.length) {
|
||||
if ((stmts[j] instanceof AST.Comment) &&
|
||||
/^\s*(\{\/code}|````)\s*$/.test((<AST.Comment>stmts[j]).text))
|
||||
if (/^\s*(\{\/code}|````)\s*$/.test(stmts[j].docText()))
|
||||
break;
|
||||
j++;
|
||||
}
|
||||
output += this.mkSnippet(stmts.slice(i + 1, j));
|
||||
i = j + 1;
|
||||
} else if ((m = /^\s*\{box:([^{}]*)\}\s*$/.exec(cmt.text)) != null) {
|
||||
} else if ((m = /^\s*\{box:([^{}]*)\}\s*$/.exec(cmt)) != null) {
|
||||
if (currBox) output += "</div>";
|
||||
var parts = m[1].split(':');
|
||||
var boxClass = parts[0];
|
||||
|
@ -1268,7 +1262,7 @@ module TDev {
|
|||
currBox = boxClass;
|
||||
output += Util.fmt("<div class='{0} md-box-{1}' {2}>{3}", boxCss, boxClass, boxDir, boxHd)
|
||||
i++;
|
||||
} else if (/^\s*\{\/box(:[^{}]*)?\}\s*$/.test(cmt.text)) {
|
||||
} else if (/^\s*\{\/box(:[^{}]*)?\}\s*$/.test(cmt)) {
|
||||
if (currBox) {
|
||||
output += boxFt + "</div>";
|
||||
currBox = null;
|
||||
|
@ -1277,13 +1271,13 @@ module TDev {
|
|||
}
|
||||
i++;
|
||||
} else {
|
||||
output += this.formatText(cmt.text);
|
||||
output += this.formatText(cmt);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
var j = i;
|
||||
while (j < stmts.length) {
|
||||
if (stmts[j] instanceof AST.Comment) break;
|
||||
if (stmts[j].docText() != null) break;
|
||||
j++;
|
||||
}
|
||||
output += this.mkSnippet(stmts.slice(i, j));
|
||||
|
|
|
@ -517,6 +517,14 @@ module TDev
|
|||
|
||||
public visitExprStmt(n:AST.ExprStmt)
|
||||
{
|
||||
if (!this.showDiff && this.formatComments) {
|
||||
var doc = n.docText()
|
||||
if (doc != null) {
|
||||
var inner = this.tline(Renderer.tdiv("md-comment",
|
||||
this.mdComments.formatText(doc)))
|
||||
return this.stmt(n, inner + this.possibleError(n));
|
||||
}
|
||||
}
|
||||
return this.stmt(n, this.renderExprStmt(n))
|
||||
}
|
||||
|
||||
|
|
|
@ -233,17 +233,18 @@ module TDev.AST
|
|||
var isAutoStep = ""
|
||||
s.tutorialWarning = null
|
||||
|
||||
if (s instanceof AST.Comment) {
|
||||
var c = <AST.Comment>s;
|
||||
if (/^\s*\{box:([^{}]*)\}\s*$/i.test(c.text))
|
||||
var ctext = s.docText()
|
||||
|
||||
if (ctext != null) {
|
||||
if (/^\s*\{box:([^{}]*)\}\s*$/i.test(ctext))
|
||||
boxNesting++;
|
||||
if (/^\s*\{\/box\}\s*$/i.test(c.text))
|
||||
if (/^\s*\{\/box\}\s*$/i.test(ctext))
|
||||
boxNesting--;
|
||||
|
||||
if (currStepIdx < 0 && /^\s*\{adddecl\}\s*$/i.test(c.text))
|
||||
if (currStepIdx < 0 && /^\s*\{adddecl\}\s*$/i.test(ctext))
|
||||
currStep.addDecl = []
|
||||
|
||||
var m = /^\s*\{stprecise:(.*)\}\s*$/i.exec(c.text)
|
||||
var m = /^\s*\{stprecise:(.*)\}\s*$/i.exec(ctext)
|
||||
if (m) {
|
||||
var vs = m[1]
|
||||
if (/^["']/.test(vs)) {
|
||||
|
@ -253,16 +254,16 @@ module TDev.AST
|
|||
preciseStrings[vs] = true
|
||||
}
|
||||
|
||||
m = /^\s*\{stnoprofile}\s*$/i.exec(c.text)
|
||||
m = /^\s*\{stnoprofile}\s*$/i.exec(ctext)
|
||||
if (m) {
|
||||
combined._skipIntelliProfile = true;
|
||||
}
|
||||
|
||||
m = /^\s*\{stauto(:(.*))?}\s*$/i.exec(c.text)
|
||||
m = /^\s*\{stauto(:(.*))?}\s*$/i.exec(ctext)
|
||||
if (m)
|
||||
isAutoStep = m[2] || "yes"
|
||||
|
||||
m = /^\s*\{stcmd:([^:]*)(:(.*))?\}\s*$/i.exec(c.text)
|
||||
m = /^\s*\{stcmd:([^:]*)(:(.*))?\}\s*$/i.exec(ctext)
|
||||
if (m) {
|
||||
currStep.command = m[1]
|
||||
currStep.commandArg = m[3] || ""
|
||||
|
@ -282,12 +283,12 @@ module TDev.AST
|
|||
}
|
||||
}
|
||||
|
||||
m = /^\s*\{sthints:([^:]*)\}\s*$/i.exec(c.text)
|
||||
m = /^\s*\{sthints:([^:]*)\}\s*$/i.exec(ctext)
|
||||
if (m) {
|
||||
currStep.hintLevel = m[1]
|
||||
}
|
||||
|
||||
m = /^\s*\{stvalidator:([^:]*)(:(.*))?\}\s*$/i.exec(c.text)
|
||||
m = /^\s*\{stvalidator:([^:]*)(:(.*))?\}\s*$/i.exec(ctext)
|
||||
if (m) {
|
||||
currStep.validator = m[1]
|
||||
currStep.validatorArg = m[3] || ""
|
||||
|
@ -404,7 +405,7 @@ module TDev.AST
|
|||
prune(i, act.body)
|
||||
var newDocs = []
|
||||
s.docs.forEach(d => {
|
||||
if (d instanceof Comment && (<Comment>d).text == "{stcode}") {
|
||||
if (d.docText() == "{stcode}") {
|
||||
newDocs.pushRange(stepStmts)
|
||||
} else newDocs.push(d)
|
||||
})
|
||||
|
|
|
@ -16,5 +16,11 @@ module TDev.RT {
|
|||
doc._url = url;
|
||||
return Promise.as(doc);
|
||||
}
|
||||
|
||||
//? Shows a document link in the docs.
|
||||
//@ docsOnly
|
||||
public docs_render(caption:string)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1640,5 +1640,11 @@ module TDev.RT {
|
|||
var now = Time.now();
|
||||
return now.year() + "-" + now.month() + "-" + now.day() + "-" + now.hour() + "-" + now.minute() + "-" + now.second() + "-" + now.millisecond();
|
||||
}
|
||||
|
||||
//? Shows an art picture in the docs.
|
||||
//@ docsOnly
|
||||
public docs_render(height:number, caption:string)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче