Community
    • Login

    Is there any plug-in that can format HTML + JAVASCRIPT + CSS at the same time?

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 379 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Freya SmithF
      Freya Smith
      last edited by

      Excuse me

      1. Is there any plug-in that can format HTML + JAVASCRIPT + CSS at the same time?
      2. Or any plug-in for formatting HTML + CSS without JAVASCRIPT?

      Example code with JAVASCRIPT
      <original no formatting>

      <!DOCTYPE html>
      <html>
          <head>
              <meta charset="UTF-8">
              <title></title>
              <link href="sharetoapp.css" rel="stylesheet" type="text/css"/>
              <script src="sharetoapp.js" type="text/javascript" async=""></script>
      		
      		<style>
      		.share_wrap{
           display:block;
      }
      
      .a2a_hide{
          display:block;
      }
      .a2a_logo_color{
          background-color:#0166ff;
      }
      .a2a_menu,.a2a_menu *{
          -moz-box-sizing:content-box;
          -webkit-box-sizing:content-box;
          box-sizing:content-box;
          float:none;
          margin:0;
          padding:0;
          position:static;
          height:auto;
          width:auto
      }
      		</style>
          </head>
          <body>
              <article class="share_wrap">
                      <div page="113" class="a2a_kit a2a_kit_size_32 a2a_default_style" style="line-height: 32px;">
                   <div style="clear: both;"></div></div>
                      </article>
      		<script>
      		function goprev() {
          Search.searchPosition -= 1;
          if (Search.searchPosition < 0) {Search.searchPosition = Search.result.length - 1;
          }
          $(window).scrollTop(Search.result[Search.searchPosition][1] - 300);
          var _loc1 = Search.result[Search.searchPosition][2]
      window.objfocus = _loc1;
          _loc2 = $("body").css("color");
                      _loc1.css("color", "blue");
                             var delay = 1500;
          setTimeout(function () {
              _loc1.css("color", _loc2);}, delay);
                          $(".findindex").text((Search.searchPosition + 1) + "/" + Search.result.length);
      }
      		</script>
          </body>
      </html>
      

      <after formatting>

      <!DOCTYPE html>
      <html>
      
      <head>
          <meta charset="UTF-8">
          <title></title>
          <link href="sharetoapp.css" rel="stylesheet" type="text/css" />
          <script src="sharetoapp.js" type="text/javascript" async=""></script>
      
          <style>
              .share_wrap {
                  display: block;
              }
      
              .a2a_hide {
                  display: block;
              }
      
              .a2a_logo_color {
                  background-color: #0166ff;
              }
      
              .a2a_menu,
              .a2a_menu * {
                  -moz-box-sizing: content-box;
                  -webkit-box-sizing: content-box;
                  box-sizing: content-box;
                  float: none;
                  margin: 0;
                  padding: 0;
                  position: static;
                  height: auto;
                  width: auto
              }
          </style>
      </head>
      
      <body>
          <article class="share_wrap">
              <div page="113" class="a2a_kit a2a_kit_size_32 a2a_default_style" style="line-height: 32px;">
                  <div style="clear: both;"></div>
              </div>
          </article>
          <script>
              function goprev() {
                  Search.searchPosition -= 1;
                  if (Search.searchPosition < 0) {
                      Search.searchPosition = Search.result.length - 1;
                  }
                  $(window).scrollTop(Search.result[Search.searchPosition][1] - 300);
                  var _loc1 = Search.result[Search.searchPosition][2]
                  window.objfocus = _loc1;
                  _loc2 = $("body").css("color");
                  _loc1.css("color", "blue");
                  var delay = 1500;
                  setTimeout(function() {
                      _loc1.css("color", _loc2);
                  }, delay);
                  $(".findindex").text((Search.searchPosition + 1) + "/" + Search.result.length);
              }
          </script>
      </body>
      
      </html>
      
      1 Reply Last reply Reply Quote 0
      • Mark OlsonM
        Mark Olson
        last edited by

        @Freya-Smith
        Probably not. There is at least one plugin (XMLTools) that can format XML (and thus HTML), but that plugin does not understand CSS or JavaScript. There is also JSTool, a plugin that can format JavaScript, but it doesn’t understand HTML or CSS.

        So the best workflow I can think of to reformat HTML and JavaScript would be something like:

        1. Use XMLTools to reformat the HTML
        2. Use the regular expression (?s-i)<script[^<>]*>\K(?:(?!(?:<\w+|</script>)).)* to find script tag, and for each script tag:
          • Copy the selected text into a new tab
          • Use JSTool to reformat the text in that tab (this will make the JavaScript pretty
          • Select the reformatted JavaScript
          • Paste it back over the selected script tag

        Sadly JSTool is not smart enough to reformat selected text while ignoring text that isn’t selected, and given that the maintainer seems relatively uninterested in the plugin nowadays, I doubt that feature will ever be implemented. Thus, it doesn’t seem like there’s any way to efficiently reformat JavaScript+HTML in Notepad++, and that’s before even considering the CSS.

        To be honest, I don’t think Notepad++ is the best text editor for working with JavaScript/HTML/CSS in 2024 on Windows; I would probably use VSCode for a project in those languages, and save Notepad++ for working with things like CSV’s, log files, or JSON.

        1 Reply Last reply Reply Quote 2
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors