allaw-ui 0.1.62 → 0.1.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import "./Paragraph.css";
|
|
3
|
+
import { convertToHtml } from "../../../utils/utils";
|
|
3
4
|
var Paragraph = function (_a) {
|
|
4
5
|
var variant = _a.variant, color = _a.color, text = _a.text, maxLines = _a.maxLines, maxChars = _a.maxChars, _b = _a.size, size = _b === void 0 ? "default" : _b;
|
|
5
6
|
// Fonction pour tronquer le texte en fonction du nombre maximum de caractères
|
|
@@ -8,10 +9,10 @@ var Paragraph = function (_a) {
|
|
|
8
9
|
return text;
|
|
9
10
|
return text.slice(0, maxChars) + "...";
|
|
10
11
|
};
|
|
12
|
+
// Convertir le texte en HTML avant de le tronquer
|
|
13
|
+
var htmlText = convertToHtml(text);
|
|
11
14
|
// Tronquer le texte si maxChars est défini
|
|
12
|
-
var truncatedText = maxChars
|
|
13
|
-
? truncateText(text, maxChars)
|
|
14
|
-
: text;
|
|
15
|
+
var truncatedText = maxChars ? truncateText(htmlText, maxChars) : htmlText;
|
|
15
16
|
return (React.createElement("p", { className: "paragraph ".concat(variant, " ").concat(color ? "color-".concat(color) : "", " ").concat(size === "small" ? "paragraph-small" : ""), style: maxLines
|
|
16
17
|
? {
|
|
17
18
|
WebkitLineClamp: maxLines,
|
|
@@ -19,6 +20,6 @@ var Paragraph = function (_a) {
|
|
|
19
20
|
WebkitBoxOrient: "vertical",
|
|
20
21
|
overflow: "hidden",
|
|
21
22
|
}
|
|
22
|
-
: {} }
|
|
23
|
+
: {}, dangerouslySetInnerHTML: { __html: truncatedText } }));
|
|
23
24
|
};
|
|
24
25
|
export default Paragraph;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertToHtml(text: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function convertToHtml(text) {
|
|
2
|
+
var lines = text.split(/\\n/); // Diviser la chaîne en un tableau de lignes en utilisant \n comme séparateur
|
|
3
|
+
var htmlLines = lines.map(function (line) {
|
|
4
|
+
// Traiter chaque ligne individuellement
|
|
5
|
+
return line
|
|
6
|
+
.replace(/</g, "<") // Échappe les caractères <
|
|
7
|
+
.replace(/>/g, ">") // Échappe les caractères >
|
|
8
|
+
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>") // Remplace **texte** par <strong>texte</strong>
|
|
9
|
+
.replace(/\_(.+?)\_/g, "<em>$1</em>") // Remplace _texte_ par <em>texte</em>
|
|
10
|
+
.replace(/\~\~(.+?)\~\~/g, "<del>$1</del>") // Remplace ~~texte~~ par <del>texte</del>
|
|
11
|
+
.replace(/\`(.+?)\`/g, "<code>$1</code>") // Remplace `texte` par <code>texte</code>
|
|
12
|
+
.replace(/\u2022\s?/g, "<li>") // Remplace les puces (•) par <li>
|
|
13
|
+
.trim(); // Supprimer les espaces de début et de fin
|
|
14
|
+
});
|
|
15
|
+
return htmlLines.join("<br>"); // Rejoindre les lignes avec <br>
|
|
16
|
+
}
|