Skip to content

Images in Language Specification #6144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified doc/TypeScript Language Specification.docx
Binary file not shown.
Binary file added doc/images/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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'.

Expand All @@ -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.

Expand Down
235 changes: 0 additions & 235 deletions scripts/word2md.js

This file was deleted.

27 changes: 22 additions & 5 deletions scripts/word2md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ module Word {
listFormat: ListFormat;
tables: Tables;
text: string;
textRetrievalMode: {
includeHiddenText: boolean;
}
words: Ranges;
}

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

function writeParagraph(p: Word.Paragraph) {

var text = p.range.text;
var range = p.range;
var text = range.text;
var style = p.style.nameLocal;
var inTable = p.range.tables.count > 0;
var inTable = range.tables.count > 0;
var level = 1;
var sectionBreak = text.indexOf("\x0C") >= 0;

text = trimEndFormattingMarks(text);
if (text === "/") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly does this mean? Can you leave a comment with the explanation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will add a comment. An inline image shows up in the text just as a "/". When I see a paragraph consisting of nothing but "/", I check to see if the paragraph contains hidden text and if so I emit that instead. The hidden text is assumed to contain an appropriate markdown image link. I could look at automatically extracting the images, but I'm not sure how much time I want to sink into further exploring the Word object model.

// An inline image shows up in the text as a "/". When we see a paragraph
// consisting of nothing but "/", we check to see if the paragraph contains
// hidden text and, if so, emit that instead. The hidden text is assumed to
// contain an appropriate markdown image link.
range.textRetrievalMode.includeHiddenText = true;
var fullText = range.text;
range.textRetrievalMode.includeHiddenText = false;
if (text !== fullText) {
text = "  " + fullText.substr(1);
}
}

if (inTable) {
style = "Table";
}
Expand All @@ -280,7 +297,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {

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

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

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

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

case "Table":
if (!lastInTable) {
tableColumnCount = p.range.tables.item(1).columns.count + 1;
tableColumnCount = range.tables.item(1).columns.count + 1;
tableCellIndex = 0;
}
if (tableCellIndex < tableColumnCount) {
Expand Down