Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ClankDev committed Aug 21, 2023
1 parent eecaed6 commit eedfaf6
Showing 1 changed file with 49 additions and 36 deletions.
85 changes: 49 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ except Exception as e:
<br>
---------------------------------------------------------------------------------------
```
// Start test server (http-server)
// Save test javascript file as a module (.mjs)
// Import the rtfToTxt function from the rtf-converter npm package
import { rtfToTxt } from './node_modules/rtf-converter/rtf_converter.js';
Expand All @@ -135,6 +137,12 @@ console.log(plainText); // Output: Hello, World!
<br>
---------------------------------------------------------------------------------------
```
<!-- Start test server (http-server) -->
<!-- Save test javascript file as a module (.mjs) -->
<!-- TEST.HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -147,44 +155,49 @@ console.log(plainText); // Output: Hello, World!
<h1>RTF Converter</h1>
<input type="file" id="rtfFile" accept=".rtf" />
<button onclick="convertRTF()">Convert RTF to Text</button>
<script type="module">
// Import the rtfToTxt function from the rtf-converter package
import { rtfToTxt } from './node_modules/rtf-converter/rtf_converter.js';
// Function to handle the conversion process
function convertRTF() {
var fileInput = document.getElementById('rtfFile');
var file = fileInput.files[0];
if (!file) {
alert('Please select an RTF file to convert.');
return;
}
// Read the RTF content from the uploaded file
var reader = new FileReader();
reader.onload = function(event) {
var rtfContent = event.target.result;
// Convert RTF content to plain text using the rtfToTxt function
var plainText = rtfToTxt(rtfContent);
// Save plain text to a new file
var blob = new Blob([plainText], { type: 'text/plain' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'output.txt';
link.click();
console.log("RTF has been successfully converted to plain text and saved as output.txt.");
};
reader.readAsText(file);
}
// Make the convertRTF function globally accessible so that it can be called from the HTML file
window.convertRTF = convertRTF;
</script>
<script src="script.mjs" type="module"></script>
</body>
</html>
<!-- SCRIPT.MJS -->
// Import the rtfToTxt function from the rtf-converter npm package
import { rtfToTxt } from './node_modules/rtf-converter/rtf_converter.js';
// Function to handle the conversion process
function convertRTF() {
var fileInput = document.getElementById('rtfFile');
var file = fileInput.files[0];
if (!file) {
alert('Please select an RTF file to convert.');
return;
}
// Read the RTF content from the uploaded file
var reader = new FileReader();
reader.onload = function(event) {
var rtfContent = event.target.result;
// Convert RTF content to plain text using the rtfToTxt function
var plainText = rtfToTxt(rtfContent);
// Save plain text to a new file
var blob = new Blob([plainText], { type: 'text/plain' });
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'output.txt';
link.click();
console.log("RTF has been successfully converted to plain text and saved as output.txt.");
};
reader.readAsText(file);
}
// Make the convertRTF function globally accessible so that it can be called from the HTML file
window.convertRTF = convertRTF;
```
---------------------------------------------------------------------------------------

Expand Down

0 comments on commit eedfaf6

Please sign in to comment.