bootstrap_pagedown 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,111 @@
1
+ (function () {
2
+ var output, Converter;
3
+ if (typeof exports === "object" && typeof require === "function") { // we're in a CommonJS (e.g. Node.js) module
4
+ output = exports;
5
+ Converter = require("./Markdown.Converter").Converter;
6
+ } else {
7
+ output = window.Markdown;
8
+ Converter = output.Converter;
9
+ }
10
+
11
+ output.getSanitizingConverter = function () {
12
+ var converter = new Converter();
13
+ converter.hooks.chain("postConversion", sanitizeHtml);
14
+ converter.hooks.chain("postConversion", balanceTags);
15
+ return converter;
16
+ }
17
+
18
+ function sanitizeHtml(html) {
19
+ return html.replace(/<[^>]*>?/gi, sanitizeTag);
20
+ }
21
+
22
+ // (tags that can be opened/closed) | (tags that stand alone)
23
+ var basic_tag_whitelist = /^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|i|kbd|li|ol|p|s|sup|sub|strong|strike|ul)>|<(br|hr)\s?\/?>)$/i;
24
+ // <a href="url..." optional title>|</a>
25
+ var a_white = /^(<a\shref="(https?:(\/\/|\/)|ftp:(\/\/|\/)|mailto:|magnet:)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+"(\stitle="[^"<>]+")?\s?>|<\/a>)$/i;
26
+
27
+ // <img src="url..." optional width optional height optional alt optional title
28
+ var img_white = /^(<img\ssrc="(https?:\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+"(\swidth="\d{1,3}")?(\sheight="\d{1,3}")?(\salt="[^"<>]*")?(\stitle="[^"<>]*")?\s?\/?>)$/i;
29
+
30
+ // <pre optional class="prettyprint linenums">|</pre> for twitter bootstrap
31
+ var pre_white = /^(<pre(\sclass="prettyprint linenums")?>|<\/pre>)$/i;
32
+
33
+ function sanitizeTag(tag) {
34
+ if (tag.match(basic_tag_whitelist) || tag.match(a_white) || tag.match(img_white) || tag.match(pre_white))
35
+ return tag;
36
+ else
37
+ return "";
38
+ }
39
+
40
+ /// <summary>
41
+ /// attempt to balance HTML tags in the html string
42
+ /// by removing any unmatched opening or closing tags
43
+ /// IMPORTANT: we *assume* HTML has *already* been
44
+ /// sanitized and is safe/sane before balancing!
45
+ ///
46
+ /// adapted from CODESNIPPET: A8591DBA-D1D3-11DE-947C-BA5556D89593
47
+ /// </summary>
48
+ function balanceTags(html) {
49
+
50
+ if (html == "")
51
+ return "";
52
+
53
+ var re = /<\/?\w+[^>]*(\s|$|>)/g;
54
+ // convert everything to lower case; this makes
55
+ // our case insensitive comparisons easier
56
+ var tags = html.toLowerCase().match(re);
57
+
58
+ // no HTML tags present? nothing to do; exit now
59
+ var tagcount = (tags || []).length;
60
+ if (tagcount == 0)
61
+ return html;
62
+
63
+ var tagname, tag;
64
+ var ignoredtags = "<p><img><br><li><hr>";
65
+ var match;
66
+ var tagpaired = [];
67
+ var tagremove = [];
68
+ var needsRemoval = false;
69
+
70
+ // loop through matched tags in forward order
71
+ for (var ctag = 0; ctag < tagcount; ctag++) {
72
+ tagname = tags[ctag].replace(/<\/?(\w+).*/, "$1");
73
+ // skip any already paired tags
74
+ // and skip tags in our ignore list; assume they're self-closed
75
+ if (tagpaired[ctag] || ignoredtags.search("<" + tagname + ">") > -1)
76
+ continue;
77
+
78
+ tag = tags[ctag];
79
+ match = -1;
80
+
81
+ if (!/^<\//.test(tag)) {
82
+ // this is an opening tag
83
+ // search forwards (next tags), look for closing tags
84
+ for (var ntag = ctag + 1; ntag < tagcount; ntag++) {
85
+ if (!tagpaired[ntag] && tags[ntag] == "</" + tagname + ">") {
86
+ match = ntag;
87
+ break;
88
+ }
89
+ }
90
+ }
91
+
92
+ if (match == -1)
93
+ needsRemoval = tagremove[ctag] = true; // mark for removal
94
+ else
95
+ tagpaired[match] = true; // mark paired
96
+ }
97
+
98
+ if (!needsRemoval)
99
+ return html;
100
+
101
+ // delete all orphaned tags from the string
102
+
103
+ var ctag = 0;
104
+ html = html.replace(re, function (match) {
105
+ var res = tagremove[ctag] ? "" : match;
106
+ ctag++;
107
+ return res;
108
+ });
109
+ return html;
110
+ }
111
+ })();
@@ -0,0 +1,5 @@
1
+ jQuery ->
2
+ if $("#wmd-input").length > 0
3
+ converter = Markdown.getSanitizingConverter()
4
+ editor = new Markdown.Editor converter
5
+ editor.run()
@@ -0,0 +1,74 @@
1
+ .wmd-panel {
2
+ width: 100%;
3
+ }
4
+
5
+ .wmd-input {
6
+ height: 300px;
7
+ width: 100%;
8
+ box-sizing: border-box;
9
+ -webkit-box-sizing: border-box;
10
+ -moz-box-sizing: border-box;
11
+ -ms-box-sizing: border-box;
12
+ }
13
+
14
+ .wmd-preview {
15
+ width: 100%;
16
+ box-sizing: border-box;
17
+ -webkit-box-sizing:border-box;
18
+ -moz-box-sizing: border-box;
19
+ -ms-box-sizing: border-box;
20
+ }
21
+
22
+ .wmd-panel .btn-toolbar {
23
+ margin-bottom: 0;
24
+ padding: 0;
25
+ width: 100%;
26
+ }
27
+
28
+ .icon-link,
29
+ .icon-blockquote,
30
+ .icon-code,
31
+ .icon-bullet-list,
32
+ .icon-list,
33
+ .icon-header,
34
+ .icon-hr-line,
35
+ .icon-undo {
36
+ background-image: url(/assets/Markdown.Editor.Icons.png);
37
+ }
38
+
39
+ .icon-link { background-position: 0 0; }
40
+ .icon-blockquote { background-position: -24px 0; }
41
+ .icon-code { background-position: -48px 0; }
42
+ .icon-bullet-list { background-position: -72px 0; }
43
+ .icon-list { background-position: -96px 0; }
44
+ .icon-header { background-position: -120px 0; }
45
+ .icon-hr-line { background-position: -144px 0; }
46
+ .icon-undo { background-position: -168px 0; }
47
+
48
+ .wmd-prompt-background
49
+ {
50
+ background-color: Black;
51
+ }
52
+
53
+ .wmd-prompt-dialog
54
+ {
55
+ border: 1px solid #999999;
56
+ background-color: #F5F5F5;
57
+ }
58
+
59
+ .wmd-prompt-dialog > div {
60
+ font-size: 0.8em;
61
+ font-family: arial, helvetica, sans-serif;
62
+ }
63
+
64
+ .wmd-prompt-dialog > form > input[type="text"] {
65
+ border: 1px solid #999999;
66
+ color: black;
67
+ }
68
+
69
+ .wmd-prompt-dialog > form > input[type="button"]{
70
+ border: 1px solid #888888;
71
+ font-family: trebuchet MS, helvetica, sans-serif;
72
+ font-size: 0.8em;
73
+ font-weight: bold;
74
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_pagedown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Enrique Vidal
@@ -36,6 +36,13 @@ files:
36
36
  - lib/bootstrap_pagedown/version.rb
37
37
  - lib/bootstrap_pagedown.rb
38
38
  - lib/tasks/bootstrap_pagedown_tasks.rake
39
+ - vendor/assets/images/Markdown.Editor.Icons.png
40
+ - vendor/assets/javascripts/bootstrap_pagedown/load_editor.coffee
41
+ - vendor/assets/javascripts/bootstrap_pagedown/Markdown.Converter.js
42
+ - vendor/assets/javascripts/bootstrap_pagedown/Markdown.Editor.js
43
+ - vendor/assets/javascripts/bootstrap_pagedown/Markdown.Sanitizer.js
44
+ - vendor/assets/javascripts/bootstrap_pagedown.js
45
+ - vendor/assets/stylesheets/bootstrap_pagedown.css.scss
39
46
  - MIT-LICENSE
40
47
  - Rakefile
41
48
  - README.md