/*
* Copyright (c) 2020 - present Cloudogu GmbH
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
// import React, { FC } from "react";
// import { storiesOf } from "@storybook/react";
// import MarkdownView from "./MarkdownView";
// import styled from "styled-components";
//
// import TestPage from "../__resources__/test-page.md";
// import MarkdownWithoutLang from "../__resources__/markdown-without-lang.md";
// import MarkdownXmlCodeBlock from "../__resources__/markdown-xml-codeblock.md";
// import MarkdownUmlCodeBlock from "../__resources__/markdown-uml-codeblock.md";
// import MarkdownInlineXml from "../__resources__/markdown-inline-xml.md";
// import MarkdownLinks from "../__resources__/markdown-links.md";
// import MarkdownImages from "../__resources__/markdown-images.md";
// import MarkdownCommitLinks from "../__resources__/markdown-commit-link.md";
// import MarkdownXss from "../__resources__/markdown-xss.md";
// import MarkdownChangelog from "../__resources__/markdown-changelog.md";
// import Title from "../layout/Title";
// import { Subtitle } from "../layout";
// import { MemoryRouter } from "react-router-dom";
// import { Binder, BinderContext, extensionPoints } from "@scm-manager/ui-extensions";
// import { ProtocolLinkRendererProps } from "./markdownExtensions";
// import { RepositoryContextProvider, RepositoryRevisionContextProvider } from "@scm-manager/ui-api";
//
// const Spacing = styled.div`
// padding: 2em;
// `;
//
// storiesOf("MarkdownView", module)
// .addDecorator(story => {story()})
// .addDecorator(story => {story()})
// // Add async parameter, because the tests needs to render async before snapshot is taken so that
// // code fragments get highlighted properly
// .addParameters({ storyshots: { async: true } })
// .add("Default", () => )
// .add("Skip Html", () => )
// .add("Code without Lang", () => )
// .add("Xml Code Block", () => )
// .add("Inline Xml", () => (
// <>
//
//
//
// >
// ))
// .add("Links", () => {
// const binder = new Binder("custom protocol link renderer");
// binder.bind>("markdown-renderer.link.protocol", {
// protocol: "scw",
// renderer: ProtocolLinkRenderer
// });
// return (
//
//
//
// );
// })
// .add("Links without Base Path", () => {
// const binder = new Binder("custom protocol link renderer");
// binder.bind>("markdown-renderer.link.protocol", {
// protocol: "scw",
// renderer: ProtocolLinkRenderer
// });
// return (
//
//
//
// );
// })
// .add("Header Anchor Links", () => (
//
// ))
// .add("Commit Links", () => )
// .add("Custom code renderer", () => {
// const binder = new Binder("custom code renderer");
// const Container: FC<{ value: string }> = ({ value }) => {
// return (
//
//
// To render plantuml as images within markdown, please install the scm-markdown-plantuml-plugin
//
//
{value}
//
// );
// };
// binder.bind>("markdown-renderer.code.uml", Container);
// return (
//
//
//
// );
// })
// .add("XSS Prevention", () => )
// .add("Images", () => (
//
//
//
//
//
// ));
//
// export const ProtocolLinkRenderer: FC> = ({ protocol, href, children }) => {
// return (
//
//
// Link: {href} [Protocol: {protocol}]
//
//
children: {children}
//
// );
// };
import React, { FC } from "react";
import styled from "styled-components";
import type { Meta, StoryObj } from "@storybook/react";
import { Binder, BinderContext, extensionPoints } from "@scm-manager/ui-extensions";
import { RepositoryContextProvider, RepositoryRevisionContextProvider } from "@scm-manager/ui-api";
import MarkdownView from "./MarkdownView";
import Title from "../layout/Title";
import { Subtitle } from "../layout";
import { ProtocolLinkRendererProps } from "./markdownExtensions";
import TestPage from "../__resources__/test-page.md";
import MarkdownWithoutLang from "../__resources__/markdown-without-lang.md";
import MarkdownXmlCodeBlock from "../__resources__/markdown-xml-codeblock.md";
import MarkdownUmlCodeBlock from "../__resources__/markdown-uml-codeblock.md";
import MarkdownInlineXml from "../__resources__/markdown-inline-xml.md";
import MarkdownLinks from "../__resources__/markdown-links.md";
import MarkdownImages from "../__resources__/markdown-images.md";
import MarkdownCommitLinks from "../__resources__/markdown-commit-link.md";
import MarkdownXss from "../__resources__/markdown-xss.md";
import MarkdownChangelog from "../__resources__/markdown-changelog.md";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import { http, HttpResponse } from "msw";
// --- Helfer-Komponenten und Mock-Daten (aus der Original-Story übernommen) ---
const Spacing = styled.div`
padding: 2em;
`;
const ProtocolLinkRenderer: FC> = ({ protocol, href, children }) => (
Link: {href} [Protocol: {protocol}]
children: {children}
);
// --- Storybook Metadaten ---
const meta: Meta = {
title: "Global/MarkdownView",
component: MarkdownView,
decorators: [
(Story) => (
} />
),
(Story) => (
),
],
tags: ["autodocs"],
parameters: {
msw: {
handlers: {
index: http.get("/api/v2/", () =>
HttpResponse.json({
version: "x.y.z",
instanceId: "storybook",
_links: { repositories: { href: "/repositories" } },
}),
),
repository: http.get("/api/v2/repositories/storybook/markdown", () =>
HttpResponse.json({
namespace: "storybook",
name: "markdown",
_links: { content: { href: "/api/v2/repositories/storybook/markdown/content/{revision}/{path}" } },
}),
),
},
},
},
};
export default meta;
// --- Story-Definitionen ---
type Story = StoryObj;
// Einfache Stories, die `args` verwenden
export const Default: Story = {
args: { content: TestPage, skipHtml: false },
};
export const SkipHtml: Story = {
args: { content: TestPage, skipHtml: true },
};
export const CodeWithoutLanguage: Story = {
name: "Code Without Language",
args: { content: MarkdownWithoutLang, skipHtml: false },
};
export const XmlCodeBlock: Story = {
args: { content: MarkdownXmlCodeBlock },
};
export const CommitLinks: Story = {
args: { content: MarkdownCommitLinks },
};
export const HeaderAnchorLinks: Story = {
args: {
content: MarkdownChangelog,
basePath: "/",
permalink: "/?path=/story/markdownview--header-anchor-links",
enableAnchorHeadings: true,
},
};
export const XSSPrevention: Story = {
args: { content: MarkdownXss, skipHtml: false },
};
// Komplexe Stories, die eine `render`-Funktion benötigen
export const InlineXml: Story = {
render: () => (
<>
>
),
};
export const Links: Story = {
render: () => {
const binder = new Binder("custom protocol link renderer");
binder.bind>("markdown-renderer.link.protocol", {
protocol: "scw",
renderer: ProtocolLinkRenderer,
});
return (
);
},
};
export const CustomCodeRenderer: Story = {
name: "Custom Code Renderer (UML)",
render: () => {
const binder = new Binder("custom code renderer");
const Container: FC<{ value: string }> = ({ value }) => (
To render plantuml as images within markdown, please install the scm-markdown-plantuml-plugin
{value}
);
binder.bind>("markdown-renderer.code.uml", Container);
return (
);
},
};
export const Images: Story = {
render: () => (
),
};