Skip to content

Commit d024e46

Browse files
committed
Some bugs were fixed. Added HTML Tag Strip
Some bugs were fixed. Added the ability to strip html tag.
1 parent 85d87b6 commit d024e46

File tree

14 files changed

+445
-155
lines changed

14 files changed

+445
-155
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Adobe Brackets developer tools extension.
1212
- Multi `Localization`
1313
- Remove Empty Lines
1414
- Remove Break Lines
15-
- Remove Leading New Lines
1615
- To Upper Case
1716
- To Lower Case
1817
- To Title Case
1918
- Html Encode
2019
- Html Docode
2120
- URL Encode
2221
- Url Decode
22+
- HTML Tag Strip
2323
- Trim
2424
- Left Trim
2525
- Right Trim
@@ -34,7 +34,7 @@ Adobe Brackets developer tools extension.
3434
#Usage
3535
All page or by selecting a specific area can use the features...
3636

37-
#Screenshot
37+
#Screencast
3838
Highlight Selection (click and ALT+F3)
3939
![Highlight Selection Sample](http://i58.tinypic.com/2hz1i87.gif)
4040

@@ -44,7 +44,7 @@ Highlight Selection (click and ALT+F3)
4444

4545
#Roadmap
4646
Planned features
47-
* Tools menu group items move to submenu. ![Trello #541](https://trello.com/c/EwLGRkYe/541-native-submenus)
47+
* Tools menu group items move to submenu. [Trello #541](https://trello.com/c/EwLGRkYe/541-native-submenus)
4848
* More string tools
4949
* Color detect and lighten/darken value
5050
* Ctrl+click search on google

htmlContent/input.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<div class="my-extension-dialog modal">
1+
<div class="insya_modal_input modal">
22
<div class="modal-header">
33
<h1 class="dialog-title">{{Localize.INPUT_TITLE}}</h1>
44
</div>
55
<div class="modal-body">
66
<p>{{Localize.INPUT_TEXT}}</p>
7-
<input name="num" id="insya_num" value="1" />
7+
<input name="num" id="num" value="1" />
88
</div>
99
<div class="modal-footer">
10-
<button class="dialog-button btn primary" data-button-id="ok">{{Strings.OK}}</button>
11-
<button class="dialog-button btn" data-button-id="close">{{Strings.CLOSE}}</button>
10+
<button class="dialog-button btn" data-button-id="cancel">{{Strings.CANCEL}}</button>
11+
<button class="dialog-button btn primary" data-button-id="ok">{{Strings.DONE}}x</button>
1212
</div>
1313
</div>

lib/autoLink.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
17+
/*global define, brackets, window, $, Mustache, navigator */
18+
19+
define(function (require, exports, module) {
20+
"use strict";
21+
22+
// Brackets modules
23+
var AppInit = brackets.getModule("utils/AppInit"),
24+
EditorManager = brackets.getModule("editor/EditorManager"),
25+
DocumentManager = brackets.getModule("document/DocumentManager");
26+
27+
/* Extension const */
28+
var pattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/;
29+
30+
/**
31+
* Url Detect
32+
* htttp://www.domain.com to <a href="http://domain.com">http://domain.com</a>
33+
* @param text
34+
*/
35+
function urlDetect(text) {
36+
37+
return text.replace(pattern, function(url) {
38+
return '<a href="' + url + '" class="autolink">' + url + '</a>';
39+
});
40+
41+
}
42+
43+
/**
44+
* Auto Link.
45+
*/
46+
function autoLink() {
47+
48+
var editor = EditorManager.getCurrentFullEditor();
49+
50+
if (editor) {
51+
var unformattedText, isSelection = false;
52+
var selectedText = editor.getSelectedText();
53+
var selection = editor.getSelection();
54+
55+
if (selectedText.length > 0) {
56+
isSelection = true;
57+
unformattedText = selectedText;
58+
} else {
59+
unformattedText = DocumentManager.getCurrentDocument().getText();
60+
}
61+
62+
var formattedText = urlDetect(unformattedText);
63+
var doc = DocumentManager.getCurrentDocument();
64+
65+
doc.batchOperation(function () {
66+
67+
if (isSelection) {
68+
doc.replaceRange(formattedText, selection.start, selection.end);
69+
} else {
70+
doc.setText(formattedText);
71+
}
72+
73+
});
74+
}
75+
}
76+
77+
78+
/**
79+
* This function is registered with EditManager as an inline editor provider. It creates an inline editor
80+
* when cursor is on a JavaScript function name, find all functions that match the name
81+
* and show (one/all of them) in an inline editor.
82+
*
83+
* @param {!Editor} editor
84+
* @param {!{line:Number, ch:Number}} pos
85+
* @return {$.Promise} a promise that will be resolved with an InlineWidget
86+
* or null if we're not going to provide anything.
87+
*/
88+
function autoLinkProvider(hostEditor, pos) {
89+
90+
// Only provide JavaScript editor if the selection is within a single line
91+
var sel = hostEditor.getSelection();
92+
if (sel.start.line !== sel.end.line) {
93+
return null;
94+
}
95+
96+
var result = new $.Deferred();
97+
98+
result.resolve(autoLink);
99+
100+
return result.promise();
101+
}
102+
103+
EditorManager.registerInlineEditProvider(autoLinkProvider);
104+
105+
});
106+
107+

lib/common.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
17+
/*global define, brackets, window, $, Mustache, navigator */
18+
19+
define(function (require, exports, module) {
20+
'use strict';
21+
22+
23+
//http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color
24+
function shadeColor(color, percent)
25+
{
26+
color = color.replace(/#/,'');
27+
var num = parseInt(color,16),
28+
amt = Math.round(2.55 * percent),
29+
R = (num >> 16) + amt,
30+
B = (num >> 8 & 0x00FF) + amt,
31+
G = (num & 0x0000FF) + amt;
32+
return '#' + (0x1000000 + (R<255?R<1?0:R:255)*0x10000 + (B<255?B<1?0:B:255)*0x100 + (G<255?G<1?0:G:255)).toString(16).slice(1);
33+
}
34+
35+
function lightColor(color)
36+
{
37+
color = color.replace(/#/,'');
38+
var num = parseInt(color,16),
39+
R = (num >> 16),
40+
B = (num >> 8 & 0x00FF),
41+
G = (num & 0x0000FF);
42+
L = 0.2*R + 0.7*G + 0.1*B;
43+
return (L/255.0 > 0.5);
44+
}
45+
46+
47+
});
48+

lib/newDoc.js

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,21 @@
1919
define(function (require, exports, module) {
2020
"use strict";
2121

22-
23-
var docIndex = 1,
24-
commandId = "insya.newdoc.cmd",
25-
html5File = "insya.newhtml5";
26-
2722
// Brackets modules
28-
var DocumentManager = brackets.getModule("document/DocumentManager"),
23+
var AppInit = brackets.getModule("utils/AppInit"),
24+
KeyEvent = brackets.getModule("utils/KeyEvent"),
25+
DocumentManager = brackets.getModule("document/DocumentManager"),
2926
Commands = brackets.getModule("command/Commands"),
3027
CommandManager = brackets.getModule("command/CommandManager"),
31-
KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
3228
EditorManager = brackets.getModule("editor/EditorManager"),
29+
KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
3330
Menus = brackets.getModule("command/Menus");
3431

3532
// Template file
3633
var Html5Template = require("text!htmlContent/html5.html"),
37-
Localize = require("strings");
34+
Localize = require("strings"),
35+
docIndex = 1,
36+
moduleName = "insya.newhtml5";
3837

3938
// Brackets elements
4039
var sidebar = $("#sidebar"),
@@ -69,16 +68,51 @@ define(function (require, exports, module) {
6968
}
7069

7170
});
71+
72+
var parseLine = function (line, cursorPosition) {
73+
var words;
74+
line = line.substring(0, cursorPosition);
75+
words = line.split(/\W/);
76+
return words[words.length - 1];
77+
};
78+
79+
var keyEventHandler = function ($event, editor, event) {
80+
81+
var cursorPosition,
82+
line,
83+
readLine,
84+
start;
85+
86+
if ((event.type === "keydown") && (event.keyCode === KeyEvent.DOM_VK_TAB)) {
87+
cursorPosition = editor.getCursorPos();
88+
line = editor.document.getLine(cursorPosition.line);
89+
readLine = parseLine(line, cursorPosition.ch);
90+
91+
if(readLine === "html5")
92+
{
93+
start = {
94+
line: cursorPosition.line,
95+
ch: cursorPosition.ch - readLine.length
96+
};
97+
editor.document.replaceRange(Html5Template, start, cursorPosition);
98+
event.preventDefault();
99+
}
100+
}
101+
};
72102

73-
// Register command
74-
CommandManager.register(Localize.MENU_NEW_DOC, html5File, handleFileNew);
103+
AppInit.appReady(function () {
75104

76-
// Set menu
77-
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
78-
menu.addMenuItem(html5File, undefined, Menus.AFTER, Commands.FILE_NEW_UNTITLED);
105+
// Register command
106+
CommandManager.register(Localize.MENU_NEW_DOC, moduleName, handleFileNew);
79107

80-
// Shortcut add binding
81-
KeyBindingManager.addBinding(commandId, "Ctrl-Alt-N", "mac");
82-
KeyBindingManager.addBinding(commandId, "Ctrl-Alt-N", "win");
108+
// Set menu
109+
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
110+
menu.addMenuItem(moduleName, undefined, Menus.AFTER, Commands.FILE_NEW_UNTITLED);
83111

112+
// Key event
113+
var currentEditor = EditorManager.getCurrentFullEditor();
114+
$(currentEditor).on('keyEvent', keyEventHandler);
115+
116+
});
117+
84118
});

0 commit comments

Comments
 (0)