Property show images in Language Specification markdown

This commit is contained in:
Anders Hejlsberg 2015-12-17 16:43:55 -08:00
parent 55d4f0f7e4
commit 3f65a31a4f
7 changed files with 25 additions and 4 deletions

BIN
doc/images/image1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
doc/images/image2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
doc/images/image3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
doc/images/image4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -262,7 +262,7 @@ function f() {
To benefit from this inference, a programmer can use the TypeScript language service. For example, a code editor can incorporate the TypeScript language service and use the service to find the members of a string object as in the following screen shot.
/
![](images/image1.png)
In this example, the programmer benefits from type inference without providing type annotations. Some beneficial tools, however, do require the programmer to provide type annotations. In TypeScript, we can express a parameter requirement as in the following code fragment.
@ -410,7 +410,7 @@ This signature denotes that a function may be passed as the parameter of the '$'
A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot.
/
![](images/image2.png)
Section [3.3](#3.3) provides additional information about object types.
@ -627,7 +627,7 @@ An important goal of TypeScript is to provide accurate and straightforward types
JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method.
/
![](images/image3.png)
The following code fragment uses this feature. Because the 'span' variable is inferred to have the type 'HTMLSpanElement', the code can reference without static error the 'isMultiline' property of 'span'.
@ -638,7 +638,7 @@ span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property
In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property.
/
![](images/image4.png)
Section [3.9.2.4](#3.9.2.4) provides details on how to use string literals in function signatures.

View file

@ -47,6 +47,7 @@ function convertDocumentToMarkdown(doc) {
var tableColumnCount;
var tableCellIndex;
var columnAlignment = [];
var imageCount = 0;
function setProperties(target, properties) {
for (var name in properties) {
if (properties.hasOwnProperty(name)) {
@ -120,12 +121,18 @@ function convertDocumentToMarkdown(doc) {
var text = p.range.text;
var style = p.style.nameLocal;
var inTable = p.range.tables.count > 0;
var containsImage = p.range.inlineShapes.count > 0;
var level = 1;
var sectionBreak = text.indexOf("\x0C") >= 0;
text = trimEndFormattingMarks(text);
if (inTable) {
style = "Table";
}
else if (containsImage) {
imageCount++;
write("![](images/image" + imageCount + ".png)\n\n");
text = "";
}
else if (style.match(/\s\d$/)) {
level = +style.substr(style.length - 1);
style = style.substr(0, style.length - 2);

View file

@ -67,10 +67,17 @@ module Word {
export interface Tables extends Collection<Table> {
}
export interface InlineShape {
}
export interface InlineShapes extends Collection<InlineShape> {
}
export interface Range {
find: Find;
listFormat: ListFormat;
tables: Tables;
inlineShapes: InlineShapes;
text: string;
words: Ranges;
}
@ -180,6 +187,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
var tableColumnCount: number;
var tableCellIndex: number;
var columnAlignment: number[] = [];
var imageCount: number = 0;
function setProperties(target: any, properties: any) {
for (var name in properties) {
@ -261,6 +269,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
var text = p.range.text;
var style = p.style.nameLocal;
var inTable = p.range.tables.count > 0;
var containsImage = p.range.inlineShapes.count > 0;
var level = 1;
var sectionBreak = text.indexOf("\x0C") >= 0;
@ -268,6 +277,11 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
if (inTable) {
style = "Table";
}
else if (containsImage) {
imageCount++;
write("![](images/image" + imageCount + ".png)\n\n");
text = "";
}
else if (style.match(/\s\d$/)) {
level = +style.substr(style.length - 1);
style = style.substr(0, style.length - 2);