Skip to content

Commit

Permalink
FIx for copy RTF with plain text format
Browse files Browse the repository at this point in the history
  • Loading branch information
iandrosov committed Dec 26, 2023
1 parent 5585984 commit d9b178a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3 slot="title" >
</template>

<!-- Display Illustration NO Data showCard = FALSE -->
<template if:false={showCard}></templateif:true>
<template if:false={showCard}>
<lightning-quick-action-panel header={displayTitle}>
<div>
<div class="slds-illustration slds-illustration_small">
Expand Down
8 changes: 5 additions & 3 deletions force-app/main/default/lwc/ggwSection/ggwSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ export default class GgwSection extends LightningElement {
});
this.dispatchEvent(evt);
}

convertToPlainText(rtf) {
let newLine = rtf.replace(/(?:<br>|<li>|<p>)/g,'\r\n');
return newLine.replace( /(<([^>]+)>)/ig, '');
}
copyText(){
let tempText = this.textBlock.replace( /(<([^>]+)>)/ig, '');

let tempText = this.convertToPlainText(this.textBlock);
navigator.clipboard.writeText(tempText).then(
() => {
this.showToastSuccess(`Data copied to clipboard`);
Expand Down
7 changes: 6 additions & 1 deletion force-app/main/default/pages/GGW_GrantPreview.page
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@
</apex:repeat>

<script type="text/javascript">
function convertToPlainText(rtf) {
let newLine = rtf.replace(/(?:<br>|<li>|<p>)/g,'\r\n');
return newLine.replace( /(<([^>]+)>)/ig, '');
}

function copyContent(itemId) {
let text = document.getElementById(itemId).innerHTML;
//console.log(`### ${text}`);

try {
let tempText = text.replace( /(<([^>]+)>)/ig, ''); // clear all HTML rich tags
let tempText = convertToPlainText(text); // clear all HTML rich tags
copyTextToClipboard(tempText);
console.log('Content copied to clipboard');
} catch (err) {
Expand Down

0 comments on commit d9b178a

Please sign in to comment.