rebuild MarkdownLinkRenderer and added real world use cases

This commit is contained in:
Sebastian Sdorra
2020-05-19 15:51:33 +02:00
parent 50e4316886
commit d1f10ec5a7
3 changed files with 83 additions and 62 deletions

View File

@@ -29,7 +29,7 @@ import { binder } from "@scm-manager/ui-extensions";
import ErrorBoundary from "./ErrorBoundary";
import SyntaxHighlighter from "./SyntaxHighlighter";
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
import MarkdownLinkRenderer from "./MarkdownLinkRenderer";
import { create } from "./MarkdownLinkRenderer";
import { useTranslation } from "react-i18next";
import Notification from "./Notification";
@@ -39,6 +39,8 @@ type Props = RouteComponentProps & {
renderers?: any;
skipHtml?: boolean;
enableAnchorHeadings?: boolean;
// basePath for markdown links
basePath?: string;
};
const xmlMarkupSample = `\`\`\`xml
@@ -98,7 +100,7 @@ class MarkdownView extends React.Component<Props> {
}
render() {
const { content, renderers, renderContext, enableAnchorHeadings, skipHtml } = this.props;
const { content, renderers, renderContext, enableAnchorHeadings, skipHtml, basePath } = this.props;
const rendererFactory = binder.getExtension("markdown-renderer-factory");
let rendererList = renderers;
@@ -115,7 +117,9 @@ class MarkdownView extends React.Component<Props> {
rendererList.heading = MarkdownHeadingRenderer;
}
rendererList.link = MarkdownLinkRenderer;
if (basePath && !rendererList.link) {
rendererList.link = create(basePath);
}
if (!rendererList.code) {
rendererList.code = SyntaxHighlighter;