diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx index 6d70623a50..6a825a4788 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageContent/dom.tsx @@ -46,7 +46,7 @@ import { scrollIntoAnchor, transform as transformer, copyToClipboard, - useHtmlTransformer, + useSanitizerTransformer, } from '../../transformers'; const MOBILE_MEDIA_QUERY = 'screen and (max-width: 76.1875em)'; @@ -77,7 +77,7 @@ export const useTechDocsReaderDom = ( const sidebar = useSidebar(); const theme = useTheme(); const isMobileMedia = useMediaQuery(MOBILE_MEDIA_QUERY); - const htmlTransformer = useHtmlTransformer(); + const sanitizerTransformer = useSanitizerTransformer(); const techdocsStorageApi = useApi(techdocsStorageApiRef); const scmIntegrationsApi = useApi(scmIntegrationsApiRef); @@ -146,7 +146,7 @@ export const useTechDocsReaderDom = ( const preRender = useCallback( (rawContent: string, contentPath: string) => transformer(rawContent, [ - htmlTransformer, + sanitizerTransformer, addBaseUrl({ techdocsStorageApi, entityId: entityRef, @@ -698,7 +698,7 @@ export const useTechDocsReaderDom = ( sidebar, scmIntegrationsApi, techdocsStorageApi, - htmlTransformer, + sanitizerTransformer, ], ); diff --git a/plugins/techdocs/src/reader/transformers/html/hooks/hooks.ts b/plugins/techdocs/src/reader/transformers/html/hooks/hooks.ts deleted file mode 100644 index a4356db2e9..0000000000 --- a/plugins/techdocs/src/reader/transformers/html/hooks/hooks.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2022 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export { removeUnsafeLinks } from './links'; -export { removeUnsafeIframes } from './iframes'; diff --git a/plugins/techdocs/src/reader/transformers/html/hooks/index.ts b/plugins/techdocs/src/reader/transformers/html/hooks/index.ts index 445136beee..a4356db2e9 100644 --- a/plugins/techdocs/src/reader/transformers/html/hooks/index.ts +++ b/plugins/techdocs/src/reader/transformers/html/hooks/index.ts @@ -14,4 +14,5 @@ * limitations under the License. */ -export * from './hooks'; +export { removeUnsafeLinks } from './links'; +export { removeUnsafeIframes } from './iframes'; diff --git a/plugins/techdocs/src/reader/transformers/html/index.ts b/plugins/techdocs/src/reader/transformers/html/index.ts index ef2708dc8e..4b8bd06798 100644 --- a/plugins/techdocs/src/reader/transformers/html/index.ts +++ b/plugins/techdocs/src/reader/transformers/html/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { useHtmlTransformer } from './transformer'; +export { useSanitizerTransformer } from './transformer'; diff --git a/plugins/techdocs/src/reader/transformers/html/transformer.test.tsx b/plugins/techdocs/src/reader/transformers/html/transformer.test.tsx index ab64eccaa4..dc4eeb85be 100644 --- a/plugins/techdocs/src/reader/transformers/html/transformer.test.tsx +++ b/plugins/techdocs/src/reader/transformers/html/transformer.test.tsx @@ -21,7 +21,7 @@ import { ConfigReader } from '@backstage/core-app-api'; import { ConfigApi, configApiRef } from '@backstage/core-plugin-api'; import { TestApiProvider } from '@backstage/test-utils'; -import { useHtmlTransformer } from './transformer'; +import { useSanitizerTransformer } from './transformer'; const configApiMock: ConfigApi = new ConfigReader({ techdocs: { @@ -39,7 +39,7 @@ const wrapper: FC = ({ children }) => ( describe('Transformers > Html', () => { it('should return a function that removes unsafe links from a given dom element', async () => { - const { result } = renderHook(() => useHtmlTransformer(), { wrapper }); + const { result } = renderHook(() => useSanitizerTransformer(), { wrapper }); const dirtyDom = document.createElement('html'); dirtyDom.innerHTML = ` @@ -62,7 +62,7 @@ describe('Transformers > Html', () => { }); it('should return a function that removes unsafe iframes from a given dom element', async () => { - const { result } = renderHook(() => useHtmlTransformer(), { wrapper }); + const { result } = renderHook(() => useSanitizerTransformer(), { wrapper }); const dirtyDom = document.createElement('html'); dirtyDom.innerHTML = ` diff --git a/plugins/techdocs/src/reader/transformers/html/transformer.ts b/plugins/techdocs/src/reader/transformers/html/transformer.ts index 0c28d3cc49..a197a2d4b7 100644 --- a/plugins/techdocs/src/reader/transformers/html/transformer.ts +++ b/plugins/techdocs/src/reader/transformers/html/transformer.ts @@ -19,7 +19,7 @@ import { useMemo, useCallback } from 'react'; import { useApi, configApiRef } from '@backstage/core-plugin-api'; -import { Transformer } from '..'; +import { Transformer } from '../transformer'; import { removeUnsafeLinks, removeUnsafeIframes } from './hooks'; /** @@ -36,7 +36,7 @@ const useSanitizerConfig = () => { /** * Returns a transformer that sanitizes the dom's internal html. */ -export const useHtmlTransformer = (): Transformer => { +export const useSanitizerTransformer = (): Transformer => { const config = useSanitizerConfig(); return useCallback(