-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
codeblock copy button copies the syntax name instead of just the code #1284
Comments
@TFWol Does this happen with KoboldAI only? If yes then check Repetition penalty and DRY. |
This has got nothing to do with rep pen. It's a UI behavior. @TFWol currently the copy button does not check for syntax and just copies the entirety of the contents of a code block. Some models generate labels and some do not, so it's hard to correctly match them all. For now i'd recommend manually ensuring that unwanted text is excluded. |
When there isn't a label, the element starts with a
✅ Successfully got userscript snippet working without any visible changes to the UI: (function() {
'use strict';
function modifyCopyCode() {
// Check if the function already exists to avoid conflicts
if (typeof copyMarkdownCode === 'function') {
const originalCopyMarkdownCode = copyMarkdownCode;
copyMarkdownCode = function(btn) {
const codeContainer = btn.parentElement.querySelector('pre code');
if (codeContainer) {
let codeText = codeContainer.innerText;
let codeLines = codeText.split('\n');
codeLines.shift(); // This gets the job done by removing the first line
let modifiedCodeText = codeLines.join('\n');
navigator.clipboard.writeText(modifiedCodeText);
}
}
} else {
console.error("copyMarkdownCode function not found. Make sure the script loads after the target page.");
}
}
// Call the modifyCopyCode function when the page loads
window.addEventListener('load', modifyCopyCode);
})(); |
@LostRuins Could you replace function copyMarkdownCode(btn)
{
const codeContainer = btn.parentElement.querySelector('pre code');
//selectElementContents(codeContainer);
navigator.clipboard.writeText(codeContainer.innerText);
} with: function copyMarkdownCode(btn)
{
const codeContainer = btn.parentElement.querySelector('pre code');
//selectElementContents(codeContainer);
if (codeContainer)
{
let codeText = codeContainer.innerText;
let codeLines = codeText.split('\n');
codeLines.shift(); // Remove the first line
let modifiedCodeText = codeLines.join('\n');
navigator.clipboard.writeText(modifiedCodeText);
}
} I'd do a pull request, but I'm not familiar with the warning on the file: |
Describe the Issue
If you have a named codeblock, like
batch
, it gets placed inside the code and ends up getting copied along with the code which can cause syntax errors if you aren't watching for it.It should be a label or something outside the box instead.
The text was updated successfully, but these errors were encountered: