diff --git a/frontend/src/components/markdown-renderer/hooks/use-markdown-extensions.ts b/frontend/src/components/markdown-renderer/hooks/use-markdown-extensions.ts index de1e632a0..e9f924882 100644 --- a/frontend/src/components/markdown-renderer/hooks/use-markdown-extensions.ts +++ b/frontend/src/components/markdown-renderer/hooks/use-markdown-extensions.ts @@ -5,6 +5,7 @@ */ import { allAppExtensions } from '../../../extensions/extra-integrations/all-app-extensions' import { useFrontendConfig } from '../../common/frontend-config-context/use-frontend-config' +import type { RendererType } from '../../render-page/window-post-message-communicator/rendering-message' import type { MarkdownRendererExtension } from '../extensions/base/markdown-renderer-extension' import { DebuggerMarkdownExtension } from '../extensions/debugger-markdown-extension' import { ProxyImageMarkdownExtension } from '../extensions/image/proxy-image-markdown-extension' @@ -18,11 +19,13 @@ import { useMemo } from 'react' * Provides a list of {@link MarkdownRendererExtension markdown extensions} that is a combination of the common extensions and the given additional. * * @param baseUrl The base url for the {@link LinkAdjustmentMarkdownExtension} + * @param rendererType The type of the renderer that uses the extensions * @param additionalExtensions The additional extensions that should be included in the list * @return The created list of markdown extensions */ export const useMarkdownExtensions = ( baseUrl: string, + rendererType: RendererType, additionalExtensions: MarkdownRendererExtension[] ): MarkdownRendererExtension[] => { const extensionEventEmitter = useExtensionEventEmitter() @@ -35,7 +38,8 @@ export const useMarkdownExtensions = ( ...allAppExtensions.flatMap((extension) => extension.buildMarkdownRendererExtensions({ frontendConfig: frontendConfig, - eventEmitter: extensionEventEmitter + eventEmitter: extensionEventEmitter, + rendererType }) ), ...additionalExtensions, @@ -45,5 +49,5 @@ export const useMarkdownExtensions = ( new DebuggerMarkdownExtension(), new ProxyImageMarkdownExtension() ] - }, [additionalExtensions, baseUrl, extensionEventEmitter, frontendConfig]) + }, [additionalExtensions, baseUrl, extensionEventEmitter, frontendConfig, rendererType]) } diff --git a/frontend/src/components/render-page/renderers/document/document-markdown-renderer.tsx b/frontend/src/components/render-page/renderers/document/document-markdown-renderer.tsx index 215b10c09..a17f45643 100644 --- a/frontend/src/components/render-page/renderers/document/document-markdown-renderer.tsx +++ b/frontend/src/components/render-page/renderers/document/document-markdown-renderer.tsx @@ -12,6 +12,7 @@ import { useCalculateLineMarkerPosition } from '../../../markdown-renderer/hooks import { useMarkdownExtensions } from '../../../markdown-renderer/hooks/use-markdown-extensions' import { MarkdownToReact } from '../../../markdown-renderer/markdown-to-react/markdown-to-react' import { useDocumentSyncScrolling } from '../../hooks/sync-scroll/use-document-sync-scrolling' +import { RendererType } from '../../window-post-message-communicator/rendering-message' import type { CommonMarkdownRendererProps, HeightChangeRendererProps } from '../common-markdown-renderer-props' import { DocumentTocSidebar } from './document-toc-sidebar' import styles from './markdown-document.module.scss' @@ -67,6 +68,7 @@ export const DocumentMarkdownRenderer: React.FC = const extensions = useMarkdownExtensions( baseUrl, + RendererType.DOCUMENT, useMemo( () => [ new HeadlineAnchorsMarkdownExtension(), diff --git a/frontend/src/components/render-page/renderers/simple/simple-markdown-renderer.tsx b/frontend/src/components/render-page/renderers/simple/simple-markdown-renderer.tsx index 2073948d8..1ab40b7b3 100644 --- a/frontend/src/components/render-page/renderers/simple/simple-markdown-renderer.tsx +++ b/frontend/src/components/render-page/renderers/simple/simple-markdown-renderer.tsx @@ -6,6 +6,7 @@ import { cypressId } from '../../../../utils/cypress-attribute' import { useMarkdownExtensions } from '../../../markdown-renderer/hooks/use-markdown-extensions' import { MarkdownToReact } from '../../../markdown-renderer/markdown-to-react/markdown-to-react' +import { RendererType } from '../../window-post-message-communicator/rendering-message' import type { CommonMarkdownRendererProps, HeightChangeRendererProps } from '../common-markdown-renderer-props' import useResizeObserver from '@react-hook/resize-observer' import React, { useEffect, useRef, useState } from 'react' @@ -32,7 +33,7 @@ export const SimpleMarkdownRenderer: React.FC = ({ setRendererSize(entry.contentRect) }) useEffect(() => onHeightChange?.((rendererSize?.height ?? 0) + 1), [rendererSize, onHeightChange]) - const extensions = useMarkdownExtensions(baseUrl, []) + const extensions = useMarkdownExtensions(baseUrl, RendererType.SIMPLE, []) return (
diff --git a/frontend/src/components/render-page/renderers/slideshow/slideshow-markdown-renderer.tsx b/frontend/src/components/render-page/renderers/slideshow/slideshow-markdown-renderer.tsx index 18e7bec26..56f7460da 100644 --- a/frontend/src/components/render-page/renderers/slideshow/slideshow-markdown-renderer.tsx +++ b/frontend/src/components/render-page/renderers/slideshow/slideshow-markdown-renderer.tsx @@ -7,6 +7,7 @@ import { RevealMarkdownExtension } from '../../../markdown-renderer/extensions/r import { useMarkdownExtensions } from '../../../markdown-renderer/hooks/use-markdown-extensions' import { REVEAL_STATUS, useReveal } from '../../../markdown-renderer/hooks/use-reveal' import { MarkdownToReact } from '../../../markdown-renderer/markdown-to-react/markdown-to-react' +import { RendererType } from '../../window-post-message-communicator/rendering-message' import type { CommonMarkdownRendererProps } from '../common-markdown-renderer-props' import { LoadingSlide } from './loading-slide' import type { SlideOptions } from '@hedgedoc/commons' @@ -34,6 +35,7 @@ export const SlideshowMarkdownRenderer: React.FC const extensions = useMarkdownExtensions( baseUrl, + RendererType.SLIDESHOW, useMemo(() => [new RevealMarkdownExtension()], []) ) diff --git a/frontend/src/extensions/base/app-extension.ts b/frontend/src/extensions/base/app-extension.ts index f8ab1419d..558f79ad3 100644 --- a/frontend/src/extensions/base/app-extension.ts +++ b/frontend/src/extensions/base/app-extension.ts @@ -7,6 +7,7 @@ import type { FrontendConfig } from '../../api/config/types' import type { CheatsheetExtension } from '../../components/editor-page/cheatsheet/cheatsheet-extension' import type { Linter } from '../../components/editor-page/editor-pane/linter/linter' import type { MarkdownRendererExtension } from '../../components/markdown-renderer/extensions/base/markdown-renderer-extension' +import type { RendererType } from '../../components/render-page/window-post-message-communicator/rendering-message' import type { CompletionSource } from '@codemirror/autocomplete' import type { EventEmitter2 } from 'eventemitter2' import type React from 'react' @@ -15,6 +16,7 @@ import { Fragment } from 'react' export interface MarkdownRendererExtensionOptions { frontendConfig: FrontendConfig eventEmitter: EventEmitter2 + rendererType: RendererType } export abstract class AppExtension {