Skip to content

Rework reference one line description extraction function #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/components/ReferenceDirectoryWithFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ type ReferenceDirectoryWithFilterProps = {
* @returns One-line description
*/
const getOneLineDescription = (description: string): string => {
// Matches until the first ., ?, !, ।, or 。 followed by a space
const fullStopRegex = /.*?(?:\.\s|\?\s|!\s|।\s|。\s)/;
const cleanedDescription = description
.replace(/<[^>]*>?/gm, "")
.replace(/\n/g, " ");
const [oneLineDescription] = cleanedDescription.match(fullStopRegex) ?? [];
return `${oneLineDescription?.trim() ?? cleanedDescription}`;
// Matches first paragraph tag, remove HTML tags, then trim to first fullstop
const firstParagraphRegex = /^<p>(.*?)<\/p>/;
let [oneLineDescription] = description.replace(/\n/g, " ").trim()
.match(firstParagraphRegex) ?? [];

if(oneLineDescription){
oneLineDescription = oneLineDescription
.replace(/^<p>|<\/p>$/g, "")
.replace(/<\/?code>/g, "")
.replace(/<var>(\d+?)<sup>(\d+?)<\/sup><\/var>/g, "$1^$2")
.replace(/<a href=".*?">|<\/a>/g, "")
.split(/\.\s|\?\s|!\s|।\s|。/)[0];
}

return oneLineDescription ?? "";
};

export const ReferenceDirectoryWithFilter = ({
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/en/p5/createP.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module: DOM
submodule: DOM
file: src/dom/dom.js
description: >
<p>Creates a <code><p></p></code> element.</p>
<p>Creates a paragraph element.</p>

<p><code><p></p></code> elements are commonly used for paragraph-length
text.</p>
Expand Down