Skip to content

Commit 4afad6d

Browse files
committed
Work around an issue where GitHub Pages cannot render <p></p> inside a pipes-and-dashes table (even though GHFM supports this)
1 parent 0aa04b2 commit 4afad6d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

apps/api-documenter/src/markdown/CustomMarkdownEmitter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class CustomMarkdownEmitter extends MarkdownEmitter {
4444
}
4545

4646
/** @override */
47-
protected writeNode(docNode: DocNode, context: IMarkdownEmitterContext): void {
47+
protected writeNode(docNode: DocNode, context: IMarkdownEmitterContext, docNodeSiblings: boolean): void {
4848
const writer: IndentedWriter = context.writer;
4949

5050
switch (docNode.kind) {
@@ -71,7 +71,7 @@ export class CustomMarkdownEmitter extends MarkdownEmitter {
7171

7272
writer.increaseIndent('> ');
7373

74-
this.writeNode(docNoteBox.content, context);
74+
this.writeNode(docNoteBox.content, context, false);
7575
writer.ensureNewLine();
7676

7777
writer.decreaseIndent();
@@ -105,7 +105,7 @@ export class CustomMarkdownEmitter extends MarkdownEmitter {
105105
if (docTable.header) {
106106
const cell: DocTableCell | undefined = docTable.header.cells[i];
107107
if (cell) {
108-
this.writeNode(cell.content, context);
108+
this.writeNode(cell.content, context, false);
109109
}
110110
}
111111
writer.write(' |');
@@ -123,7 +123,7 @@ export class CustomMarkdownEmitter extends MarkdownEmitter {
123123
writer.write('| ');
124124
for (const cell of row.cells) {
125125
writer.write(' ');
126-
this.writeNode(cell.content, context);
126+
this.writeNode(cell.content, context, false);
127127
writer.write(' |');
128128
}
129129
writer.writeLine();
@@ -146,7 +146,7 @@ export class CustomMarkdownEmitter extends MarkdownEmitter {
146146
break;
147147
}
148148
default:
149-
super.writeNode(docNode, context);
149+
super.writeNode(docNode, context, false);
150150
}
151151
}
152152

apps/api-documenter/src/markdown/MarkdownEmitter.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class MarkdownEmitter {
5858
options
5959
};
6060

61-
this.writeNode(docNode, context);
61+
this.writeNode(docNode, context, false);
6262

6363
writer.ensureNewLine(); // finish the last line
6464

@@ -79,7 +79,7 @@ export class MarkdownEmitter {
7979
/**
8080
* @virtual
8181
*/
82-
protected writeNode(docNode: DocNode, context: IMarkdownEmitterContext): void {
82+
protected writeNode(docNode: DocNode, context: IMarkdownEmitterContext, docNodeSiblings: boolean): void {
8383
const writer: IndentedWriter = context.writer;
8484

8585
switch (docNode.kind) {
@@ -122,9 +122,14 @@ export class MarkdownEmitter {
122122
const docParagraph: DocParagraph = docNode as DocParagraph;
123123
const trimmedParagraph: DocParagraph = DocNodeTransforms.trimSpacesInParagraph(docParagraph);
124124
if (context.insideTable) {
125-
writer.write('<p>');
126-
this.writeNodes(trimmedParagraph.nodes, context);
127-
writer.write('</p>');
125+
if (docNodeSiblings) {
126+
writer.write('<p>');
127+
this.writeNodes(trimmedParagraph.nodes, context);
128+
writer.write('</p>');
129+
} else {
130+
// Special case: If we are the only element inside this table cell, then we can omit the <p></p> container.
131+
this.writeNodes(trimmedParagraph.nodes, context);
132+
}
128133
} else {
129134
this.writeNodes(trimmedParagraph.nodes, context);
130135
writer.ensureNewLine();
@@ -237,7 +242,7 @@ export class MarkdownEmitter {
237242

238243
protected writeNodes(docNodes: ReadonlyArray<DocNode>, context: IMarkdownEmitterContext): void {
239244
for (const docNode of docNodes) {
240-
this.writeNode(docNode, context);
245+
this.writeNode(docNode, context, docNodes.length > 1);
241246
}
242247
}
243248
}

0 commit comments

Comments
 (0)