Skip to content

Commit

Permalink
fix: markdown image link
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Nov 5, 2021
1 parent 59dc643 commit bf2da59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/descriptionFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { format, BuiltInParserName } from "prettier";
import { DESCRIPTION, EXAMPLE, PRIVATE_REMARKS, REMARKS, TODO } from "./tags";
import { DESCRIPTION, EXAMPLE, TODO } from "./tags";
import { AllOptions } from "./types";
import { capitalizer, formatCode } from "./utils";
import fromMarkdown from "mdast-util-from-markdown";
Expand Down Expand Up @@ -73,7 +73,7 @@ function formatDescription(
});
if (options.jsdocCapitalizeDescription) text = capitalizer(text);

text = `${"!".repeat(tagStringLength)}${
text = `${tagStringLength ? `${"!".repeat(tagStringLength - 1)}?` : ""}${
text.startsWith("```") ? "\n" : ""
}${text}`;

Expand Down Expand Up @@ -150,7 +150,7 @@ function formatDescription(
return `\\\n`;
}

return (mdAst.value || "") as string;
return (mdAst.value || mdAst.title || mdAst.alt || "") as string;
}

function stringyfy(
Expand Down Expand Up @@ -268,7 +268,7 @@ function formatDescription(
)}`;
}

if (ast.type === "link") {
if (ast.type === "link" || ast.type === "image") {
return `[${stringyfy(ast, intention, mdAst)}](${ast.url})`;
}

Expand All @@ -279,7 +279,8 @@ function formatDescription(

let result = stringyfy(rootAst, beginningSpace, null);

result = result.trimStart().slice(tagStringLength);
result = result.replace(/^[\s\n]+/g, "");
result = result.replace(/^([!]+\?)/g, "");

return result;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/__snapshots__/descriptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ exports[`Markdown Table 3`] = `
"
`;
exports[`Markdown link 1`] = `
"/** @param {string} [dir] [Next.js](https://nextjs.org) project directory path. */
"
`;
exports[`Nested list 1`] = `
"/**
* 1. Foo
Expand Down
10 changes: 10 additions & 0 deletions tests/descriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,16 @@ test("Jsdoc link in description", () => {
expect(result1).toMatchSnapshot();
});

test("Markdown link", () => {
const result1 = subject(`
/**
@param {string} [dir] [Next.js](https://nextjs.org) project directory path.
*/
`);

expect(result1).toMatchSnapshot();
});

test("Not Capitalizing", () => {
const comment = `/**
Expand Down

0 comments on commit bf2da59

Please sign in to comment.