Skip to content

Commit deedaf9

Browse files
committed
Add jake task for generating Markdown language spec
1 parent 72ac68c commit deedaf9

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

Jakefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
var fs = require("fs");
44
var path = require("path");
5+
var child_process = require("child_process");
56

67
// Variables
78
var compilerDirectory = "src/compiler/";
89
var servicesDirectory = "src/services/";
910
var harnessDirectory = "src/harness/";
1011
var libraryDirectory = "src/lib/";
1112
var scriptsDirectory = "scripts/";
13+
var docDirectory = "doc/";
1214

1315
var builtDirectory = "built/";
1416
var builtLocalDirectory = "built/local/";
@@ -260,6 +262,38 @@ task("clean", function() {
260262
jake.rmRf(builtDirectory);
261263
});
262264

265+
// Generate Markdown spec
266+
var word2mdJs = path.join(scriptsDirectory, "word2md.js");
267+
var word2mdTs = path.join(scriptsDirectory, "word2md.ts");
268+
var specWord = path.join(docDirectory, "TypeScript Language Specification.docx");
269+
var specMd = path.join(docDirectory, "spec.md");
270+
var headerMd = path.join(docDirectory, "header.md");
271+
272+
file(word2mdTs);
273+
274+
// word2md script
275+
compileFile(word2mdJs,
276+
[word2mdTs],
277+
[word2mdTs],
278+
[],
279+
false);
280+
281+
// The generated spec.md; built for the 'generate-spec' task
282+
file(specMd, [word2mdJs, specWord], function () {
283+
jake.cpR(headerMd, specMd, {silent: true});
284+
var specWordFullPath = path.resolve(specWord);
285+
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd;
286+
console.log(cmd);
287+
child_process.exec(cmd, function () {
288+
complete();
289+
});
290+
}, {async: true})
291+
292+
293+
desc("Generates a Markdown version of the Language Specification");
294+
task("generate-spec", [specMd])
295+
296+
263297
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
264298
desc("Makes a new LKG out of the built js files");
265299
task("LKG", libraryTargets, function() {
-6.01 KB
Binary file not shown.

doc/spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ Object type literals are the primary form of type literals and are described in
13541354

13551355
As the table above illustrates, an array type literal is shorthand for a reference to the generic interface type ‘Array’ in the global module, a function type literal is shorthand for an object type containing a single call signature, and a constructor type literal is shorthand for an object type containing a single construct signature. Note that function and constructor types with multiple call or construct signatures cannot be written as function or constructor type literals but must instead be written as object type literals.
13561356

1357-
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an A*rrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type
1357+
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the ‘Array<T>’ notation. For example, the type
13581358

13591359
```TypeScript
13601360
() => string[]

scripts/word2md.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
// word2md - Word to Markdown conversion tool
2-
//
3-
// word2md converts a Microsoft Word document to Markdown formatted text. The tool uses the
4-
// Word Automation APIs to start an instance of Word and access the contents of the document
5-
// being converted. The tool must be run using the cscript.exe script host and requires Word
6-
// to be installed on the target machine. The name of the document to convert must be specified
7-
// as a command line argument and the resulting Markdown is written to standard output. The
8-
// tool recognizes the specific Word styles used in the TypeScript Language Specification.
91
var sys = (function () {
102
var args = [];
113
for (var i = 0; i < WScript.Arguments.length; i++) {
@@ -163,9 +155,9 @@ function convertDocumentToMarkdown(doc) {
163155
writeBlockEnd();
164156
}
165157
findReplace("", { font: { subscript: true } }, "<sub>^&</sub>", { font: { subscript: false } });
166-
findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 /* default font */ });
167-
findReplace("", { style: "Production" }, "*^&*", { style: -66 /* default font */ });
168-
findReplace("", { style: "Terminal" }, "`^&`", { style: -66 /* default font */ });
158+
findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 });
159+
findReplace("", { style: "Production" }, "*^&*", { style: -66 });
160+
findReplace("", { style: "Terminal" }, "`^&`", { style: -66 });
169161
findReplace("", { font: { bold: true, italic: true } }, "***^&***", { font: { bold: false, italic: false } });
170162
findReplace("", { font: { italic: true } }, "*^&*", { font: { italic: false } });
171163
doc.fields.toggleShowCodes();

scripts/word2md.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module Word {
9797
}
9898

9999
export interface Fields extends Collection<Field> {
100-
toggleShowCodes();
100+
toggleShowCodes(): void;
101101
}
102102

103103
export interface Document {
@@ -138,7 +138,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
138138
var tableCellIndex: number;
139139
var columnAlignment: number[] = [];
140140

141-
function setProperties(target: {}, properties: {}) {
141+
function setProperties(target: any, properties: any) {
142142
for (var name in properties) {
143143
if (properties.hasOwnProperty(name)) {
144144
var value = properties[name];

0 commit comments

Comments
 (0)