-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/text.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Cloud Annotations | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* ========================================================================== */ | ||
|
||
import { stripText } from "./text"; | ||
|
||
describe("stripText function", () => { | ||
it("should return empty string when passed undefined", () => { | ||
expect(stripText(undefined)).toBe(""); | ||
}); | ||
|
||
it("should strip markdown", () => { | ||
expect( | ||
stripText( | ||
"**This** description contains [markdown](https://www.markdownguide.org/)" | ||
) | ||
).toBe("This description contains markdown"); | ||
}); | ||
|
||
it("should strip HTML", () => { | ||
expect( | ||
stripText( | ||
'<strong>This</strong> description contains <a href="https://www.w3.org/html/">HTML</a>' | ||
) | ||
).toBe("This description contains HTML"); | ||
}); | ||
|
||
it("should replace newlines with space", () => { | ||
expect(stripText("one\ntwo\n\nthree")).toBe("one two three"); | ||
}); | ||
|
||
it("should insert whitespace between HTML elements", () => { | ||
expect( | ||
stripText("<div><div>one</div></div><p>two</p><p>three</p><br />four") | ||
).toBe("one two three four"); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/docusaurus-theme-openapi/src/theme/ApiDemoPanel/text.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* ============================================================================ | ||
* Copyright (c) Cloud Annotations | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* ========================================================================== */ | ||
|
||
import { marked } from "marked"; | ||
import striptags from "striptags"; | ||
|
||
export function stripText(text?: string): string { | ||
if (text === undefined) { | ||
return ""; | ||
} | ||
const renderer = new marked.TextRenderer(); | ||
marked.use({ silent: true, renderer }); | ||
const parsedMarkdown = marked.parse(text, { async: false }) as string; | ||
return striptags(parsedMarkdown, [], " ").replace(/\s+/g, " ").trim(); | ||
} |
Oops, something went wrong.