Skip to content

Commit

Permalink
chore: do not use portal for markdown copy button #2025
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-mihok committed Aug 28, 2023
1 parent 6094402 commit af34fb7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ui/src/markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ const highlightSyntax = async (str: S, language: S, codeBlockId: S) => {
const highlightedCode = language
? hljs.highlight(str, { language, ignoreIllegals: true }).value
: hljs.highlightAuto(str).value
codeBlock.outerHTML = `<code id="${codeBlockId}" class="hljs" style="position:relative;">${highlightedCode}</code>`
const buttonContainerId = `cpb-${codeBlockId}`
codeBlock.outerHTML = `<code id="${codeBlockId}" class="hljs" style="position:relative;">${highlightedCode}<span id="${buttonContainerId}"/></code>`

const cb = document.getElementById(codeBlockId)
if (cb) ReactDOM.render(<ClipboardCopyButton value={str} anchorElement={cb} showOnHoverOnly portal />, document.createElement('div'))
if (cb) ReactDOM.render(<ClipboardCopyButton value={str} anchorElement={cb} showOnHoverOnly />, document.getElementById(buttonContainerId))
}

export const
Expand Down

0 comments on commit af34fb7

Please sign in to comment.