pagedown-bootstrap-rails 1.0.0

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,3 @@
1
+ //= require markdown.converter
2
+ //= require markdown.editor
3
+ //= require markdown.sanitizer
@@ -0,0 +1,116 @@
1
+ $baseFontFamily: "Helvetica Neue", Helvetica, Arial, sans-serif !default;
2
+ $baseFontSize: 14px !default;
3
+
4
+ .wmd-input {
5
+ height: 300px;
6
+ width: 100%;
7
+ box-sizing: border-box;
8
+ -webkit-box-sizing: border-box;
9
+ -moz-box-sizing: border-box;
10
+ -ms-box-sizing: border-box;
11
+ &.wmd-input-small{
12
+ height: 50px;
13
+ }
14
+ }
15
+
16
+ .wmd-preview {
17
+ min-height: 20px;
18
+ max-height: 300px;
19
+ overflow-y: scroll;
20
+ padding: 19px;
21
+ margin: 20px 0 0;
22
+ background-color: #f5f5f5;
23
+ border: 1px solid #eee;
24
+ border: 1px solid rgba(0, 0, 0, 0.05);
25
+ -webkit-border-radius: 4px;
26
+ -moz-border-radius: 4px;
27
+ border-radius: 4px;
28
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
29
+ -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
30
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
31
+ width: 100%;
32
+ box-sizing: border-box;
33
+ -webkit-box-sizing: border-box;
34
+ -moz-box-sizing: border-box;
35
+ -ms-box-sizing: border-box;
36
+ }
37
+
38
+ .wmd-preview blockquote {
39
+ border-color: #ddd;
40
+ border-color: rgba(0, 0, 0, 0.15);
41
+ }
42
+
43
+ .wmd-panel .btn-toolbar {
44
+ margin-bottom: 0;
45
+ padding: 0;
46
+ width: 100%;
47
+ }
48
+
49
+ .icon-link,
50
+ .icon-quote-left,
51
+ .icon-code,
52
+ .icon-bullet-list,
53
+ .icon-list-ol,
54
+ .icon-header,
55
+ .icon-hr-line,
56
+ .icon-undo {
57
+ background-image: image-url('pagedown-bootstrap-buttons.png');
58
+ }
59
+
60
+ .icon-link {
61
+ background-position: 0 0;
62
+ }
63
+
64
+ .icon-quote-left {
65
+ background-position: -24px 0;
66
+ }
67
+
68
+ .icon-code {
69
+ background-position: -48px 0;
70
+ }
71
+
72
+ .icon-bullet-list {
73
+ background-position: -72px 0;
74
+ }
75
+
76
+ .icon-list-ol {
77
+ background-position: -96px 0;
78
+ }
79
+
80
+ .icon-header {
81
+ background-position: -120px 0;
82
+ }
83
+
84
+ .icon-hr-line {
85
+ background-position: -144px 0;
86
+ }
87
+
88
+ .icon-undo {
89
+ background-position: -168px 0;
90
+ }
91
+
92
+ .wmd-prompt-background {
93
+ background-color: #000000;
94
+ }
95
+
96
+ .wmd-prompt-dialog {
97
+ border: 1px solid #999999;
98
+ background-color: #F5F5F5;
99
+ }
100
+
101
+ .wmd-prompt-dialog > div {
102
+ font-size: $baseFontSize;
103
+ font-family: $baseFontFamily;
104
+ }
105
+
106
+ .wmd-prompt-dialog > form > input[type="text"] {
107
+ border: 1px solid #999999;
108
+ color: black;
109
+ }
110
+
111
+ .wmd-prompt-dialog > form > input[type="button"] {
112
+ border: 1px solid #888888;
113
+ font-family: $baseFontFamily;
114
+ font-size: $baseFontSize;
115
+ font-weight: bold;
116
+ }
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pagedown-bootstrap-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hugh Evans
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>'
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: PageDown Bootstrap for the Rails asset pipeline
31
+ email:
32
+ - hugh@artpop.com.au
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/pagedown-bootstrap-rails.rb
38
+ - lib/pagedown_bootstrap/rails/engine.rb
39
+ - lib/pagedown_bootstrap/rails/version.rb
40
+ - lib/pagedown_bootstrap/rails.rb
41
+ - vendor/assets/images/pagedown-bootstrap-buttons.png
42
+ - vendor/assets/javascripts/markdown.converter.js
43
+ - vendor/assets/javascripts/markdown.editor.js
44
+ - vendor/assets/javascripts/markdown.sanitizer.js
45
+ - vendor/assets/javascripts/pagedown_bootstrap.js
46
+ - vendor/assets/stylesheets/pagedown_bootstrap.css.scss
47
+ - Readme.md
48
+ homepage: http://github.com/hughevans/pagedown-bootstrap-rails
49
+ licenses:
50
+ - MIT
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: This gem makes PageDown Bootstrap available in the Rails asset pipeline.
73
+ test_files: []