Skip to content

Commit

Permalink
Merge pull request github#31061 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Jan 11, 2024
2 parents 841882d + 2de3af5 commit 8676fc5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/rest/components/RestCodeSamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ function getLanguageHighlight(selectedLanguage: string) {
return selectedLanguage === CodeSampleKeys.javascript ? 'javascript' : 'curl'
}

function highlightElement(element: HTMLElement) {
element.className = 'hljs'
// If the element was already highlighted, remove the dataset property
// otherwise the `hljs.highlightElement` function will not highlight.
delete element.dataset.highlighted
hljs.highlightElement(element)
}

export function RestCodeSamples({ operation, slug, heading }: Props) {
const { t } = useTranslation(['rest_reference'])
const { isEnterpriseServer } = useVersion()
Expand Down Expand Up @@ -147,8 +155,7 @@ export function RestCodeSamples({ operation, slug, heading }: Props) {
// intersection observer syntax highlighting
// (ClientSideHighlightJS) will have already handled highlighting
if (reqElem && !firstRender.current) {
reqElem.className = 'hljs'
hljs.highlightElement(reqElem)
highlightElement(reqElem)
handleResponseResize()
}
}, [selectedLanguage])
Expand All @@ -168,8 +175,7 @@ export function RestCodeSamples({ operation, slug, heading }: Props) {
// intersection observer syntax highlighting
// (ClientSideHighlightJS) will have already handled highlighting
if (reqElem && !firstRender.current) {
reqElem.className = 'hljs'
hljs.highlightElement(reqElem)
highlightElement(reqElem)
}
}, [selectedResponse])

Expand All @@ -178,14 +184,12 @@ export function RestCodeSamples({ operation, slug, heading }: Props) {
useEffect(() => {
const reqElem = requestCodeExample.current
if (reqElem) {
reqElem.className = 'hljs'
hljs.highlightElement(reqElem)
highlightElement(reqElem)
}

const resElem = responseCodeExample.current
if (resElem) {
resElem.className = 'hljs'
hljs.highlightElement(resElem)
highlightElement(resElem)
}
}, [selectedExample])

Expand Down

0 comments on commit 8676fc5

Please sign in to comment.