|
|
|
@ -7,7 +7,7 @@ export default function initializePrism() {
|
|
|
|
'remove-trailing': true,
|
|
|
|
'remove-trailing': true,
|
|
|
|
'remove-indent': true,
|
|
|
|
'remove-indent': true,
|
|
|
|
'left-trim': true,
|
|
|
|
'left-trim': true,
|
|
|
|
'right-trim': true,
|
|
|
|
//'right-trim': true,
|
|
|
|
'remove-initial-line-feed': true,
|
|
|
|
'remove-initial-line-feed': true,
|
|
|
|
'tabs-to-spaces': 2
|
|
|
|
'tabs-to-spaces': 2
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -55,16 +55,30 @@ function expandButton() {
|
|
|
|
Prism.plugins.toolbar.registerButton('expand', env => {
|
|
|
|
Prism.plugins.toolbar.registerButton('expand', env => {
|
|
|
|
let expanded = false
|
|
|
|
let expanded = false
|
|
|
|
const codeBlock = env.element.closest('.code-toolbar')
|
|
|
|
const codeBlock = env.element.closest('.code-toolbar')
|
|
|
|
const container = env.element.closest('.page-col-content.ty-max-width')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const applyInlineStyles = (marginLeft, width) => {
|
|
|
|
const getExpandedStyle = () => {
|
|
|
|
|
|
|
|
const contentWrapper = env.element.closest('.ty-content-wrapper')
|
|
|
|
|
|
|
|
const content = env.element.closest('.page-col-content')
|
|
|
|
|
|
|
|
const innerContent = env.element.closest('.contents')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const contentMargin = contentWrapper.offsetWidth - content.offsetWidth
|
|
|
|
|
|
|
|
const contentPadding = content.offsetWidth - innerContent.offsetWidth
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
width: `${contentWrapper.offsetWidth - contentPadding}px`,
|
|
|
|
|
|
|
|
marginLeft: `-${(contentMargin) / 2}px`,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateInlineStyle = () => {
|
|
|
|
codeBlock.style.width = `${codeBlock.closest('.contents').offsetWidth}px`
|
|
|
|
codeBlock.style.width = `${codeBlock.closest('.contents').offsetWidth}px`
|
|
|
|
codeBlock.style.marginLeft = '0px'
|
|
|
|
codeBlock.style.marginLeft = '0px'
|
|
|
|
|
|
|
|
|
|
|
|
if (expanded) {
|
|
|
|
if (expanded) {
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
window.requestAnimationFrame(() => {
|
|
|
|
codeBlock.style.marginLeft = `${marginLeft}px`
|
|
|
|
const style = getExpandedStyle()
|
|
|
|
codeBlock.style.width = `${width}px`
|
|
|
|
codeBlock.style.marginLeft = style.marginLeft
|
|
|
|
|
|
|
|
codeBlock.style.width = style.width
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
@ -73,25 +87,13 @@ function expandButton() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const recalculateWidth = () => {
|
|
|
|
|
|
|
|
const containerMargin = parseFloat(window.getComputedStyle(container).marginLeft)
|
|
|
|
|
|
|
|
const containerPadding = parseFloat(window.getComputedStyle(container).paddingLeft)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// compute expanded size
|
|
|
|
|
|
|
|
const expandedWidth = container.offsetWidth - containerPadding * 2 + containerMargin * 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// apply inline styles to code block
|
|
|
|
|
|
|
|
applyInlineStyles(-containerMargin, expandedWidth)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const expandButton = document.createElement('button')
|
|
|
|
const expandButton = document.createElement('button')
|
|
|
|
|
|
|
|
|
|
|
|
expandButton.innerHTML = expandIcon
|
|
|
|
expandButton.innerHTML = expandIcon
|
|
|
|
|
|
|
|
|
|
|
|
expandButton.addEventListener('click', () => {
|
|
|
|
expandButton.addEventListener('click', () => {
|
|
|
|
expanded = !expanded
|
|
|
|
expanded = !expanded
|
|
|
|
|
|
|
|
|
|
|
|
recalculateWidth()
|
|
|
|
updateInlineStyle()
|
|
|
|
|
|
|
|
|
|
|
|
// switch icon
|
|
|
|
// switch icon
|
|
|
|
expandButton.innerHTML = expanded ? collapseIcon : expandIcon
|
|
|
|
expandButton.innerHTML = expanded ? collapseIcon : expandIcon
|
|
|
|
@ -99,7 +101,7 @@ function expandButton() {
|
|
|
|
document.activeElement.blur()
|
|
|
|
document.activeElement.blur()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('resize', recalculateWidth)
|
|
|
|
window.addEventListener('resize', updateInlineStyle)
|
|
|
|
|
|
|
|
|
|
|
|
return expandButton
|
|
|
|
return expandButton
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|