Skip to content

Commit 94e91e5

Browse files
committed
Use hidden text in Word document for markdown image links
1 parent 549fbf5 commit 94e91e5

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

Diff for: doc/TypeScript Language Specification.docx

-228 Bytes
Binary file not shown.

Diff for: doc/spec.md

+4-4
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-
   ![](images/image1.png)
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-
   ![](images/image2.png)
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-
   ![](images/image3.png)
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-
   ![](images/image4.png)
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

Diff for: scripts/word2md.js

+14-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/word2md.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ module Word {
6767
export interface Tables extends Collection<Table> {
6868
}
6969

70-
export interface InlineShape {
71-
}
72-
73-
export interface InlineShapes extends Collection<InlineShape> {
74-
}
75-
7670
export interface Range {
7771
find: Find;
7872
listFormat: ListFormat;
7973
tables: Tables;
80-
inlineShapes: InlineShapes;
8174
text: string;
75+
textRetrievalMode: {
76+
includeHiddenText: boolean;
77+
}
8278
words: Ranges;
8379
}
8480

@@ -266,22 +262,26 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
266262

267263
function writeParagraph(p: Word.Paragraph) {
268264

269-
var text = p.range.text;
265+
var range = p.range;
266+
var text = range.text;
270267
var style = p.style.nameLocal;
271-
var inTable = p.range.tables.count > 0;
272-
var containsImage = p.range.inlineShapes.count > 0;
268+
var inTable = range.tables.count > 0;
273269
var level = 1;
274270
var sectionBreak = text.indexOf("\x0C") >= 0;
275271

276272
text = trimEndFormattingMarks(text);
273+
if (text === "/") {
274+
range.textRetrievalMode.includeHiddenText = true;
275+
var fullText = range.text;
276+
range.textRetrievalMode.includeHiddenText = false;
277+
if (text !== fullText) {
278+
text = "&emsp;&emsp;" + fullText.substr(1);
279+
}
280+
}
281+
277282
if (inTable) {
278283
style = "Table";
279284
}
280-
else if (containsImage) {
281-
imageCount++;
282-
write("&emsp;&emsp;&emsp;![](images/image" + imageCount + ".png)\n\n");
283-
text = "";
284-
}
285285
else if (style.match(/\s\d$/)) {
286286
level = +style.substr(style.length - 1);
287287
style = style.substr(0, style.length - 2);
@@ -294,7 +294,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
294294

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

@@ -305,7 +305,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
305305
break;
306306

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

311311
case "Grammar":
@@ -324,7 +324,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
324324

325325
case "Table":
326326
if (!lastInTable) {
327-
tableColumnCount = p.range.tables.item(1).columns.count + 1;
327+
tableColumnCount = range.tables.item(1).columns.count + 1;
328328
tableCellIndex = 0;
329329
}
330330
if (tableCellIndex < tableColumnCount) {

0 commit comments

Comments
 (0)