Skip to content

Commit b45d5ea

Browse files
committed
Fix multiple issues with markdown parsing
1 parent ddc64e5 commit b45d5ea

File tree

10 files changed

+181
-37
lines changed

10 files changed

+181
-37
lines changed

.config/typedoc.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"categorizeByGroup": false,
3737
"categoryOrder": ["Reflections", "Types", "Comments", "*"],
3838
"groupOrder": ["Common", "Namespaces", "*"],
39+
"hostedBaseUrl": "https://typedoc.org/example/",
3940
"navigationLinks": {
4041
"Docs": "https://typedoc.org",
4142
"Example": "https://typedoc.org/example/index.html",

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ title: Changelog
77
### Bug Fixes
88

99
- Fix restoration of groups/categories including documents, #2801.
10+
- Fixed missed relative paths within markdown link references in documents.
11+
- Improved handling of incomplete inline code blocks within markdown.
1012

1113
### Thanks!
1214

example/typedoc.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"searchGroupBoosts": {
1212
"Classes": 1.5
1313
},
14+
"hostedBaseUrl": "https://typedoc.org/example/",
1415
"navigationLinks": {
1516
"Docs": "https://typedoc.org",
1617
"API": "https://typedoc.org/api/index.html",

site/options/input.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Expects all entry points to be `.json` files generated with a previous run of Ty
9090
Options to set be set within each package when entryPointStrategy is set to
9191
packages. Unlike most options in TypeDoc, paths within this object are
9292
interpreted relative to the package directory. This option has no effect if
93-
[entryPointStrategy](#entrypointstrategy) is not set to `packages.
93+
[entryPointStrategy](#entrypointstrategy) is not set to `packages`.
9494

9595
## alwaysCreateEntryPointModule
9696

site/typedoc.config.jsonc

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"notExported": false,
4848
},
4949

50+
"hostedBaseUrl": "https://typedoc.org/",
5051
"redirects": {
52+
"guides/": "documents/Overview.html",
5153
"guides/overview/": "documents/Overview.html",
5254
"guides/installation/": "index.html",
5355
"guides/options/": "documents/Options.html",
@@ -65,7 +67,7 @@
6567
"guides/themes/": "documents/Themes.html",
6668
"guides/plugins/": "documents/Plugins.html",
6769
"guides/declaration-references/": "documents/Declaration_References.html",
68-
"guides/development": "documents/Development.html",
70+
"guides/development/": "documents/Development.html",
6971
"guides/changelog/": "documents/Changelog.html",
7072

7173
// Tags
@@ -106,7 +108,7 @@
106108
"tags/readonly/": "documents/Tags._readonly.html",
107109
"tags/remarks/": "documents/Tags._remarks.html",
108110
"tags/returns/": "documents/Tags._returns.html",
109-
"tags/satisfies/": "documents/Tags._satisfies.html",
111+
"tags/satisfies/": "documents/Tags.TypeScript_Tags.html",
110112
"tags/sealed/": "documents/Tags._sealed.html",
111113
"tags/see/": "documents/Tags._see.html",
112114
"tags/template/": "documents/Tags._template.html",

src/lib/converter/comments/blockLexer.ts

+28-10
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,31 @@ function* lexBlockComment2(
147147

148148
case "`": {
149149
// Markdown's code rules are a royal pain. This could be one of several things.
150-
// 1. Inline code: <1-n ticks><text><same number of ticks>
151-
// 2. Code block: <3 ticks><language, no ticks>\n<text>\n<3 ticks>\n
150+
// 1. Inline code: <1-n ticks><text without multiple consecutive newlines or ticks at start of line><same number of ticks>
151+
// 2. Code block: <newline><3+ ticks><language, no ticks>\n<text>\n<3 ticks>\n
152152
// 3. Unmatched tick(s), not code, but part of some text.
153153
// We don't quite handle #2 correctly yet. PR welcome!
154154
braceStartsType = false;
155155
let tickCount = 1;
156-
let lookahead = pos;
156+
157+
let lookahead = pos - 1;
158+
let atNewline = true;
159+
while (lookahead > 0 && file[lookahead] !== "\n") {
160+
if (/\S/.test(file[lookahead])) {
161+
if (!commentHasStars || file[lookahead] !== "*") {
162+
atNewline = false;
163+
break;
164+
}
165+
}
166+
--lookahead;
167+
}
168+
lookahead = pos;
157169

158170
while (lookahead + 1 < end && file[lookahead + 1] === "`") {
159171
tickCount++;
160172
lookahead++;
161173
}
174+
const isCodeBlock = atNewline && tickCount >= 3;
162175
let lookaheadStart = pos;
163176
const codeText: string[] = [];
164177

@@ -169,12 +182,17 @@ function* lexBlockComment2(
169182
codeText.push(
170183
file.substring(lookaheadStart, lookahead),
171184
);
172-
yield {
173-
kind: TokenSyntaxKind.Code,
174-
text: codeText.join(""),
175-
pos,
176-
};
177-
pos = lookahead;
185+
const codeTextStr = codeText.join("");
186+
if (isCodeBlock || !/\n\s*\n/.test(codeTextStr)) {
187+
yield {
188+
kind: TokenSyntaxKind.Code,
189+
text: codeTextStr,
190+
pos,
191+
};
192+
pos = lookahead;
193+
} else {
194+
yield makeToken(TokenSyntaxKind.Text, tickCount);
195+
}
178196
break;
179197
} else if (file[lookahead] === "`") {
180198
while (lookahead < end && file[lookahead] === "`") {
@@ -216,7 +234,7 @@ function* lexBlockComment2(
216234

217235
if (lookahead >= end && pos !== lookahead) {
218236
if (
219-
tickCount === 3 &&
237+
isCodeBlock &&
220238
file.substring(pos, end).includes("\n")
221239
) {
222240
codeText.push(file.substring(lookaheadStart, end));

src/lib/converter/comments/lineLexer.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,23 @@ function* lexLineComments2(
8787
// We don't quite handle #2 correctly yet. PR welcome!
8888
braceStartsType = false;
8989
let tickCount = 1;
90-
let lookahead = pos;
90+
91+
let lookahead = pos - 1;
92+
let atNewline = true;
93+
while (lookahead > 0 && file[lookahead] !== "\n") {
94+
if (/\S/.test(file[lookahead])) {
95+
atNewline = false;
96+
break;
97+
}
98+
--lookahead;
99+
}
100+
lookahead = pos;
91101

92102
while (lookahead + 1 < end && file[lookahead + 1] === "`") {
93103
tickCount++;
94104
lookahead++;
95105
}
106+
const isCodeBlock = atNewline && tickCount >= 3;
96107
let lookaheadStart = pos;
97108
const codeText: string[] = [];
98109

@@ -103,12 +114,17 @@ function* lexLineComments2(
103114
codeText.push(
104115
file.substring(lookaheadStart, lookahead),
105116
);
106-
yield {
107-
kind: TokenSyntaxKind.Code,
108-
text: codeText.join(""),
109-
pos,
110-
};
111-
pos = lookahead;
117+
const codeTextStr = codeText.join("");
118+
if (isCodeBlock || !/\n\s*\n/.test(codeTextStr)) {
119+
yield {
120+
kind: TokenSyntaxKind.Code,
121+
text: codeTextStr,
122+
pos,
123+
};
124+
pos = lookahead;
125+
} else {
126+
yield makeToken(TokenSyntaxKind.Text, tickCount);
127+
}
112128
break;
113129
} else if (file[lookahead] === "`") {
114130
while (lookahead < end && file[lookahead] === "`") {

src/lib/converter/comments/rawLexer.ts

+28-17
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,16 @@ function* lexCommentString2(
5353
end--;
5454
}
5555

56-
let lineStart = true;
5756
let expectingTag = false;
5857

5958
for (;;) {
6059
if (pos >= end) {
6160
return;
6261
}
6362

64-
if (lineStart) {
65-
lineStart = false;
66-
}
67-
6863
switch (file[pos]) {
6964
case "\n":
7065
yield makeToken(TokenSyntaxKind.NewLine, 1);
71-
lineStart = true;
7266
expectingTag = false;
7367
break;
7468

@@ -84,17 +78,28 @@ function* lexCommentString2(
8478

8579
case "`": {
8680
// Markdown's code rules are a royal pain. This could be one of several things.
87-
// 1. Inline code: <1-n ticks><text><same number of ticks>
88-
// 2. Code block: <3 ticks><language, no ticks>\n<text>\n<3 ticks>\n
81+
// 1. Inline code: <1-n ticks><text without multiple consecutive newlines or ticks at start of line><same number of ticks>
82+
// 2. Code block: <newline><3+ ticks><language, no ticks>\n<text>\n<3 ticks>\n
8983
// 3. Unmatched tick(s), not code, but part of some text.
9084
// We don't quite handle #2 correctly yet. PR welcome!
9185
let tickCount = 1;
92-
let lookahead = pos;
86+
87+
let lookahead = pos - 1;
88+
let atNewline = true;
89+
while (lookahead > 0 && file[lookahead] !== "\n") {
90+
if (/\S/.test(file[lookahead])) {
91+
atNewline = false;
92+
break;
93+
}
94+
--lookahead;
95+
}
96+
lookahead = pos;
9397

9498
while (lookahead + 1 < end && file[lookahead + 1] === "`") {
9599
tickCount++;
96100
lookahead++;
97101
}
102+
const isCodeBlock = atNewline && tickCount >= 3;
98103
let lookaheadStart = pos;
99104
const codeText: string[] = [];
100105

@@ -105,13 +110,19 @@ function* lexCommentString2(
105110
codeText.push(
106111
file.substring(lookaheadStart, lookahead),
107112
);
108-
yield {
109-
kind: TokenSyntaxKind.Code,
110-
text: codeText.join(""),
111-
pos,
112-
};
113-
expectingTag = false;
114-
pos = lookahead;
113+
const codeTextStr = codeText.join("");
114+
if (isCodeBlock || !/\n\s*\n/.test(codeTextStr)) {
115+
yield {
116+
kind: TokenSyntaxKind.Code,
117+
text: codeTextStr,
118+
pos,
119+
};
120+
expectingTag = false;
121+
pos = lookahead;
122+
} else {
123+
yield makeToken(TokenSyntaxKind.Text, tickCount);
124+
expectingTag = false;
125+
}
115126
break;
116127
} else if (file[lookahead] === "`") {
117128
while (lookahead < end && file[lookahead] === "`") {
@@ -136,7 +147,7 @@ function* lexCommentString2(
136147

137148
if (lookahead >= end && pos !== lookahead) {
138149
if (
139-
tickCount === 3 &&
150+
isCodeBlock &&
140151
file.substring(pos, end).includes("\n")
141152
) {
142153
codeText.push(file.substring(lookaheadStart, end));

src/lib/converter/comments/textParser.ts

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export function textContent(
139139
continue;
140140
}
141141

142+
data.atNewLine = token.text[data.pos] === "\n";
142143
++data.pos;
143144
}
144145

0 commit comments

Comments
 (0)