v1.4.7
A React component that displays the content of an editor in JSON format. It converts an array of elements (titles, paragraphs, images, quotes, etc.) into HTML tags.
Composant React permettant d'afficher le contenu d'un éditeur au format JSON. Il convertit un tableau d'éléments (titres, paragraphes, images, citations…) en balises HTML.
Ajoutez un fichier .npmrc à la racine de votre projet :
@jeremiemeunier:registry=https://npm.pkg.github.com
Installez la dépendance :
npm install @jeremiemeunier/editorparser
| Commande | Description |
|---|---|
npm run lint | Vérifie la qualité du code avec ESLint. |
npm run build | Construit les bundles dist/ via tsup. |
npm run pub | Construit puis publie le package sur GitHub Packages. |
npm install npm run lint npm run build # npm run pub
Ce package ne propose pas encore de tests automatisés.
Importez le composant et passez‑lui la structure JSON décrivant votre contenu :
import { EditorParser } from "@jeremiemeunier/editorparser"; const data = [ { type: "h2", content: "Titre" }, { type: "p", content: "Premier paragraphe" }, { type: "img", content: "/image.jpg" }, { type: "cit", content: "Citation", author: "Auteur" }, ]; const Article = () => <EditorParser bson={data} />;
EditorParser accepte la propriété bson qui peut être un élément unique ou un
tableau d'éléments. Chaque élément possède au minimum :
interface EditorBlockElementInterface { type: string; content: string | EditorBlockCardInterface[]; class?: string[]; author?: string; }
Les types reconnus par le parser sont h2 à h6, cit, img et p (par
defaut).