Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aqeelat committed Sep 28, 2020
1 parent ed6d8f4 commit 60eff6a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node/node_modules
.DS_Store
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# brackets-escaper
A brackets plugin to escape characters for safe html handling
# Escape HTML

49 changes: 49 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */

/** Simple extension that adds a "File > Hello World" menu item */
define(function (require, exports, module) {
"use strict";


var CommandManager = brackets.getModule("command/CommandManager"),
NodeDomain = brackets.getModule("utils/NodeDomain"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Menus = brackets.getModule("command/Menus"),
EditorManager = brackets.getModule('editor/EditorManager');


var escape = new NodeDomain("escape-html", ExtensionUtils.getModulePath(module, "node/escapeHtmlDomain"));

// Function to run when the menu item is clicked

function handleEscaping() {
let editor = EditorManager.getFocusedEditor();
let selections = editor.getSelections();

selections.forEach((selection)=>{
let text = editor.document.getRange(selection.start, selection.end);
if (!text || !text.length) return;
escape.exec("escapeHtml", text).done((result) => {
text = result;
console.log(text);
editor.document.replaceRange(text, selection.start, selection.end);
});

});
}


// First, register a command - a UI-less object associating an id to a handler
var MY_COMMAND_ID = "aqeelat.escaper"; // package-style naming to avoid collisions
CommandManager.register("Escaper", MY_COMMAND_ID, handleEscaping);

// Then create a menu item bound to the command
// The label of the menu item is the name we gave the command (see above)
var menu = Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
menu.addMenuItem(MY_COMMAND_ID);

// We could also add a key binding at the same time:
//menu.addMenuItem(MY_COMMAND_ID, "Ctrl-Alt-W");
// (Note: "Ctrl" is automatically mapped to "Cmd" on Mac)
});
45 changes: 45 additions & 0 deletions node/escapeHtmlDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4,
maxerr: 50, node: true */
/*global */

(function () {
"use strict";

var escapeHtml = require('escape-html');

// /**
// * @private
// * Handler function for the simple.getMemory command.
// * @param {string} text If true, return total memory; if false, return free memory only.
// * @return {steing} The amount of memory.
// */
// function escapeHtml(text) {
// return escape(text);
// }

/**
* Initializes the test domain with several test commands.
* @param {DomainManager} domainManager The DomainManager for the server
*/
function init(domainManager) {
if (!domainManager.hasDomain("escape-html")) {
domainManager.registerDomain("escape-html", {major: 1, minor: 0});
}
domainManager.registerCommand(
"escape-html", // domain name
"escapeHtml", // command name
escapeHtml, // command handler function
true, // this command is synchronous in Node
"Escapes HTML characters.",
[{name: "text", // parameters
type: "string",
description: "The text to be escape."}],
[{name: "text", // return values
type: "string",
description: "The escaped text."}]
);
}

exports.init = init;

}());
11 changes: 11 additions & 0 deletions node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"escape-html": "^1.0.3"
}
}
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "aqeelat.escape-html",
"title": "Escape HTML",
"description": "Excapes selected strings",
"homepage": "https://github.com/AqeelAT/BracketsEscapeHtml",
"version": "1.0.0",
"author": "Abdullah Alaqeel <a@aqeelat.com> (http://aqeelat.com)",
"license": "MIT",
"engines": {
"brackets": ">=1.14.2"
}
}

0 comments on commit 60eff6a

Please sign in to comment.