@backstage/plugin-techdocs 1.10.8-next.1 → 1.10.8-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/alpha/package.json +1 -1
- package/dist/reader/components/TechDocsReaderPageContent/dom.esm.js +3 -1
- package/dist/reader/components/TechDocsReaderPageContent/dom.esm.js.map +1 -1
- package/dist/reader/transformers/handleMetaRedirects.esm.js +34 -0
- package/dist/reader/transformers/handleMetaRedirects.esm.js.map +1 -0
- package/dist/reader/transformers/html/transformer.esm.js +17 -1
- package/dist/reader/transformers/html/transformer.esm.js.map +1 -1
- package/dist/reader/transformers/styles/rules/typeset.esm.js +14 -6
- package/dist/reader/transformers/styles/rules/typeset.esm.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @backstage/plugin-techdocs
|
|
2
2
|
|
|
3
|
+
## 1.10.8-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 67e76f2: TechDocs now supports the `mkdocs-redirects` plugin. Redirects defined using the `mkdocs-redirect` plugin will be handled automatically in TechDocs. Redirecting to external urls is not supported. In the case that an external redirect url is provided, TechDocs will redirect to the current documentation site home.
|
|
8
|
+
- bdc5471: Fixed issue where header styles were incorrectly generated when themes used CSS variables to define font size.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- @backstage/frontend-plugin-api@0.7.0-next.2
|
|
11
|
+
- @backstage/core-compat-api@0.2.8-next.2
|
|
12
|
+
- @backstage/plugin-search-common@1.2.14-next.1
|
|
13
|
+
- @backstage/plugin-search-react@1.7.14-next.2
|
|
14
|
+
- @backstage/plugin-catalog-react@1.12.3-next.2
|
|
15
|
+
- @backstage/integration@1.14.0-next.0
|
|
16
|
+
- @backstage/catalog-model@1.5.0
|
|
17
|
+
- @backstage/config@1.2.0
|
|
18
|
+
- @backstage/core-components@0.14.10-next.0
|
|
19
|
+
- @backstage/core-plugin-api@1.9.3
|
|
20
|
+
- @backstage/errors@1.2.4
|
|
21
|
+
- @backstage/integration-react@1.1.30-next.0
|
|
22
|
+
- @backstage/theme@0.5.6
|
|
23
|
+
- @backstage/plugin-auth-react@0.1.5-next.0
|
|
24
|
+
- @backstage/plugin-techdocs-common@0.1.0-next.0
|
|
25
|
+
- @backstage/plugin-techdocs-react@1.2.7-next.0
|
|
26
|
+
|
|
3
27
|
## 1.10.8-next.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -19,6 +19,7 @@ import { onCssReady } from '../../transformers/onCssReady.esm.js';
|
|
|
19
19
|
import { scrollIntoNavigation } from '../../transformers/scrollIntoNavigation.esm.js';
|
|
20
20
|
import { transform } from '../../transformers/transformer.esm.js';
|
|
21
21
|
import { useNavigateUrl } from './useNavigateUrl.esm.js';
|
|
22
|
+
import { handleMetaRedirects } from '../../transformers/handleMetaRedirects.esm.js';
|
|
22
23
|
|
|
23
24
|
const MOBILE_MEDIA_QUERY = "screen and (max-width: 76.1875em)";
|
|
24
25
|
const useTechDocsReaderDom = (entityRef) => {
|
|
@@ -119,6 +120,7 @@ const useTechDocsReaderDom = (entityRef) => {
|
|
|
119
120
|
);
|
|
120
121
|
const postRender = useCallback(
|
|
121
122
|
async (transformedElement) => transform(transformedElement, [
|
|
123
|
+
handleMetaRedirects(navigate, entityRef.name),
|
|
122
124
|
scrollIntoNavigation(),
|
|
123
125
|
copyToClipboard(theme),
|
|
124
126
|
addLinkClickListener({
|
|
@@ -167,7 +169,7 @@ const useTechDocsReaderDom = (entityRef) => {
|
|
|
167
169
|
}
|
|
168
170
|
})
|
|
169
171
|
]),
|
|
170
|
-
[theme, navigate, analytics]
|
|
172
|
+
[theme, navigate, analytics, entityRef.name]
|
|
171
173
|
);
|
|
172
174
|
useEffect(() => {
|
|
173
175
|
if (!rawPage) return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.esm.js","sources":["../../../../src/reader/components/TechDocsReaderPageContent/dom.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport { useTheme } from '@material-ui/core/styles';\n\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { useAnalytics, useApi } from '@backstage/core-plugin-api';\nimport { scmIntegrationsApiRef } from '@backstage/integration-react';\n\nimport {\n techdocsStorageApiRef,\n useShadowDomStylesLoading,\n} from '@backstage/plugin-techdocs-react';\n\nimport { useTechDocsReader } from '../TechDocsReaderProvider';\n\nimport {\n addBaseUrl,\n addGitFeedbackLink,\n addLinkClickListener,\n addSidebarToggle,\n onCssReady,\n removeMkdocsHeader,\n rewriteDocLinks,\n simplifyMkdocsFooter,\n scrollIntoNavigation,\n transform as transformer,\n copyToClipboard,\n useSanitizerTransformer,\n useStylesTransformer,\n} from '../../transformers';\nimport { useNavigateUrl } from './useNavigateUrl';\n\nconst MOBILE_MEDIA_QUERY = 'screen and (max-width: 76.1875em)';\n\n/**\n * Hook that encapsulates the behavior of getting raw HTML and applying\n * transforms to it in order to make it function at a basic level in the\n * Backstage UI.\n */\nexport const useTechDocsReaderDom = (\n entityRef: CompoundEntityRef,\n): Element | null => {\n const navigate = useNavigateUrl();\n const theme = useTheme();\n const isMobileMedia = useMediaQuery(MOBILE_MEDIA_QUERY);\n const sanitizerTransformer = useSanitizerTransformer();\n const stylesTransformer = useStylesTransformer();\n const analytics = useAnalytics();\n\n const techdocsStorageApi = useApi(techdocsStorageApiRef);\n const scmIntegrationsApi = useApi(scmIntegrationsApiRef);\n\n const { state, path, content: rawPage } = useTechDocsReader();\n\n const [dom, setDom] = useState<HTMLElement | null>(null);\n const isStyleLoading = useShadowDomStylesLoading(dom);\n\n const updateSidebarPositionAndHeight = useCallback(() => {\n if (!dom) return;\n\n const sidebars = dom.querySelectorAll<HTMLElement>('.md-sidebar');\n\n sidebars.forEach(element => {\n // set sidebar position to render in correct position\n if (isMobileMedia) {\n element.style.top = '0px';\n } else {\n const page = document?.querySelector('.techdocs-reader-page');\n const pageTop = page?.getBoundingClientRect().top ?? 0;\n let domTop = dom.getBoundingClientRect().top ?? 0;\n\n const tabs = dom.querySelector('.md-container > .md-tabs');\n const tabsHeight = tabs?.getBoundingClientRect().height ?? 0;\n\n // the sidebars should not scroll beyond the total height of the header and tabs\n if (domTop < pageTop) {\n domTop = pageTop;\n }\n\n const scrollbarTopPx = Math.max(domTop, 0) + tabsHeight;\n\n element.style.top = `${scrollbarTopPx}px`;\n\n // set scrollbar height to ensure all links can be seen when content is small\n const footer = dom.querySelector('.md-container > .md-footer');\n // if no footer, fallback to using the bottom of the window\n const scrollbarEndPx =\n footer?.getBoundingClientRect().top ?? window.innerHeight;\n\n element.style.height = `${scrollbarEndPx - scrollbarTopPx}px`;\n }\n\n // show the sidebar only after updating its position\n element.style.setProperty('opacity', '1');\n });\n }, [dom, isMobileMedia]);\n\n useEffect(() => {\n window.addEventListener('resize', updateSidebarPositionAndHeight);\n window.addEventListener('scroll', updateSidebarPositionAndHeight, true);\n return () => {\n window.removeEventListener('resize', updateSidebarPositionAndHeight);\n window.removeEventListener(\n 'scroll',\n updateSidebarPositionAndHeight,\n true,\n );\n };\n }, [dom, updateSidebarPositionAndHeight]);\n\n // dynamically set width of footer to accommodate for pinning of the sidebar\n const updateFooterWidth = useCallback(() => {\n if (!dom) return;\n const footer = dom.querySelector<HTMLElement>('.md-footer');\n if (footer) {\n footer.style.width = `${dom.getBoundingClientRect().width}px`;\n }\n }, [dom]);\n\n useEffect(() => {\n window.addEventListener('resize', updateFooterWidth);\n return () => {\n window.removeEventListener('resize', updateFooterWidth);\n };\n }, [dom, updateFooterWidth]);\n\n // an update to \"state\" might lead to an updated UI so we include it as a trigger\n useEffect(() => {\n if (!isStyleLoading) {\n updateFooterWidth();\n updateSidebarPositionAndHeight();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n state,\n isStyleLoading,\n updateFooterWidth,\n updateSidebarPositionAndHeight,\n ]);\n\n // a function that performs transformations that are executed prior to adding it to the DOM\n const preRender = useCallback(\n (rawContent: string, contentPath: string) =>\n transformer(rawContent, [\n sanitizerTransformer,\n addBaseUrl({\n techdocsStorageApi,\n entityId: entityRef,\n path: contentPath,\n }),\n rewriteDocLinks(),\n addSidebarToggle(),\n removeMkdocsHeader(),\n simplifyMkdocsFooter(),\n addGitFeedbackLink(scmIntegrationsApi),\n stylesTransformer,\n ]),\n [\n // only add dependencies that are in state or memorized variables to avoid unnecessary calls between re-renders\n entityRef,\n scmIntegrationsApi,\n techdocsStorageApi,\n sanitizerTransformer,\n stylesTransformer,\n ],\n );\n\n // a function that performs transformations that are executed after adding it to the DOM\n const postRender = useCallback(\n async (transformedElement: Element) =>\n transformer(transformedElement, [\n scrollIntoNavigation(),\n copyToClipboard(theme),\n addLinkClickListener({\n baseUrl: window.location.origin,\n onClick: (event: MouseEvent, url: string) => {\n // detect if CTRL or META keys are pressed so that links can be opened in a new tab with `window.open`\n const modifierActive = event.ctrlKey || event.metaKey;\n const parsedUrl = new URL(url);\n\n // capture link clicks within documentation\n const linkText =\n (event.target as HTMLAnchorElement | undefined)?.innerText || url;\n const to = url.replace(window.location.origin, '');\n analytics.captureEvent('click', linkText, { attributes: { to } });\n\n // hash exists when anchor is clicked on secondary sidebar\n if (parsedUrl.hash) {\n if (modifierActive) {\n window.open(url, '_blank');\n } else {\n navigate(url);\n // Scroll to hash if it's on the current page\n transformedElement\n ?.querySelector(`[id=\"${parsedUrl.hash.slice(1)}\"]`)\n ?.scrollIntoView();\n }\n } else {\n if (modifierActive) {\n window.open(url, '_blank');\n } else {\n navigate(url);\n }\n }\n },\n }),\n // disable MkDocs drawer toggling ('for' attribute => checkbox mechanism)\n onCssReady({\n onLoading: () => {},\n onLoaded: () => {\n transformedElement\n .querySelector('.md-nav__title')\n ?.removeAttribute('for');\n },\n }),\n // hide sidebars until their positions are updated\n onCssReady({\n onLoading: () => {\n const sidebars = Array.from(\n transformedElement.querySelectorAll<HTMLElement>('.md-sidebar'),\n );\n sidebars.forEach(element => {\n element.style.setProperty('opacity', '0');\n });\n },\n onLoaded: () => {},\n }),\n ]),\n [theme, navigate, analytics],\n );\n\n useEffect(() => {\n if (!rawPage) return () => {};\n\n // if false, there is already a newer execution of this effect\n let shouldReplaceContent = true;\n\n // Pre-render\n preRender(rawPage, path).then(async preTransformedDomElement => {\n if (!preTransformedDomElement?.innerHTML) {\n return; // An unexpected error occurred\n }\n\n // don't manipulate the shadow dom if this isn't the latest effect execution\n if (!shouldReplaceContent) {\n return;\n }\n\n // Scroll to top after render\n window.scroll({ top: 0 });\n\n // Post-render\n const postTransformedDomElement = await postRender(\n preTransformedDomElement,\n );\n setDom(postTransformedDomElement as HTMLElement);\n });\n\n // cancel this execution\n return () => {\n shouldReplaceContent = false;\n };\n }, [rawPage, path, preRender, postRender]);\n\n return dom;\n};\n"],"names":["transformer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,kBAAqB,GAAA,mCAAA,CAAA;AAOd,MAAA,oBAAA,GAAuB,CAClC,SACmB,KAAA;AACnB,EAAA,MAAM,WAAW,cAAe,EAAA,CAAA;AAChC,EAAA,MAAM,QAAQ,QAAS,EAAA,CAAA;AACvB,EAAM,MAAA,aAAA,GAAgB,cAAc,kBAAkB,CAAA,CAAA;AACtD,EAAA,MAAM,uBAAuB,uBAAwB,EAAA,CAAA;AACrD,EAAA,MAAM,oBAAoB,oBAAqB,E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,wBAAA;AAAA,OACF,CAAA;AACA,MAAA,MAAA,CAAO,yBAAwC,CAAA,CAAA;AAAA,KAChD,CAAA,CAAA;AAGD,IAAA,OAAO,MAAM;AACX,MAAuB,oBAAA,GAAA,KAAA,CAAA;AAAA,KACzB,CAAA;AAAA,KACC,CAAC,OAAA,EAAS,IAAM,EAAA,SAAA,EAAW,UAAU,CAAC,CAAA,CAAA;AAEzC,EAAO,OAAA,GAAA,CAAA;AACT;;;;"}
|
|
1
|
+
{"version":3,"file":"dom.esm.js","sources":["../../../../src/reader/components/TechDocsReaderPageContent/dom.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useCallback, useEffect, useState } from 'react';\n\nimport useMediaQuery from '@material-ui/core/useMediaQuery';\nimport { useTheme } from '@material-ui/core/styles';\n\nimport { CompoundEntityRef } from '@backstage/catalog-model';\nimport { useAnalytics, useApi } from '@backstage/core-plugin-api';\nimport { scmIntegrationsApiRef } from '@backstage/integration-react';\n\nimport {\n techdocsStorageApiRef,\n useShadowDomStylesLoading,\n} from '@backstage/plugin-techdocs-react';\n\nimport { useTechDocsReader } from '../TechDocsReaderProvider';\n\nimport {\n addBaseUrl,\n addGitFeedbackLink,\n addLinkClickListener,\n addSidebarToggle,\n onCssReady,\n removeMkdocsHeader,\n rewriteDocLinks,\n simplifyMkdocsFooter,\n scrollIntoNavigation,\n transform as transformer,\n copyToClipboard,\n useSanitizerTransformer,\n useStylesTransformer,\n} from '../../transformers';\nimport { useNavigateUrl } from './useNavigateUrl';\nimport { handleMetaRedirects } from '../../transformers/handleMetaRedirects';\n\nconst MOBILE_MEDIA_QUERY = 'screen and (max-width: 76.1875em)';\n\n/**\n * Hook that encapsulates the behavior of getting raw HTML and applying\n * transforms to it in order to make it function at a basic level in the\n * Backstage UI.\n */\nexport const useTechDocsReaderDom = (\n entityRef: CompoundEntityRef,\n): Element | null => {\n const navigate = useNavigateUrl();\n const theme = useTheme();\n const isMobileMedia = useMediaQuery(MOBILE_MEDIA_QUERY);\n const sanitizerTransformer = useSanitizerTransformer();\n const stylesTransformer = useStylesTransformer();\n const analytics = useAnalytics();\n\n const techdocsStorageApi = useApi(techdocsStorageApiRef);\n const scmIntegrationsApi = useApi(scmIntegrationsApiRef);\n\n const { state, path, content: rawPage } = useTechDocsReader();\n\n const [dom, setDom] = useState<HTMLElement | null>(null);\n const isStyleLoading = useShadowDomStylesLoading(dom);\n\n const updateSidebarPositionAndHeight = useCallback(() => {\n if (!dom) return;\n\n const sidebars = dom.querySelectorAll<HTMLElement>('.md-sidebar');\n\n sidebars.forEach(element => {\n // set sidebar position to render in correct position\n if (isMobileMedia) {\n element.style.top = '0px';\n } else {\n const page = document?.querySelector('.techdocs-reader-page');\n const pageTop = page?.getBoundingClientRect().top ?? 0;\n let domTop = dom.getBoundingClientRect().top ?? 0;\n\n const tabs = dom.querySelector('.md-container > .md-tabs');\n const tabsHeight = tabs?.getBoundingClientRect().height ?? 0;\n\n // the sidebars should not scroll beyond the total height of the header and tabs\n if (domTop < pageTop) {\n domTop = pageTop;\n }\n\n const scrollbarTopPx = Math.max(domTop, 0) + tabsHeight;\n\n element.style.top = `${scrollbarTopPx}px`;\n\n // set scrollbar height to ensure all links can be seen when content is small\n const footer = dom.querySelector('.md-container > .md-footer');\n // if no footer, fallback to using the bottom of the window\n const scrollbarEndPx =\n footer?.getBoundingClientRect().top ?? window.innerHeight;\n\n element.style.height = `${scrollbarEndPx - scrollbarTopPx}px`;\n }\n\n // show the sidebar only after updating its position\n element.style.setProperty('opacity', '1');\n });\n }, [dom, isMobileMedia]);\n\n useEffect(() => {\n window.addEventListener('resize', updateSidebarPositionAndHeight);\n window.addEventListener('scroll', updateSidebarPositionAndHeight, true);\n return () => {\n window.removeEventListener('resize', updateSidebarPositionAndHeight);\n window.removeEventListener(\n 'scroll',\n updateSidebarPositionAndHeight,\n true,\n );\n };\n }, [dom, updateSidebarPositionAndHeight]);\n\n // dynamically set width of footer to accommodate for pinning of the sidebar\n const updateFooterWidth = useCallback(() => {\n if (!dom) return;\n const footer = dom.querySelector<HTMLElement>('.md-footer');\n if (footer) {\n footer.style.width = `${dom.getBoundingClientRect().width}px`;\n }\n }, [dom]);\n\n useEffect(() => {\n window.addEventListener('resize', updateFooterWidth);\n return () => {\n window.removeEventListener('resize', updateFooterWidth);\n };\n }, [dom, updateFooterWidth]);\n\n // an update to \"state\" might lead to an updated UI so we include it as a trigger\n useEffect(() => {\n if (!isStyleLoading) {\n updateFooterWidth();\n updateSidebarPositionAndHeight();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n state,\n isStyleLoading,\n updateFooterWidth,\n updateSidebarPositionAndHeight,\n ]);\n\n // a function that performs transformations that are executed prior to adding it to the DOM\n const preRender = useCallback(\n (rawContent: string, contentPath: string) =>\n transformer(rawContent, [\n sanitizerTransformer,\n addBaseUrl({\n techdocsStorageApi,\n entityId: entityRef,\n path: contentPath,\n }),\n rewriteDocLinks(),\n addSidebarToggle(),\n removeMkdocsHeader(),\n simplifyMkdocsFooter(),\n addGitFeedbackLink(scmIntegrationsApi),\n stylesTransformer,\n ]),\n [\n // only add dependencies that are in state or memorized variables to avoid unnecessary calls between re-renders\n entityRef,\n scmIntegrationsApi,\n techdocsStorageApi,\n sanitizerTransformer,\n stylesTransformer,\n ],\n );\n\n // a function that performs transformations that are executed after adding it to the DOM\n const postRender = useCallback(\n async (transformedElement: Element) =>\n transformer(transformedElement, [\n handleMetaRedirects(navigate, entityRef.name),\n scrollIntoNavigation(),\n copyToClipboard(theme),\n addLinkClickListener({\n baseUrl: window.location.origin,\n onClick: (event: MouseEvent, url: string) => {\n // detect if CTRL or META keys are pressed so that links can be opened in a new tab with `window.open`\n const modifierActive = event.ctrlKey || event.metaKey;\n const parsedUrl = new URL(url);\n\n // capture link clicks within documentation\n const linkText =\n (event.target as HTMLAnchorElement | undefined)?.innerText || url;\n const to = url.replace(window.location.origin, '');\n analytics.captureEvent('click', linkText, { attributes: { to } });\n\n // hash exists when anchor is clicked on secondary sidebar\n if (parsedUrl.hash) {\n if (modifierActive) {\n window.open(url, '_blank');\n } else {\n navigate(url);\n // Scroll to hash if it's on the current page\n transformedElement\n ?.querySelector(`[id=\"${parsedUrl.hash.slice(1)}\"]`)\n ?.scrollIntoView();\n }\n } else {\n if (modifierActive) {\n window.open(url, '_blank');\n } else {\n navigate(url);\n }\n }\n },\n }),\n // disable MkDocs drawer toggling ('for' attribute => checkbox mechanism)\n onCssReady({\n onLoading: () => {},\n onLoaded: () => {\n transformedElement\n .querySelector('.md-nav__title')\n ?.removeAttribute('for');\n },\n }),\n // hide sidebars until their positions are updated\n onCssReady({\n onLoading: () => {\n const sidebars = Array.from(\n transformedElement.querySelectorAll<HTMLElement>('.md-sidebar'),\n );\n sidebars.forEach(element => {\n element.style.setProperty('opacity', '0');\n });\n },\n onLoaded: () => {},\n }),\n ]),\n [theme, navigate, analytics, entityRef.name],\n );\n\n useEffect(() => {\n if (!rawPage) return () => {};\n\n // if false, there is already a newer execution of this effect\n let shouldReplaceContent = true;\n\n // Pre-render\n preRender(rawPage, path).then(async preTransformedDomElement => {\n if (!preTransformedDomElement?.innerHTML) {\n return; // An unexpected error occurred\n }\n\n // don't manipulate the shadow dom if this isn't the latest effect execution\n if (!shouldReplaceContent) {\n return;\n }\n\n // Scroll to top after render\n window.scroll({ top: 0 });\n\n // Post-render\n const postTransformedDomElement = await postRender(\n preTransformedDomElement,\n );\n setDom(postTransformedDomElement as HTMLElement);\n });\n\n // cancel this execution\n return () => {\n shouldReplaceContent = false;\n };\n }, [rawPage, path, preRender, postRender]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AAA,CAAC,OAAS,EAAA,OAAO,MAAM;AAAA,KAAC,CAAA;AAG5B,IAAA,IAAI,oBAAuB,GAAA,IAAA,CAAA;AAG3B,IAAA,SAAA,CAAU,OAAS,EAAA,IAAI,CAAE,CAAA,IAAA,CAAK,OAAM,wBAA4B,KAAA;AAC9D,MAAI,IAAA,CAAC,0BAA0B,SAAW,EAAA;AACxC,QAAA,OAAA;AAAA,OACF;AAGA,MAAA,IAAI,CAAC,oBAAsB,EAAA;AACzB,QAAA,OAAA;AAAA,OACF;AAGA,MAAA,MAAA,CAAO,MAAO,CAAA,EAAE,GAAK,EAAA,CAAA,EAAG,CAAA,CAAA;AAGxB,MAAA,MAAM,4BAA4B,MAAM,UAAA;AAAA,QACtC,wBAAA;AAAA,OACF,CAAA;AACA,MAAA,MAAA,CAAO,yBAAwC,CAAA,CAAA;AAAA,KAChD,CAAA,CAAA;AAGD,IAAA,OAAO,MAAM;AACX,MAAuB,oBAAA,GAAA,KAAA,CAAA;AAAA,KACzB,CAAA;AAAA,KACC,CAAC,OAAA,EAAS,IAAM,EAAA,SAAA,EAAW,UAAU,CAAC,CAAA,CAAA;AAEzC,EAAO,OAAA,GAAA,CAAA;AACT;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { normalizeUrl } from './rewriteDocLinks.esm.js';
|
|
2
|
+
|
|
3
|
+
const handleMetaRedirects = (navigate, entityName) => {
|
|
4
|
+
return (dom) => {
|
|
5
|
+
for (const elem of Array.from(dom.querySelectorAll("meta"))) {
|
|
6
|
+
if (elem.getAttribute("http-equiv") === "refresh") {
|
|
7
|
+
const metaContentParameters = elem.getAttribute("content")?.split("url=");
|
|
8
|
+
if (!metaContentParameters || metaContentParameters.length < 2) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const metaUrl = metaContentParameters[1];
|
|
12
|
+
const normalizedCurrentUrl = normalizeUrl(window.location.href);
|
|
13
|
+
const absoluteRedirectObj = new URL(metaUrl, normalizedCurrentUrl);
|
|
14
|
+
const isExternalRedirect = absoluteRedirectObj.hostname !== window.location.hostname;
|
|
15
|
+
if (isExternalRedirect) {
|
|
16
|
+
const currentTechDocPath = window.location.pathname;
|
|
17
|
+
const indexOfSiteHome = currentTechDocPath.indexOf(entityName);
|
|
18
|
+
const siteHomePath = currentTechDocPath.slice(
|
|
19
|
+
0,
|
|
20
|
+
indexOfSiteHome + entityName.length
|
|
21
|
+
);
|
|
22
|
+
navigate(siteHomePath);
|
|
23
|
+
} else {
|
|
24
|
+
navigate(absoluteRedirectObj.href);
|
|
25
|
+
}
|
|
26
|
+
return dom;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return dom;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { handleMetaRedirects };
|
|
34
|
+
//# sourceMappingURL=handleMetaRedirects.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleMetaRedirects.esm.js","sources":["../../../src/reader/transformers/handleMetaRedirects.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Transformer } from './transformer';\nimport { normalizeUrl } from './rewriteDocLinks';\n\nexport const handleMetaRedirects = (\n navigate: (to: string) => void,\n entityName: string,\n): Transformer => {\n return dom => {\n for (const elem of Array.from(dom.querySelectorAll('meta'))) {\n if (elem.getAttribute('http-equiv') === 'refresh') {\n const metaContentParameters = elem\n .getAttribute('content')\n ?.split('url=');\n if (!metaContentParameters || metaContentParameters.length < 2) {\n continue;\n }\n\n const metaUrl = metaContentParameters[1];\n const normalizedCurrentUrl = normalizeUrl(window.location.href);\n // If metaUrl is relative, it will be resolved with base href. If it is absolute, it will replace the base href when creating URL object.\n const absoluteRedirectObj = new URL(metaUrl, normalizedCurrentUrl);\n const isExternalRedirect =\n absoluteRedirectObj.hostname !== window.location.hostname;\n\n if (isExternalRedirect) {\n // If the redirect is external, navigate to the documentation site home instead of the external url.\n const currentTechDocPath = window.location.pathname;\n const indexOfSiteHome = currentTechDocPath.indexOf(entityName);\n const siteHomePath = currentTechDocPath.slice(\n 0,\n indexOfSiteHome + entityName.length,\n );\n navigate(siteHomePath);\n } else {\n // The navigate function from dom.tsx is a wrapper around react-router navigate function that helps absolute url redirects.\n navigate(absoluteRedirectObj.href);\n }\n return dom;\n }\n }\n return dom;\n };\n};\n"],"names":[],"mappings":";;AAmBa,MAAA,mBAAA,GAAsB,CACjC,QAAA,EACA,UACgB,KAAA;AAChB,EAAA,OAAO,CAAO,GAAA,KAAA;AACZ,IAAA,KAAA,MAAW,QAAQ,KAAM,CAAA,IAAA,CAAK,IAAI,gBAAiB,CAAA,MAAM,CAAC,CAAG,EAAA;AAC3D,MAAA,IAAI,IAAK,CAAA,YAAA,CAAa,YAAY,CAAA,KAAM,SAAW,EAAA;AACjD,QAAA,MAAM,wBAAwB,IAC3B,CAAA,YAAA,CAAa,SAAS,CAAA,EACrB,MAAM,MAAM,CAAA,CAAA;AAChB,QAAA,IAAI,CAAC,qBAAA,IAAyB,qBAAsB,CAAA,MAAA,GAAS,CAAG,EAAA;AAC9D,UAAA,SAAA;AAAA,SACF;AAEA,QAAM,MAAA,OAAA,GAAU,sBAAsB,CAAC,CAAA,CAAA;AACvC,QAAA,MAAM,oBAAuB,GAAA,YAAA,CAAa,MAAO,CAAA,QAAA,CAAS,IAAI,CAAA,CAAA;AAE9D,QAAA,MAAM,mBAAsB,GAAA,IAAI,GAAI,CAAA,OAAA,EAAS,oBAAoB,CAAA,CAAA;AACjE,QAAA,MAAM,kBACJ,GAAA,mBAAA,CAAoB,QAAa,KAAA,MAAA,CAAO,QAAS,CAAA,QAAA,CAAA;AAEnD,QAAA,IAAI,kBAAoB,EAAA;AAEtB,UAAM,MAAA,kBAAA,GAAqB,OAAO,QAAS,CAAA,QAAA,CAAA;AAC3C,UAAM,MAAA,eAAA,GAAkB,kBAAmB,CAAA,OAAA,CAAQ,UAAU,CAAA,CAAA;AAC7D,UAAA,MAAM,eAAe,kBAAmB,CAAA,KAAA;AAAA,YACtC,CAAA;AAAA,YACA,kBAAkB,UAAW,CAAA,MAAA;AAAA,WAC/B,CAAA;AACA,UAAA,QAAA,CAAS,YAAY,CAAA,CAAA;AAAA,SAChB,MAAA;AAEL,UAAA,QAAA,CAAS,oBAAoB,IAAI,CAAA,CAAA;AAAA,SACnC;AACA,QAAO,OAAA,GAAA,CAAA;AAAA,OACT;AAAA,KACF;AACA,IAAO,OAAA,GAAA,CAAA;AAAA,GACT,CAAA;AACF;;;;"}
|
|
@@ -16,14 +16,30 @@ const useSanitizerTransformer = () => {
|
|
|
16
16
|
async (dom) => {
|
|
17
17
|
const hosts = config?.getOptionalStringArray("allowedIframeHosts");
|
|
18
18
|
DOMPurify.addHook("beforeSanitizeElements", removeUnsafeLinks);
|
|
19
|
-
const tags = ["link"];
|
|
19
|
+
const tags = ["link", "meta"];
|
|
20
20
|
if (hosts) {
|
|
21
21
|
tags.push("iframe");
|
|
22
22
|
DOMPurify.addHook("beforeSanitizeElements", removeUnsafeIframes(hosts));
|
|
23
23
|
}
|
|
24
|
+
DOMPurify.addHook("uponSanitizeElement", (currNode, data) => {
|
|
25
|
+
if (data.tagName === "meta") {
|
|
26
|
+
const isMetaRefreshTag = currNode.getAttribute("http-equiv") === "refresh" && currNode.getAttribute("content")?.includes("url=");
|
|
27
|
+
if (!isMetaRefreshTag) {
|
|
28
|
+
currNode.parentNode?.removeChild(currNode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
DOMPurify.addHook("uponSanitizeAttribute", (currNode, data) => {
|
|
33
|
+
if (currNode.tagName !== "meta") {
|
|
34
|
+
if (data.attrName === "http-equiv" || data.attrName === "content") {
|
|
35
|
+
currNode.removeAttribute(data.attrName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
24
39
|
return DOMPurify.sanitize(dom.outerHTML, {
|
|
25
40
|
ADD_TAGS: tags,
|
|
26
41
|
FORBID_TAGS: ["style"],
|
|
42
|
+
ADD_ATTR: ["http-equiv", "content"],
|
|
27
43
|
WHOLE_DOCUMENT: true,
|
|
28
44
|
RETURN_DOM: true
|
|
29
45
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.esm.js","sources":["../../../../src/reader/transformers/html/transformer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport DOMPurify from 'dompurify';\nimport { useCallback, useMemo } from 'react';\n\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { Transformer } from '../transformer';\nimport { removeUnsafeIframes, removeUnsafeLinks } from './hooks';\n\n/**\n * Returns html sanitizer configuration\n */\nconst useSanitizerConfig = () => {\n const configApi = useApi(configApiRef);\n\n return useMemo(() => {\n return configApi.getOptionalConfig('techdocs.sanitizer');\n }, [configApi]);\n};\n\n/**\n * Returns a transformer that sanitizes the dom\n */\nexport const useSanitizerTransformer = (): Transformer => {\n const config = useSanitizerConfig();\n\n return useCallback(\n async (dom: Element) => {\n const hosts = config?.getOptionalStringArray('allowedIframeHosts');\n\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeLinks);\n const tags = ['link'];\n\n if (hosts) {\n tags.push('iframe');\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeIframes(hosts));\n }\n\n // using outerHTML as we want to preserve the html tag attributes (lang)\n return DOMPurify.sanitize(dom.outerHTML, {\n ADD_TAGS: tags,\n FORBID_TAGS: ['style'],\n WHOLE_DOCUMENT: true,\n RETURN_DOM: true,\n });\n },\n [config],\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,qBAAqB,MAAM;AAC/B,EAAM,MAAA,SAAA,GAAY,OAAO,YAAY,CAAA,CAAA;AAErC,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAO,OAAA,SAAA,CAAU,kBAAkB,oBAAoB,CAAA,CAAA;AAAA,GACzD,EAAG,CAAC,SAAS,CAAC,CAAA,CAAA;AAChB,CAAA,CAAA;AAKO,MAAM,0BAA0B,MAAmB;AACxD,EAAA,MAAM,SAAS,kBAAmB,EAAA,CAAA;AAElC,EAAO,OAAA,WAAA;AAAA,IACL,OAAO,GAAiB,KAAA;AACtB,MAAM,MAAA,KAAA,GAAQ,MAAQ,EAAA,sBAAA,CAAuB,oBAAoB,CAAA,CAAA;AAEjE,MAAU,SAAA,CAAA,OAAA,CAAQ,0BAA0B,iBAAiB,CAAA,CAAA;AAC7D,MAAM,MAAA,IAAA,GAAO,CAAC,MAAM,CAAA,CAAA;
|
|
1
|
+
{"version":3,"file":"transformer.esm.js","sources":["../../../../src/reader/transformers/html/transformer.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport DOMPurify from 'dompurify';\nimport { useCallback, useMemo } from 'react';\n\nimport { configApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { Transformer } from '../transformer';\nimport { removeUnsafeIframes, removeUnsafeLinks } from './hooks';\n\n/**\n * Returns html sanitizer configuration\n */\nconst useSanitizerConfig = () => {\n const configApi = useApi(configApiRef);\n\n return useMemo(() => {\n return configApi.getOptionalConfig('techdocs.sanitizer');\n }, [configApi]);\n};\n\n/**\n * Returns a transformer that sanitizes the dom\n */\nexport const useSanitizerTransformer = (): Transformer => {\n const config = useSanitizerConfig();\n\n return useCallback(\n async (dom: Element) => {\n const hosts = config?.getOptionalStringArray('allowedIframeHosts');\n\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeLinks);\n const tags = ['link', 'meta'];\n\n if (hosts) {\n tags.push('iframe');\n DOMPurify.addHook('beforeSanitizeElements', removeUnsafeIframes(hosts));\n }\n\n // Only allow meta tags if they are used for refreshing the page. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeElement', (currNode, data) => {\n if (data.tagName === 'meta') {\n const isMetaRefreshTag =\n currNode.getAttribute('http-equiv') === 'refresh' &&\n currNode.getAttribute('content')?.includes('url=');\n if (!isMetaRefreshTag) {\n currNode.parentNode?.removeChild(currNode);\n }\n }\n });\n\n // Only allow http-equiv and content attributes on meta tags. They are required for the redirect feature.\n DOMPurify.addHook('uponSanitizeAttribute', (currNode, data) => {\n if (currNode.tagName !== 'meta') {\n if (data.attrName === 'http-equiv' || data.attrName === 'content') {\n currNode.removeAttribute(data.attrName);\n }\n }\n });\n\n // using outerHTML as we want to preserve the html tag attributes (lang)\n return DOMPurify.sanitize(dom.outerHTML, {\n ADD_TAGS: tags,\n FORBID_TAGS: ['style'],\n ADD_ATTR: ['http-equiv', 'content'],\n WHOLE_DOCUMENT: true,\n RETURN_DOM: true,\n });\n },\n [config],\n );\n};\n"],"names":[],"mappings":";;;;;;AA2BA,MAAM,qBAAqB,MAAM;AAC/B,EAAM,MAAA,SAAA,GAAY,OAAO,YAAY,CAAA,CA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S,YAAY,MAAQ,EAAA;AAC/B,UAAA,IAAI,IAAK,CAAA,QAAA,KAAa,YAAgB,IAAA,IAAA,CAAK,aAAa,SAAW,EAAA;AACjE,YAAS,QAAA,CAAA,eAAA,CAAgB,KAAK,QAAQ,CAAA,CAAA;AAAA,WACxC;AAAA,SACF;AAAA,OACD,CAAA,CAAA;AAGD,MAAO,OAAA,SAAA,CAAU,QAAS,CAAA,GAAA,CAAI,SAAW,EAAA;AAAA,QACvC,QAAU,EAAA,IAAA;AAAA,QACV,WAAA,EAAa,CAAC,OAAO,CAAA;AAAA,QACrB,QAAA,EAAU,CAAC,YAAA,EAAc,SAAS,CAAA;AAAA,QAClC,cAAgB,EAAA,IAAA;AAAA,QAChB,UAAY,EAAA,IAAA;AAAA,OACb,CAAA,CAAA;AAAA,KACH;AAAA,IACA,CAAC,MAAM,CAAA;AAAA,GACT,CAAA;AACF;;;;"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const headings = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
2
|
+
const relativeLengthUnit = /(em)|(rem)/gi;
|
|
3
|
+
const cssVariable = /var\(|\)/gi;
|
|
2
4
|
var typeset = ({ theme }) => `
|
|
3
5
|
/*================== Typeset ==================*/
|
|
4
6
|
|
|
@@ -11,14 +13,20 @@ ${headings.reduce((style, heading) => {
|
|
|
11
13
|
const styles = theme.typography[heading];
|
|
12
14
|
const { lineHeight, fontFamily, fontWeight, fontSize } = styles;
|
|
13
15
|
const calculate = (value) => {
|
|
14
|
-
let factor = 1;
|
|
15
16
|
if (typeof value === "number") {
|
|
16
|
-
|
|
17
|
+
return calculate(`${value / htmlFontSize * 0.6}rem`);
|
|
18
|
+
} else if (typeof value === "string") {
|
|
19
|
+
if (value.match(cssVariable)) {
|
|
20
|
+
const resolvedValue = window.getComputedStyle(document.body).getPropertyValue(value.replaceAll(cssVariable, ""));
|
|
21
|
+
if (resolvedValue !== "") {
|
|
22
|
+
return calculate(resolvedValue);
|
|
23
|
+
}
|
|
24
|
+
} else if (value.match(relativeLengthUnit)) {
|
|
25
|
+
const factor = value.replace(relativeLengthUnit, "");
|
|
26
|
+
return `calc(${factor} * var(--md-typeset-font-size))`;
|
|
27
|
+
}
|
|
17
28
|
}
|
|
18
|
-
|
|
19
|
-
factor = value.replace("rem", "");
|
|
20
|
-
}
|
|
21
|
-
return `calc(${factor} * var(--md-typeset-font-size))`;
|
|
29
|
+
return value;
|
|
22
30
|
};
|
|
23
31
|
return style.concat(`
|
|
24
32
|
.md-typeset ${heading} {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeset.esm.js","sources":["../../../../../src/reader/transformers/styles/rules/typeset.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RuleOptions } from './types';\n\ntype RuleTypography = RuleOptions['theme']['typography'];\n\ntype BackstageTypography = RuleTypography & {\n htmlFontSize?: number;\n};\n\ntype TypographyHeadings = Pick<\n RuleTypography,\n 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n>;\n\ntype TypographyHeadingsKeys = keyof TypographyHeadings;\n\nconst headings: TypographyHeadingsKeys[] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];\n\nexport default ({ theme }: RuleOptions) => `\n/*================== Typeset ==================*/\n\n.md-typeset {\n font-size: var(--md-typeset-font-size);\n}\n\n${headings.reduce<string>((style, heading) => {\n const htmlFontSize =\n (theme.typography as BackstageTypography).htmlFontSize ?? 16;\n const styles = theme.typography[heading];\n const { lineHeight, fontFamily, fontWeight, fontSize } = styles;\n const calculate = (value: typeof fontSize)
|
|
1
|
+
{"version":3,"file":"typeset.esm.js","sources":["../../../../../src/reader/transformers/styles/rules/typeset.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { RuleOptions } from './types';\n\ntype RuleTypography = RuleOptions['theme']['typography'];\n\ntype BackstageTypography = RuleTypography & {\n htmlFontSize?: number;\n};\n\ntype TypographyHeadings = Pick<\n RuleTypography,\n 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n>;\n\ntype TypographyHeadingsKeys = keyof TypographyHeadings;\n\nconst headings: TypographyHeadingsKeys[] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];\nconst relativeLengthUnit: RegExp = /(em)|(rem)/gi;\nconst cssVariable: RegExp = /var\\(|\\)/gi;\n\nexport default ({ theme }: RuleOptions) => `\n/*================== Typeset ==================*/\n\n.md-typeset {\n font-size: var(--md-typeset-font-size);\n}\n\n${headings.reduce<string>((style, heading) => {\n const htmlFontSize =\n (theme.typography as BackstageTypography).htmlFontSize ?? 16;\n const styles = theme.typography[heading];\n const { lineHeight, fontFamily, fontWeight, fontSize } = styles;\n const calculate = (value: typeof fontSize): string | undefined => {\n if (typeof value === 'number') {\n // Convert px to rem and apply 60% factor\n return calculate(`${(value / htmlFontSize) * 0.6}rem`);\n } else if (typeof value === 'string') {\n if (value.match(cssVariable)) {\n // Resolve css variable and calculate recursively\n const resolvedValue = window\n .getComputedStyle(document.body)\n .getPropertyValue(value.replaceAll(cssVariable, ''));\n if (resolvedValue !== '') {\n return calculate(resolvedValue);\n }\n } else if (value.match(relativeLengthUnit)) {\n // Use relative size as factor\n const factor = value.replace(relativeLengthUnit, '');\n return `calc(${factor} * var(--md-typeset-font-size))`;\n }\n }\n // Value is not a number, relative length unit, or CSS variable, return as is\n return value;\n };\n return style.concat(`\n .md-typeset ${heading} {\n color: var(--md-default-fg-color);\n line-height: ${lineHeight};\n font-family: ${fontFamily};\n font-weight: ${fontWeight};\n font-size: ${calculate(fontSize)};\n }\n `);\n}, '')}\n\n.md-typeset .md-content__button {\n color: var(--md-default-fg-color);\n}\n\n.md-typeset hr {\n border-bottom: 0.05rem dotted ${theme.palette.divider};\n}\n\n.md-typeset details {\n font-size: var(--md-typeset-font-size) !important;\n}\n.md-typeset details summary {\n padding-left: 2.5rem !important;\n}\n.md-typeset details summary:before,\n.md-typeset details summary:after {\n top: 50% !important;\n width: 20px !important;\n height: 20px !important;\n transform: rotate(0deg) translateY(-50%) !important;\n}\n.md-typeset details[open] > summary:after {\n transform: rotate(90deg) translateX(-50%) !important;\n}\n\n.md-typeset blockquote {\n color: var(--md-default-fg-color--light);\n border-left: 0.2rem solid var(--md-default-fg-color--light);\n}\n\n.md-typeset table:not([class]) {\n font-size: var(--md-typeset-font-size);\n border: 1px solid var(--md-default-fg-color);\n border-bottom: none;\n border-collapse: collapse;\n}\n.md-typeset table:not([class]) th {\n font-weight: bold;\n}\n.md-typeset table:not([class]) td, .md-typeset table:not([class]) th {\n border-bottom: 1px solid var(--md-default-fg-color);\n}\n\n.md-typeset pre > code::-webkit-scrollbar-thumb {\n background-color: hsla(0, 0%, 0%, 0.32);\n}\n.md-typeset pre > code::-webkit-scrollbar-thumb:hover {\n background-color: hsla(0, 0%, 0%, 0.87);\n}\n\n.md-typeset code {\n word-break: keep-all;\n}\n`;\n"],"names":[],"mappings":"AA+BA,MAAM,WAAqC,CAAC,IAAA,EAAM,MAAM,IAAM,EAAA,IAAA,EAAM,MAAM,IAAI,CAAA,CAAA;AAC9E,MAAM,kBAA6B,GAAA,cAAA,CAAA;AAC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AAEA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT,CAAA;AACA,EAAA,OAAO,MAAM,MAAO,CAAA,CAAA;AAAA,gBAAA,EACJ,OAAO,CAAA;AAAA;AAAA,mBAAA,EAEJ,UAAU,CAAA;AAAA,mBAAA,EACV,UAAU,CAAA;AAAA,mBAAA,EACV,UAAU,CAAA;AAAA,iBACZ,EAAA,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA;AAAA,EAEnC,CAAA,CAAA,CAAA;AACH,CAAA,EAAG,EAAE,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAO4B,EAAA,KAAA,CAAM,QAAQ,OAAO,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-techdocs",
|
|
3
|
-
"version": "1.10.8-next.
|
|
3
|
+
"version": "1.10.8-next.2",
|
|
4
4
|
"description": "The Backstage plugin that renders technical documentation for your components",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "frontend-plugin",
|
|
@@ -60,17 +60,17 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@backstage/catalog-model": "^1.5.0",
|
|
62
62
|
"@backstage/config": "^1.2.0",
|
|
63
|
-
"@backstage/core-compat-api": "^0.2.8-next.
|
|
63
|
+
"@backstage/core-compat-api": "^0.2.8-next.2",
|
|
64
64
|
"@backstage/core-components": "^0.14.10-next.0",
|
|
65
65
|
"@backstage/core-plugin-api": "^1.9.3",
|
|
66
66
|
"@backstage/errors": "^1.2.4",
|
|
67
|
-
"@backstage/frontend-plugin-api": "^0.
|
|
67
|
+
"@backstage/frontend-plugin-api": "^0.7.0-next.2",
|
|
68
68
|
"@backstage/integration": "^1.14.0-next.0",
|
|
69
69
|
"@backstage/integration-react": "^1.1.30-next.0",
|
|
70
70
|
"@backstage/plugin-auth-react": "^0.1.5-next.0",
|
|
71
|
-
"@backstage/plugin-catalog-react": "^1.12.3-next.
|
|
72
|
-
"@backstage/plugin-search-common": "^1.2.14-next.
|
|
73
|
-
"@backstage/plugin-search-react": "^1.7.14-next.
|
|
71
|
+
"@backstage/plugin-catalog-react": "^1.12.3-next.2",
|
|
72
|
+
"@backstage/plugin-search-common": "^1.2.14-next.1",
|
|
73
|
+
"@backstage/plugin-search-react": "^1.7.14-next.2",
|
|
74
74
|
"@backstage/plugin-techdocs-common": "^0.1.0-next.0",
|
|
75
75
|
"@backstage/plugin-techdocs-react": "^1.2.7-next.0",
|
|
76
76
|
"@backstage/theme": "^0.5.6",
|
|
@@ -88,11 +88,11 @@
|
|
|
88
88
|
"react-use": "^17.2.4"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@backstage/cli": "^0.27.0-next.
|
|
91
|
+
"@backstage/cli": "^0.27.0-next.3",
|
|
92
92
|
"@backstage/core-app-api": "^1.14.2-next.0",
|
|
93
|
-
"@backstage/dev-utils": "^1.0.37-next.
|
|
93
|
+
"@backstage/dev-utils": "^1.0.37-next.2",
|
|
94
94
|
"@backstage/plugin-techdocs-module-addons-contrib": "^1.1.13-next.0",
|
|
95
|
-
"@backstage/test-utils": "^1.5.10-next.
|
|
95
|
+
"@backstage/test-utils": "^1.5.10-next.2",
|
|
96
96
|
"@testing-library/dom": "^10.0.0",
|
|
97
97
|
"@testing-library/jest-dom": "^6.0.0",
|
|
98
98
|
"@testing-library/react": "^15.0.0",
|