Skip to content

Commit 0e516df

Browse files
authored
Merge pull request #697 from limzykenneth/main
Rework reference one line description extraction function
2 parents 8d3ab19 + 1ea2306 commit 0e516df

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/components/ReferenceDirectoryWithFilter/index.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,21 @@ type ReferenceDirectoryWithFilterProps = {
3838
* @returns One-line description
3939
*/
4040
const getOneLineDescription = (description: string): string => {
41-
// Matches until the first ., ?, !, ।, or 。 followed by a space
42-
const fullStopRegex = /.*?(?:\.\s|\?\s|!\s|\s|\s)/;
43-
const cleanedDescription = description
44-
.replace(/<[^>]*>?/gm, "")
45-
.replace(/\n/g, " ");
46-
const [oneLineDescription] = cleanedDescription.match(fullStopRegex) ?? [];
47-
return `${oneLineDescription?.trim() ?? cleanedDescription}`;
41+
// Matches first paragraph tag, remove HTML tags, then trim to first fullstop
42+
const firstParagraphRegex = /^<p>(.*?)<\/p>/;
43+
let [oneLineDescription] = description.replace(/\n/g, " ").trim()
44+
.match(firstParagraphRegex) ?? [];
45+
46+
if(oneLineDescription){
47+
oneLineDescription = oneLineDescription
48+
.replace(/^<p>|<\/p>$/g, "")
49+
.replace(/<\/?code>/g, "")
50+
.replace(/<var>(\d+?)<sup>(\d+?)<\/sup><\/var>/g, "$1^$2")
51+
.replace(/<a href=".*?">|<\/a>/g, "")
52+
.split(/\.\s|\?\s|!\s|\s|/)[0];
53+
}
54+
55+
return oneLineDescription ?? "";
4856
};
4957

5058
export const ReferenceDirectoryWithFilter = ({

src/content/reference/en/p5/createP.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module: DOM
44
submodule: DOM
55
file: src/dom/dom.js
66
description: >
7-
<p>Creates a <code><p></p></code> element.</p>
7+
<p>Creates a paragraph element.</p>
88
99
<p><code><p></p></code> elements are commonly used for paragraph-length
1010
text.</p>

0 commit comments

Comments
 (0)