Skip to content

Commit

Permalink
feat: preserve spaces in code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelFroeschen authored and Gerrit0 committed Feb 20, 2021
1 parent 441fea2 commit c8de53a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/lib/converter/factories/comment.ts
Expand Up @@ -258,6 +258,7 @@ export function parseComment(
let inFencedCode = false;
function readLine(line: string) {
line = line.replace(/^\s*\*? ?/, "");
const rawLine = line;
line = line.replace(/\s*$/, "");

if (CODE_FENCE.test(line)) {
Expand All @@ -271,7 +272,12 @@ export function parseComment(
return readTagLine(line, tag);
}
}
readBareLine(line);
if (inFencedCode) {
// This will not include code blocks declared with four spaces
readBareLine(rawLine);
} else {
readBareLine(line);
}
}

text = text.replace(/^\s*\/\*+/, "");
Expand Down
13 changes: 13 additions & 0 deletions src/test/converter/comment/comment4.ts
@@ -0,0 +1,13 @@
/**
* This is a comment containing a multiline code block
* ```ts
* export function multiply(a: number, b: number) {
* return a * b;
* }
* ```
* @module
*/

export function multiply(a: number, b: number) {
return a * b;
}
68 changes: 67 additions & 1 deletion src/test/converter/comment/specs.json
Expand Up @@ -380,6 +380,71 @@
]
}
]
},
{
"id": 42,
"name": "comment4",
"kind": 1,
"kindString": "Module",
"flags": {},
"comment": {
"shortText": "This is a comment containing a multiline code block\n```ts\nexport function multiply(a: number, b: number) {\n return a * b;\n}\n```"
},
"children": [
{
"id": 43,
"name": "multiply",
"kind": 64,
"kindString": "Function",
"flags": {},
"signatures": [
{
"id": 44,
"name": "multiply",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 45,
"name": "a",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
},
{
"id": 46,
"name": "b",
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"type": {
"type": "intrinsic",
"name": "number"
}
}
],
"type": {
"type": "intrinsic",
"name": "number"
}
}
]
}
],
"groups": [
{
"title": "Functions",
"kind": 64,
"children": [
43
]
}
]
}
],
"groups": [
Expand All @@ -389,7 +454,8 @@
"children": [
1,
32,
37
37,
42
]
}
]
Expand Down

0 comments on commit c8de53a

Please sign in to comment.