Skip to content
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

Added a download button #2312

Merged
merged 7 commits into from
Sep 15, 2024
Merged

Added a download button #2312

merged 7 commits into from
Sep 15, 2024

Conversation

ozearkhan
Copy link
Contributor

Description

Summary

This pull request introduces a new feature to the js-beautify project: a "Download Code" button that allows users to download the beautified code in the format they choose (HTML, CSS, or JS).

Fixes Issue:

Changes Made

  1. Added Download Button to index.html

    • A new button labeled "Download Beautified Code" has been added to the HTML.
    • Clicking this button triggers the downloadBeautifiedCode function.
  2. Implemented downloadBeautifiedCode Function

    • Added a function in web/common-function.js to handle the download functionality.
    • The function generates a Blob from the beautified code and initiates a download with a filename based on the selected language.

Detailed Description

index.html

  • New Button Added:
    <button class="control" type="button" onclick="downloadBeautifiedCode()"><strong>Download Beautified Code</strong></button>

web/common-function.js

  • New Function: downloadBeautifiedCode
    function downloadBeautifiedCode() {
      var output = the.lastOutput; // The beautified code
      var language = $('#language').val();
      var filename = 'beautified_code.' + (language === 'html' ? 'html' : language === 'css' ? 'css' : 'js');
      
      var blob = new Blob([output], { type: 'text/' + (language === 'html' ? 'html' : language) });
      var link = document.createElement('a');
      link.href = URL.createObjectURL(blob);
      link.download = filename;
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link);
    }

Testing

  • Manual Testing:
    • Verified that the "Download Beautified Code" button appears and functions correctly.
    • Ensured that clicking the button downloads the beautified code in the correct format and with the correct filename.

Additional Information

  • Screenshots:

Screenshot 2024-09-11 131114

Screenshot 2024-09-11 131140

  • Related Issues:
    • No issues found.

@ozearkhan
Copy link
Contributor Author

@bitwiseman sir this PR is ready for review.

js/bin/js-beautify.js Outdated Show resolved Hide resolved
web/common-function.js Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
@ozearkhan
Copy link
Contributor Author

ozearkhan commented Sep 12, 2024

Could you please let me know if any further changes are needed? If not, could you specify the conditions required for merging? This is my first PR, so I would really appreciate any feedback.

web/common-function.js Outdated Show resolved Hide resolved
@bitwiseman bitwiseman merged commit 1ff8cce into beautifier:main Sep 15, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants