Merge pull request #905 from Microsoft/langSpecStraightQuotes

Straight quotes in Language Specification
This commit is contained in:
Anders Hejlsberg 2014-10-16 14:06:05 -07:00
commit b435f149aa
6 changed files with 376 additions and 316 deletions

View File

@ -294,7 +294,7 @@ compileFile(word2mdJs,
file(specMd, [word2mdJs, specWord], function () {
jake.cpR(headerMd, specMd, {silent: true});
var specWordFullPath = path.resolve(specWord);
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd;
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
console.log(cmd);
child_process.exec(cmd, function () {
complete();

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,8 @@
var sys = (function () {
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2;
var binaryStream = new ActiveXObject("ADODB.Stream");
binaryStream.Type = 1;
var args = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
@ -6,7 +10,24 @@ var sys = (function () {
return {
args: args,
createObject: function (typeName) { return new ActiveXObject(typeName); },
write: function (s) { return WScript.StdOut.Write(s); }
write: function (s) {
WScript.StdOut.Write(s);
},
writeFile: function (fileName, data) {
fileStream.Open();
binaryStream.Open();
try {
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
fileStream.Position = 3;
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2);
}
finally {
binaryStream.Close();
fileStream.Close();
}
}
};
})();
function convertDocumentToMarkdown(doc) {
@ -149,6 +170,10 @@ function convertDocumentToMarkdown(doc) {
lastInTable = inTable;
}
function writeDocument() {
var title = doc.builtInDocumentProperties.item(1) + "";
if (title.length) {
write("# " + title + "\n\n");
}
for (var p = doc.paragraphs.first; p; p = p.next()) {
writeParagraph(p);
}
@ -168,16 +193,19 @@ function convertDocumentToMarkdown(doc) {
findReplace("^19 REF", {}, "[^&](#^&)", {});
doc.fields.toggleShowCodes();
writeDocument();
result = result.replace(/\x85/g, "\u2026");
result = result.replace(/\x96/g, "\u2013");
result = result.replace(/\x97/g, "\u2014");
return result;
}
function main(args) {
if (args.length !== 1) {
sys.write("Syntax: word2md <filename>\n");
if (args.length !== 2) {
sys.write("Syntax: word2md <inputfile> <outputfile>\n");
return;
}
var app = sys.createObject("Word.Application");
var doc = app.documents.open(args[0]);
sys.write(convertDocumentToMarkdown(doc));
sys.writeFile(args[1], convertDocumentToMarkdown(doc));
doc.close(false);
app.quit();
}

View File

@ -103,6 +103,7 @@ module Word {
export interface Document {
fields: Fields;
paragraphs: Paragraphs;
builtInDocumentProperties: Collection<any>;
close(saveChanges: boolean): void;
range(): Range;
}
@ -118,6 +119,10 @@ module Word {
}
var sys = (function () {
var fileStream = new ActiveXObject("ADODB.Stream");
fileStream.Type = 2 /*text*/;
var binaryStream = new ActiveXObject("ADODB.Stream");
binaryStream.Type = 1 /*binary*/;
var args: string[] = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
args[i] = WScript.Arguments.Item(i);
@ -125,7 +130,26 @@ var sys = (function () {
return {
args: args,
createObject: (typeName: string) => new ActiveXObject(typeName),
write: (s: string) => WScript.StdOut.Write(s)
write(s: string): void {
WScript.StdOut.Write(s);
},
writeFile: (fileName: string, data: string): void => {
fileStream.Open();
binaryStream.Open();
try {
// Write characters in UTF-8 encoding
fileStream.Charset = "utf-8";
fileStream.WriteText(data);
// We don't want the BOM, skip it by setting the starting location to 3 (size of BOM).
fileStream.Position = 3;
fileStream.CopyTo(binaryStream);
binaryStream.SaveToFile(fileName, 2 /*overwrite*/);
}
finally {
binaryStream.Close();
fileStream.Close();
}
}
};
})();
@ -298,6 +322,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
}
function writeDocument() {
var title = doc.builtInDocumentProperties.item(1) + "";
if (title.length) {
write("# " + title + "\n\n");
}
for (var p = doc.paragraphs.first; p; p = p.next()) {
writeParagraph(p);
}
@ -321,17 +349,21 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
writeDocument();
result = result.replace(/\x85/g, "\u2026");
result = result.replace(/\x96/g, "\u2013");
result = result.replace(/\x97/g, "\u2014");
return result;
}
function main(args: string[]) {
if (args.length !== 1) {
sys.write("Syntax: word2md <filename>\n");
if (args.length !== 2) {
sys.write("Syntax: word2md <inputfile> <outputfile>\n");
return;
}
var app: Word.Application = sys.createObject("Word.Application");
var doc = app.documents.open(args[0]);
sys.write(convertDocumentToMarkdown(doc));
sys.writeFile(args[1], convertDocumentToMarkdown(doc));
doc.close(false);
app.quit();
}