Trình làm đẹp Javascript văn bản tuyệt vời 3

Tôi vừa thấy một ghi chú nói rằng chỉnh sửa chạy. js, nhưng tôi không biết phải làm gì, có ai có thể chỉnh sửa mã cho tôi không?


/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at //mozilla.org/MPL/2.0/. */

[function[] {
  "use strict";

  // Cache the console log function and the process arguments.
  var log = console.log;
  var argv = process.argv;

  // Require path and file system utilities to load the jshint.js file.
  var path = require["path"];
  var fs = require["fs"];

  // The source file to be prettified, original source's path and some options.
  var tempPath = argv[2] || "";
  var filePath = argv[3] || "";
  var options = { html: {}, css: {}, js: {} };

  // This stuff does all the magic.
  var html_beautify = require[path.join[__dirname, "beautify-html.js"]].html_beautify;
  var js_beautify = require[path.join[__dirname, "beautify.js"]].js_beautify;
  var css_beautify = require[path.join[__dirname, "beautify-css.js"]].css_beautify;

  // Some handy utility functions.
  function isTrue[value] {
    return value == "true" || value == true;
  }
  function getUserHome[] {
    return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
  }
  function getOptions[file] {
    var data = fs.readFileSync[file, "utf8"];
    var comments = /[?:\/\*[?:\s\S]*?]\*\/]|[?:\/\/[?:.*]$]/gm;
    try {
      return JSON.parse[data.replace[comments, ""]];
    } catch [e] {
      return Object.create[null];
    }
  }
  function setOptions[file, optionsStore] {
    var obj = getOptions[file];
    for [var key in obj] {
      var value = obj[key];

      // Options are defined as an object for each format, with keys as prefs.
      if [key != "html" && key != "css" && key != "js"] {
        continue;
      }
      for [var pref in value] {
        // Special case "true" and "false" pref values as actually booleans.
        // This avoids common accidents in .jsbeautifyrc json files.
        if [value == "true" || value == "false"] {
          optionsStore[key][pref] = isTrue[value[pref]];
        } else {
          optionsStore[key][pref] = value[pref];
        }
      }
    }
  }

  var jsbeautifyrc = ".jsbeautifyrc";
  var pluginFolder = path.dirname[__dirname];
  var sourceFolder = path.dirname[filePath];
  var sourceParent = path.dirname[sourceFolder];
  var jsbeautifyrcPath;

  // Older versions of node has `existsSync` in the path module, not fs. Meh.
  fs.existsSync = fs.existsSync || path.existsSync;

  // Try and get some persistent options from the plugin folder.
  if [fs.existsSync[jsbeautifyrcPath = pluginFolder + path.sep + jsbeautifyrc]] {
    setOptions[jsbeautifyrcPath, options];
  }

  // When a JSBeautify config file exists in the same dir as the source file or
  // one dir above, then use this configuration to overwrite the default prefs.

  // Try and get more options from the source's folder.
  if [fs.existsSync[jsbeautifyrcPath = sourceFolder + path.sep + jsbeautifyrc]] {
    setOptions[jsbeautifyrcPath, options];
  }
  // ...or the parent folder.
  else if [fs.existsSync[jsbeautifyrcPath = sourceParent + path.sep + jsbeautifyrc]] {
    setOptions[jsbeautifyrcPath, options];
  }
  // ...or the user's home folder if everything else fails.
  else if [fs.existsSync[jsbeautifyrcPath = getUserHome[] + path.sep + jsbeautifyrc]] {
    setOptions[jsbeautifyrcPath, options];
  }

  function isHTML[path, data] {
    return path.match[/\.html?$/] ||
      path.match[/\.xhtml?$/] ||
      path.match[/\.xml$/] ||
      [path == "?" && data.match[/^\s* dòng > reindent] nên tôi đã thêm “reindent” vào chuỗi lệnh của mình [sau “htmlprettify”] mà tôi đã tổng hợp để làm sạch mã mà tôi nhận được từ 

[mã]nhập siêu phàm, sublime_plugin

Định dạng lại lớpHtml[sublime_plugin. WindowCommand].
def run[self].
# package dependancies: //github.com/SublimeText/TrailingSpaces - //github.com/victorporof/Sublime-HTMLPrettify
self. cửa sổ. run_command[“select_all”]
self. cửa sổ. run_command[“delete_trailing_spaces”]
self. cửa sổ. run_command[“delete_blank_lines”]
self. cửa sổ. run_command[“htmlprettify”]
self. cửa sổ. run_command[“reindent”]
self. cửa sổ. run_command[“invert_selection”][/code]
Tôi không biết những gì mình đã làm có đúng hay không, nhưng cách này phù hợp với tôi và tôi đã thêm một phím tắt cho thao tác trên. tập tin py.

{ "keys": "ctrl+alt+r"], "command": "reformat_html" }, // ReformatHtml.py

Tuy nhiên, lệnh “reindent” không thành công trên mã trong trường hợp nó chưa có dòng trả về cho thẻ mở và thẻ đóng. Vì vậy, nếu mã là

blahpictureaandtext

tất cả trên một dòng, lối tắt của tôi sẽ không cung cấp cho tôi những gì tôi muốn nên tôi vẫn sẽ gặp khó khăn với việc dành quá nhiều thời gian để xem và định dạng một số mã nhiều hơn mức tôi muốn

chỉnh sửa

Bỏ qua tất cả những gì tôi đã nói ở trên, tôi có thể xóa nhưng có lẽ tốt hơn nên giữ lại phòng trường hợp người khác có thể có ý tưởng tương tự để họ thấy rằng đó là một ý tưởng tồi khi làm những gì tôi đã làm

Sau khi tìm hiểu thêm, tôi phát hiện ra rằng việc thêm “html” vào danh sách các phần tử chưa được định dạng là nguồn gốc của vấn đề với các thẻ khác không được định dạng đúng

làm đẹp-html. js dòng 122 có thuộc tính extra_liners… vì vậy tôi đã sao chép dòng đó, nhận xét dòng gốc và xóa danh sách các thẻ từ bên trong dấu nháy đơn

Chủ Đề