friendly_markdown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2470e9e83a1af50e8635e6c613be00fb185bfa82
4
+ data.tar.gz: 14f12f302edb5904fb32255a85ef79c0492b3aa9
5
+ SHA512:
6
+ metadata.gz: 04346f7dd6700714637f5a86fccfb182df0f99d29a1e09a4c449539051835ba91792d74ccf78486c5cbdb95a353ad4789b56015df4dfad01c8c5a249cdb1825e
7
+ data.tar.gz: f8866a45e46c4f314bc495e78f1d7f4363d96b9ec286ff301cebe55030ce3503f2d745702ea5b509f606520d1a4c9e4be73829911fa4fe7c7fac9ad0a22ad5c0
@@ -0,0 +1,2 @@
1
+ /pkg/
2
+ /coverage/
@@ -0,0 +1,3 @@
1
+ [submodule "task"]
2
+ path = task
3
+ url = git://github.com/godfat/gemgem.git
@@ -0,0 +1,11 @@
1
+
2
+ language: ruby
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - rbx-2
8
+ - jruby
9
+
10
+ install: 'bundle install --retry=3'
11
+ script: 'ruby -r bundler/setup -S rake test'
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'pork'
8
+
9
+ gem 'simplecov', :require => false if ENV['COV']
10
+ gem 'coveralls', :require => false if ENV['CI']
11
+
12
+ platform :rbx do
13
+ gem 'rubysl-singleton' # used in rake
14
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,64 @@
1
+ # friendly_markdown [![Build Status](https://secure.travis-ci.org/godfat/friendly_markdown.png?branch=master)](http://travis-ci.org/godfat/friendly_markdown) [![Coverage Status](https://coveralls.io/repos/godfat/friendly_markdown/badge.png)](https://coveralls.io/r/godfat/friendly_markdown) [![Join the chat at https://gitter.im/godfat/friendly_markdown](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/friendly_markdown)
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/friendly_markdown)
8
+ * [rubygems](https://rubygems.org/gems/friendly_markdown)
9
+ * [rdoc](http://rdoc.info/github/godfat/friendly_markdown)
10
+
11
+ ## DESCRIPTION:
12
+
13
+ Simple markdown for user input, with auto-link, auto-linebreak,
14
+ and sanitization.
15
+
16
+ ## FEATURES:
17
+
18
+ * Auto-links
19
+ * Auto-linebreak
20
+ * Sanitization
21
+
22
+ ## WHY?
23
+
24
+ Original markdown doesn't work well for user input, it's unsafe and
25
+ inconvenient for quick comments.
26
+
27
+ ## REQUIREMENTS:
28
+
29
+ * kramdown
30
+ * sanitize
31
+ * Tested with MRI (official CRuby), Rubinius and JRuby.
32
+
33
+ ## INSTALLATION:
34
+
35
+ gem install friendly_markdown
36
+
37
+ ## SYNOPSIS:
38
+
39
+ ``` ruby
40
+ reqiore 'friendly_markdown'
41
+ FriendlyMarkdown.compile('user input')
42
+ ```
43
+
44
+ ## CONTRIBUTORS:
45
+
46
+ * Lin Jen-Shin (@godfat)
47
+
48
+ ## LICENSE:
49
+
50
+ Apache License 2.0
51
+
52
+ Copyright (c) 2015, Lin Jen-Shin (godfat)
53
+
54
+ Licensed under the Apache License, Version 2.0 (the "License");
55
+ you may not use this file except in compliance with the License.
56
+ You may obtain a copy of the License at
57
+
58
+ <http://www.apache.org/licenses/LICENSE-2.0>
59
+
60
+ Unless required by applicable law or agreed to in writing, software
61
+ distributed under the License is distributed on an "AS IS" BASIS,
62
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63
+ See the License for the specific language governing permissions and
64
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+
2
+ begin
3
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
4
+ rescue LoadError
5
+ sh 'git submodule update --init'
6
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
7
+ end
8
+
9
+ Gemgem.init(dir) do |s|
10
+ s.name = 'friendly_markdown'
11
+ s.version = '0.1.0'
12
+ %w[kramdown sanitize].each{ |g| s.add_runtime_dependency(g) }
13
+ end
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: friendly_markdown 0.1.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "friendly_markdown"
6
+ s.version = "0.1.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib"]
10
+ s.authors = ["Lin Jen-Shin (godfat)"]
11
+ s.date = "2015-11-04"
12
+ s.description = "Simple markdown for user input, with auto-link, auto-linebreak,\nand sanitization."
13
+ s.email = ["godfat (XD) godfat.org"]
14
+ s.files = [
15
+ ".gitignore",
16
+ ".gitmodules",
17
+ ".travis.yml",
18
+ "Gemfile",
19
+ "LICENSE",
20
+ "README.md",
21
+ "Rakefile",
22
+ "friendly_markdown.gemspec",
23
+ "lib/friendly_markdown.rb",
24
+ "task/README.md",
25
+ "task/gemgem.rb",
26
+ "test/test_basic.rb"]
27
+ s.homepage = "https://github.com/godfat/friendly_markdown"
28
+ s.licenses = ["Apache License 2.0"]
29
+ s.rubygems_version = "2.4.8"
30
+ s.summary = "Simple markdown for user input, with auto-link, auto-linebreak,"
31
+ s.test_files = ["test/test_basic.rb"]
32
+
33
+ if s.respond_to? :specification_version then
34
+ s.specification_version = 4
35
+
36
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
37
+ s.add_runtime_dependency(%q<kramdown>, [">= 0"])
38
+ s.add_runtime_dependency(%q<sanitize>, [">= 0"])
39
+ else
40
+ s.add_dependency(%q<kramdown>, [">= 0"])
41
+ s.add_dependency(%q<sanitize>, [">= 0"])
42
+ end
43
+ else
44
+ s.add_dependency(%q<kramdown>, [">= 0"])
45
+ s.add_dependency(%q<sanitize>, [">= 0"])
46
+ end
47
+ end
@@ -0,0 +1,37 @@
1
+
2
+ require 'kramdown'
3
+ require 'sanitize'
4
+
5
+ module FriendlyMarkdown
6
+ module_function
7
+ def compile input, mconfig: markdown_config, sconfig: sanitize_config
8
+ sanitize(markdown(autolink(input.strip), mconfig), sconfig)
9
+ end
10
+
11
+ def autolink text
12
+ text.gsub(%r{\<?\bhttps?://\S+[\b/]?}) do |m|
13
+ if m =~ /\A<.+>\z$/
14
+ s = m[1..-2]
15
+ %Q{&lt;<a href="#{s}">#{s}</a>&gt;}
16
+ else
17
+ %Q{<a href="#{m}">#{m}</a>}
18
+ end
19
+ end
20
+ end
21
+
22
+ def markdown md, config=markdown_config
23
+ Kramdown::Document.new(md, config).to_html
24
+ end
25
+
26
+ def sanitize html, config=sanitize_config
27
+ Sanitize.fragment(html, config)
28
+ end
29
+
30
+ def markdown_config
31
+ {:input => 'GFM', :hard_wrap => true}
32
+ end
33
+
34
+ def sanitize_config
35
+ Sanitize::Config::RELAXED
36
+ end
37
+ end
@@ -0,0 +1,54 @@
1
+ # Gemgem
2
+
3
+ ## DESCRIPTION:
4
+
5
+ Provided tasks:
6
+
7
+ rake clean # Remove ignored files
8
+ rake gem:build # Build gem
9
+ rake gem:install # Install gem
10
+ rake gem:release # Release gem
11
+ rake gem:spec # Generate gemspec
12
+ rake test # Run tests in memory
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
17
+
18
+ ## INSTALLATION:
19
+
20
+ git submodule add git://github.com/godfat/gemgem.git task
21
+
22
+ And in Rakefile:
23
+
24
+ ``` ruby
25
+ begin
26
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
27
+ rescue LoadError
28
+ sh 'git submodule update --init'
29
+ exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
30
+ end
31
+
32
+ Gemgem.init(dir) do |s|
33
+ s.name = 'your-gem'
34
+ s.version = '0.1.0'
35
+ end
36
+ ```
37
+
38
+ ## LICENSE:
39
+
40
+ Apache License 2.0
41
+
42
+ Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
43
+
44
+ Licensed under the Apache License, Version 2.0 (the "License");
45
+ you may not use this file except in compliance with the License.
46
+ You may obtain a copy of the License at
47
+
48
+ <http://www.apache.org/licenses/LICENSE-2.0>
49
+
50
+ Unless required by applicable law or agreed to in writing, software
51
+ distributed under the License is distributed on an "AS IS" BASIS,
52
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
53
+ See the License for the specific language governing permissions and
54
+ limitations under the License.
@@ -0,0 +1,316 @@
1
+
2
+ module Gemgem
3
+ class << self
4
+ attr_accessor :dir, :spec, :spec_create
5
+ end
6
+
7
+ module_function
8
+ def gem_tag ; "#{spec.name}-#{spec.version}" ; end
9
+ def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
10
+ def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
11
+ def pkg_dir ; "#{dir}/pkg" ; end
12
+ def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
13
+
14
+ def init dir, &block
15
+ self.dir = dir
16
+ $LOAD_PATH.unshift("#{dir}/lib")
17
+ ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
18
+ ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
19
+ self.spec_create = block
20
+ end
21
+
22
+ def create
23
+ spec = Gem::Specification.new do |s|
24
+ s.authors = ['Lin Jen-Shin (godfat)']
25
+ s.email = ['godfat (XD) godfat.org']
26
+
27
+ s.description = description.join
28
+ s.summary = description.first
29
+ s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
30
+
31
+ s.date = Time.now.strftime('%Y-%m-%d')
32
+ s.files = gem_files
33
+ s.test_files = test_files
34
+ s.executables = bin_files
35
+ end
36
+ spec_create.call(spec)
37
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
38
+ self.spec = spec
39
+ end
40
+
41
+ def gem_install
42
+ require 'rubygems/commands/install_command'
43
+ # read ~/.gemrc
44
+ Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
45
+ Gem::Command.extra_args = Gem.configuration[:gem]
46
+
47
+ # setup install options
48
+ cmd = Gem::Commands::InstallCommand.new
49
+ cmd.handle_options([])
50
+
51
+ # install
52
+ install = Gem::Installer.new(gem_path, cmd.options)
53
+ install.install
54
+ puts "\e[35mGem installed: \e[33m#{strip_path(install.gem_dir)}\e[0m"
55
+ end
56
+
57
+ def gem_spec
58
+ create
59
+ write
60
+ end
61
+
62
+ def gem_build
63
+ require 'fileutils'
64
+ require 'rubygems/package'
65
+ gem = nil
66
+ Dir.chdir(dir) do
67
+ gem = Gem::Package.build(Gem::Specification.load(spec_path))
68
+ FileUtils.mkdir_p(pkg_dir)
69
+ FileUtils.mv(gem, pkg_dir) # gem is relative path, but might be ok
70
+ end
71
+ puts "\e[35mGem built: \e[33m#{strip_path("#{pkg_dir}/#{gem}")}\e[0m"
72
+ end
73
+
74
+ def gem_release
75
+ sh_git('tag', gem_tag)
76
+ sh_git('push')
77
+ sh_git('push', '--tags')
78
+ sh_gem('push', gem_path)
79
+ end
80
+
81
+ def gem_check
82
+ unless git('status', '--porcelain').empty?
83
+ puts("\e[35mWorking copy is not clean.\e[0m")
84
+ exit(3)
85
+ end
86
+
87
+ ver = spec.version.to_s
88
+
89
+ if ENV['VERSION'].nil?
90
+ puts("\e[35mExpected " \
91
+ "\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
92
+ exit(1)
93
+
94
+ elsif ENV['VERSION'] != ver
95
+ puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
96
+ "\e[35mbut got\n " \
97
+ "\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
98
+ exit(2)
99
+ end
100
+ end
101
+
102
+ def test
103
+ return if test_files.empty?
104
+
105
+ if ENV['COV'] || ENV['CI']
106
+ require 'simplecov'
107
+ if ENV['CI']
108
+ begin
109
+ require 'coveralls'
110
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
111
+ rescue LoadError => e
112
+ puts "Cannot load coveralls, skip: #{e}"
113
+ end
114
+ end
115
+ SimpleCov.start do
116
+ add_filter('test/')
117
+ add_filter('test.rb')
118
+ end
119
+ end
120
+
121
+ test_files.each{ |file| require "#{dir}/#{file[0..-4]}" }
122
+ end
123
+
124
+ def clean
125
+ return if ignored_files.empty?
126
+
127
+ require 'fileutils'
128
+ trash = File.expand_path("~/.Trash/#{spec.name}")
129
+ puts "Move the following files into: \e[35m#{strip_path(trash)}\e[33m"
130
+
131
+ ignored_files.each do |file|
132
+ from = "#{dir}/#{file}"
133
+ to = "#{trash}/#{File.dirname(file)}"
134
+ puts strip_path(from)
135
+
136
+ FileUtils.mkdir_p(to)
137
+ FileUtils.mv(from, to)
138
+ end
139
+
140
+ print "\e[0m"
141
+ end
142
+
143
+ def write
144
+ File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
145
+ end
146
+
147
+ def split_lines ruby
148
+ ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
149
+ if $2.index(',')
150
+ "#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
151
+ else
152
+ s
153
+ end
154
+ }
155
+ end
156
+
157
+ def strip_path path
158
+ strip_home_path(strip_cwd_path(path))
159
+ end
160
+
161
+ def strip_home_path path
162
+ path.sub(ENV['HOME'], '~')
163
+ end
164
+
165
+ def strip_cwd_path path
166
+ path.sub(Dir.pwd, '.')
167
+ end
168
+
169
+ def git *args
170
+ `git --git-dir=#{dir}/.git #{args.join(' ')}`
171
+ end
172
+
173
+ def sh_git *args
174
+ Rake.sh('git', "--git-dir=#{dir}/.git", *args)
175
+ end
176
+
177
+ def sh_gem *args
178
+ Rake.sh(Gem.ruby, '-S', 'gem', *args)
179
+ end
180
+
181
+ def glob path=dir
182
+ Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
183
+ end
184
+
185
+ def readme
186
+ @readme ||=
187
+ if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
188
+ ps = "##{File.read(path)}".
189
+ scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
190
+ ps.inject('HEADER' => ps.first){ |r, s, i|
191
+ r[s[/\w+/]] = s
192
+ r
193
+ }
194
+ else
195
+ {}
196
+ end
197
+ end
198
+
199
+ def description
200
+ # JRuby String#lines is returning an enumerator
201
+ @description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
202
+ end
203
+
204
+ def all_files
205
+ @all_files ||= fold_files(glob).sort
206
+ end
207
+
208
+ def fold_files files
209
+ files.inject([]){ |r, path|
210
+ if File.file?(path) && path !~ %r{/\.git(/|$)} &&
211
+ (rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
212
+ r << rpath
213
+ elsif File.symlink?(path) # walk into symlinks...
214
+ r.concat(fold_files(glob(File.expand_path(path,
215
+ File.readlink(path)))))
216
+ else
217
+ r
218
+ end
219
+ }
220
+ end
221
+
222
+ def gem_files
223
+ @gem_files ||= all_files.reject{ |f|
224
+ f =~ ignored_pattern && !git_files.include?(f)
225
+ }
226
+ end
227
+
228
+ def test_files
229
+ @test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
230
+ end
231
+
232
+ def bin_files
233
+ @bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
234
+ end
235
+
236
+ def git_files
237
+ @git_files ||= if File.exist?("#{dir}/.git")
238
+ git('ls-files').split("\n")
239
+ else
240
+ []
241
+ end
242
+ end
243
+
244
+ def ignored_files
245
+ @ignored_files ||= all_files.grep(ignored_pattern)
246
+ end
247
+
248
+ def ignored_pattern
249
+ @ignored_pattern ||= if gitignore.empty?
250
+ /^$/
251
+ else
252
+ Regexp.new(expand_patterns(gitignore).join('|'))
253
+ end
254
+ end
255
+
256
+ def expand_patterns pathes
257
+ # http://git-scm.com/docs/gitignore
258
+ pathes.flat_map{ |path|
259
+ # we didn't implement negative pattern for now
260
+ Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
261
+ }
262
+ end
263
+
264
+ def gitignore
265
+ @gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
266
+ File.read(path).lines.
267
+ reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
268
+ else
269
+ []
270
+ end
271
+ end
272
+ end
273
+
274
+ namespace :gem do
275
+
276
+ desc 'Install gem'
277
+ task :install => [:build] do
278
+ Gemgem.gem_install
279
+ end
280
+
281
+ desc 'Build gem'
282
+ task :build => [:spec] do
283
+ Gemgem.gem_build
284
+ end
285
+
286
+ desc 'Generate gemspec'
287
+ task :spec do
288
+ Gemgem.gem_spec
289
+ end
290
+
291
+ desc 'Release gem'
292
+ task :release => [:spec, :check, :build] do
293
+ Gemgem.gem_release
294
+ end
295
+
296
+ task :check do
297
+ Gemgem.gem_check
298
+ end
299
+
300
+ end # of gem namespace
301
+
302
+ desc 'Run tests'
303
+ task :test do
304
+ Gemgem.test
305
+ end
306
+
307
+ desc 'Trash ignored files'
308
+ task :clean => ['gem:spec'] do
309
+ Gemgem.clean
310
+ end
311
+
312
+ task :default do
313
+ # Is there a reliable way to do this in the current process?
314
+ # It failed miserably before between Rake versions...
315
+ exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
316
+ end
@@ -0,0 +1,68 @@
1
+
2
+ require 'pork/auto'
3
+ require 'friendly_markdown'
4
+
5
+ describe FriendlyMarkdown do
6
+ would 'compile' do
7
+ html = FriendlyMarkdown.compile <<-MARKDOWN
8
+ I can use regular html <b>strong</b>.
9
+ With regular line break.
10
+ And autolink: https://github.com/godfat/friendly_markdown
11
+ It just works.
12
+
13
+ And code block without html:
14
+
15
+ ``` xml
16
+ <b>this is xml</b>
17
+ ```
18
+
19
+ # And quote stuffs as usual:
20
+
21
+ > This is just a simple quote
22
+
23
+ Cheers! autolink: https://github.com/godfat/friendly_markdown
24
+ MARKDOWN
25
+
26
+ expect(html).eq <<-HTML
27
+ <p>I can use regular html <b>strong</b>.<br>
28
+ With regular line break.<br>
29
+ And autolink: <a href="https://github.com/godfat/friendly_markdown">https://github.com/godfat/friendly_markdown</a><br>
30
+ It just works.</p>
31
+
32
+ <p>And code block without html:</p>
33
+
34
+ <pre><code class="language-xml">&lt;b&gt;this is xml&lt;/b&gt;
35
+ </code></pre>
36
+
37
+ <h1 id="and-quote-stuffs-as-usual">And quote stuffs as usual:</h1>
38
+
39
+ <blockquote>
40
+ <p>This is just a simple quote</p>
41
+ </blockquote>
42
+
43
+ <p>Cheers! autolink: <a href="https://github.com/godfat/friendly_markdown">https://github.com/godfat/friendly_markdown</a></p>
44
+ HTML
45
+ end
46
+
47
+ would 'remove script' do
48
+ html = FriendlyMarkdown.compile('remove me <script>')
49
+ expect(html).eq "<p>remove me </p>\n"
50
+ end
51
+
52
+ would 'remove unknown tags' do
53
+ html = FriendlyMarkdown.compile('remove me <bad>')
54
+ expect(html).eq "<p>remove me </p>\n"
55
+ end
56
+
57
+ would 'allow markdown links' do
58
+ html = FriendlyMarkdown.compile <<-MARKDOWN
59
+ This is autolink: https://github.com/godfat/friendly_markdown
60
+ This is markdown link: <https://github.com/godfat/friendly_markdown>
61
+ MARKDOWN
62
+
63
+ expect(html).eq <<-HTML
64
+ <p>This is autolink: <a href="https://github.com/godfat/friendly_markdown">https://github.com/godfat/friendly_markdown</a><br>
65
+ This is markdown link: &lt;<a href="https://github.com/godfat/friendly_markdown">https://github.com/godfat/friendly_markdown</a>&gt;</p>
66
+ HTML
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: friendly_markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lin Jen-Shin (godfat)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sanitize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |-
42
+ Simple markdown for user input, with auto-link, auto-linebreak,
43
+ and sanitization.
44
+ email:
45
+ - godfat (XD) godfat.org
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".gitmodules"
52
+ - ".travis.yml"
53
+ - Gemfile
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - friendly_markdown.gemspec
58
+ - lib/friendly_markdown.rb
59
+ - task/README.md
60
+ - task/gemgem.rb
61
+ - test/test_basic.rb
62
+ homepage: https://github.com/godfat/friendly_markdown
63
+ licenses:
64
+ - Apache License 2.0
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.8
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Simple markdown for user input, with auto-link, auto-linebreak,
86
+ test_files:
87
+ - test/test_basic.rb