Skip to content

Commit 72bb1d3

Browse files
committed
Merge pull request #6144 from Microsoft/langSpecImages
Images in Language Specification
2 parents 827fec6 + e93df41 commit 72bb1d3

File tree

8 files changed

+26
-244
lines changed

8 files changed

+26
-244
lines changed
-228 Bytes
Binary file not shown.

doc/images/image1.png

11.4 KB
Loading

doc/images/image2.png

10 KB
Loading

doc/images/image3.png

5.86 KB
Loading

doc/images/image4.png

15.7 KB
Loading

doc/spec.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function f() {
262262

263263
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.
264264

265-
/
265+
  ![](images/image1.png)
266266

267267
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.
268268

@@ -410,7 +410,7 @@ This signature denotes that a function may be passed as the parameter of the '$'
410410
411411
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.
412412
413-
/
413+
  ![](images/image2.png)
414414
415415
Section [3.3](#3.3) provides additional information about object types.
416416
@@ -627,7 +627,7 @@ An important goal of TypeScript is to provide accurate and straightforward types
627627

628628
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.
629629

630-
/
630+
  ![](images/image3.png)
631631

632632
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'.
633633

@@ -638,7 +638,7 @@ span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property
638638

639639
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.
640640

641-
/
641+
  ![](images/image4.png)
642642

643643
Section [3.9.2.4](#3.9.2.4) provides details on how to use string literals in function signatures.
644644

scripts/word2md.js

Lines changed: 0 additions & 235 deletions
This file was deleted.

scripts/word2md.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ module Word {
7272
listFormat: ListFormat;
7373
tables: Tables;
7474
text: string;
75+
textRetrievalMode: {
76+
includeHiddenText: boolean;
77+
}
7578
words: Ranges;
7679
}
7780

@@ -258,13 +261,27 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
258261

259262
function writeParagraph(p: Word.Paragraph) {
260263

261-
var text = p.range.text;
264+
var range = p.range;
265+
var text = range.text;
262266
var style = p.style.nameLocal;
263-
var inTable = p.range.tables.count > 0;
267+
var inTable = range.tables.count > 0;
264268
var level = 1;
265269
var sectionBreak = text.indexOf("\x0C") >= 0;
266270

267271
text = trimEndFormattingMarks(text);
272+
if (text === "/") {
273+
// An inline image shows up in the text as a "/". When we see a paragraph
274+
// consisting of nothing but "/", we check to see if the paragraph contains
275+
// hidden text and, if so, emit that instead. The hidden text is assumed to
276+
// contain an appropriate markdown image link.
277+
range.textRetrievalMode.includeHiddenText = true;
278+
var fullText = range.text;
279+
range.textRetrievalMode.includeHiddenText = false;
280+
if (text !== fullText) {
281+
text = "  " + fullText.substr(1);
282+
}
283+
}
284+
268285
if (inTable) {
269286
style = "Table";
270287
}
@@ -280,7 +297,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
280297

281298
case "Heading":
282299
case "Appendix":
283-
var section = p.range.listFormat.listString;
300+
var section = range.listFormat.listString;
284301
write("####".substr(0, level) + ' <a name="' + section + '"/>' + section + " " + text + "\n\n");
285302
break;
286303

@@ -291,7 +308,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
291308
break;
292309

293310
case "List Paragraph":
294-
write(" ".substr(0, p.range.listFormat.listLevelNumber * 2 - 2) + "* " + text + "\n");
311+
write(" ".substr(0, range.listFormat.listLevelNumber * 2 - 2) + "* " + text + "\n");
295312
break;
296313

297314
case "Grammar":
@@ -310,7 +327,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
310327

311328
case "Table":
312329
if (!lastInTable) {
313-
tableColumnCount = p.range.tables.item(1).columns.count + 1;
330+
tableColumnCount = range.tables.item(1).columns.count + 1;
314331
tableCellIndex = 0;
315332
}
316333
if (tableCellIndex < tableColumnCount) {

0 commit comments

Comments
 (0)