-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node/node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
}()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"escape-html": "^1.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |