Skip to content

Commit

Permalink
fix: the "caption" should place behind the tag of "example" (#15)
Browse files Browse the repository at this point in the history
* chore: prettier

* fix: the "caption" should place behind the tag of "example"

* fix: handler multi caption tag

Co-authored-by: Hossein Mohammadi <[email protected]>
  • Loading branch information
aqzhyi and hosseinmd authored Dec 19, 2020
1 parent 0c0292a commit b8d6e34
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ const stringify = (

// Try to use prettier on @example tag description
if (tag === EXAMPLE) {
const exampleCaption = description.match(
/<caption>(((?!(<\/caption>))[\s\S])*)<\/caption>/i,
);

if (exampleCaption) {
description = description.replace(exampleCaption[0], "");
tagString = `${tagString} ${exampleCaption[0]}`;
}

try {
const formattedExample = format(description || "", options);
tagString += formattedExample.replace(/(^|\n)/g, "\n ");
Expand Down
14 changes: 12 additions & 2 deletions tests/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@ exports[`Big single word 1`] = `

exports[`Example start by xml tag 1`] = `
"/**
* @example
* <caption>TradingViewChart</caption>;
* @example <caption>TradingViewChart</caption>
* export default Something;
*/
"
`;

exports[`Example start by xml tag 2`] = `
"/**
* @example <caption>TradingViewChart</caption>
* function Something() {
* return <caption>TradingViewChart</caption>;
* }
* export default Something;
*/
"
Expand Down
15 changes: 14 additions & 1 deletion tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,25 @@ test("Example start by xml tag", () => {
const result = subject(`
/**
* @example <caption>TradingViewChart</caption>;
*
*
* export default Something
*/
`);

expect(result).toMatchSnapshot();

const result1 = subject(`
/**
* @example <caption>TradingViewChart</caption>
*
* function Something(){
* return <caption>TradingViewChart</caption>
* }
* export default Something
*/
`);

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

test("Bad defined name", () => {
Expand Down

0 comments on commit b8d6e34

Please sign in to comment.