how to ignore system prompt symbols in codeblock on copy?
Posted: Fri Mar 01, 2024 12:14 pm
hi,
some of the readers asked us if it's possible to set a rule in the publishing template or include some js script to ignore system prompt symbols like $ > or # in code block on copy.
lots of sample scripts were provided by coders without splitting code and execution result. we hope the readers could read the result right after the script so they get to know what the expected results are. but when they copy the code sample, and paste them to client, they need to remove the result before clicking the run button.
so I used a js script for such purpose:
document.addEventListener('copy', function(e) {
const selection = window.getSelection();
const text = selection.toString().replace(/[$#>]+/g, ''); // Remove $, #, > symbols
// Oxygen XML Editor WebHelp requires using the 'copy' event on document.body
const copyEvent = new ClipboardEvent('copy', { dataType: 'text/plain', data: text });
document.body.dispatchEvent(copyEvent);
e.preventDefault();
});
and call this js file from an xml file which was specified for webhelp.fragment.after.search.input parameter in the opt file.
<script src='./oncopy.js' defer></script>
and test the script, nothing happens.
is it possible to have a parameter for the webhelp publishing template so that when copying codeblock from pages system prompt symbols can be ignored?
some of the readers asked us if it's possible to set a rule in the publishing template or include some js script to ignore system prompt symbols like $ > or # in code block on copy.
lots of sample scripts were provided by coders without splitting code and execution result. we hope the readers could read the result right after the script so they get to know what the expected results are. but when they copy the code sample, and paste them to client, they need to remove the result before clicking the run button.
so I used a js script for such purpose:
document.addEventListener('copy', function(e) {
const selection = window.getSelection();
const text = selection.toString().replace(/[$#>]+/g, ''); // Remove $, #, > symbols
// Oxygen XML Editor WebHelp requires using the 'copy' event on document.body
const copyEvent = new ClipboardEvent('copy', { dataType: 'text/plain', data: text });
document.body.dispatchEvent(copyEvent);
e.preventDefault();
});
and call this js file from an xml file which was specified for webhelp.fragment.after.search.input parameter in the opt file.
<script src='./oncopy.js' defer></script>
and test the script, nothing happens.
is it possible to have a parameter for the webhelp publishing template so that when copying codeblock from pages system prompt symbols can be ignored?