kramdown-service 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bb6c0ae34cd14bb0e341d06335f2566e2690eab
4
- data.tar.gz: d62c7a076b8c362acb2206f2bf536631917e54d8
3
+ metadata.gz: 41dd07d48ed67c255c39b46e71c8493186055b4b
4
+ data.tar.gz: e65a3defc5c2df215b1c07bff78eb9171bbafe09
5
5
  SHA512:
6
- metadata.gz: 1ef87eaf533a9cffa0d49c648465dd28a053b2ee081a95f1bdb6659e492a743b5873fc4161d22ca72e3552b812680ba58ac19f36a2cdbbe1cf30a54a590d4f8a
7
- data.tar.gz: 6082b5ea11b37ddfb1310c4afcd9b52e0276d057bf9f2df3b714833464618a8b8b598ebc7e50e0cef58fd85a7e8b4dbe266e7385fb05157085f926189e775464
6
+ metadata.gz: c5888bbad01662d9f78c436a2fa16910954871b3dcf0dbf730e337df0a8e3bc5f10154f327098c0b9500f804841c450b18725d237c2bf81ca8a210ae3fdbba8d
7
+ data.tar.gz: 4f34a2085f07012be2e28fa916cd9d943fd8fc6d362f7fcf015d91ccce4e097ca7d4b12c8303b7b4d9db832d204e25ae412609ca4cd0fd1b19ee401f2d3d7360
@@ -13,13 +13,10 @@ lib/kramdown/service/public/js/lib3rd/jquery-2.0.1.min.js
13
13
  lib/kramdown/service/public/js/markdown.note.js
14
14
  lib/kramdown/service/public/style.css
15
15
  lib/kramdown/service/version.rb
16
- lib/kramdown/service/views/_about.erb
17
16
  lib/kramdown/service/views/_debug.erb
18
17
  lib/kramdown/service/views/_editor.erb
19
18
  lib/kramdown/service/views/_editor_head.erb
20
19
  lib/kramdown/service/views/_editor_setup.erb
21
- lib/kramdown/service/views/_libs.erb
22
- lib/kramdown/service/views/_libs_service.erb
23
20
  lib/kramdown/service/views/_service.erb
24
21
  lib/kramdown/service/views/_version.erb
25
22
  lib/kramdown/service/views/debug.erb
@@ -27,3 +24,7 @@ lib/kramdown/service/views/editor.erb
27
24
  lib/kramdown/service/views/index.erb
28
25
  lib/kramdown/service/views/layout.erb
29
26
  lib/kramdown/service/views/service.erb
27
+ test/helper.rb
28
+ test/test_babelmark.rb
29
+ test/test_kramdown.rb
30
+ test/test_markdown.rb
data/README.md CHANGED
@@ -6,11 +6,34 @@
6
6
  * rdoc :: [rubydoc.info/gems/kramdown-service](http://rubydoc.info/gems/kramdown-service)
7
7
 
8
8
 
9
- ## Usage - Web Service / HTTP (JSON) API - `GET /markdown`
9
+ ## Live Version
10
10
 
11
11
  Try the `markdown` HTTP (JSON) API running
12
12
  on Heroku [`trykramdown.herokuapp.com`](http://trykramdown.herokuapp.com).
13
13
 
14
+ Note: If you see an Application Error on Heroku. Sorry. It means "**Free app running time quota exhausted**".
15
+ Please, check back in a day (or use `$ kramup` to run the service on your local machine). Thanks.
16
+
17
+
18
+ ## Start Your Own Local Version / Service
19
+
20
+ To start your own local version on your own machine use the bundled command line tool called `kramup`.
21
+
22
+ Step 0 - Install the gem e.g.
23
+
24
+ $ gem install kramdown-service
25
+
26
+ Step 1 - Start the server / service e.g.
27
+
28
+ $ kramup
29
+
30
+ Step 2 - Open up the editor page in your browser e.g. use `http://localhost:4567`.
31
+
32
+ That's it.
33
+
34
+
35
+ ## Usage - Web Service / HTTP (JSON) API - `GET /markdown`
36
+
14
37
 
15
38
  Example 1 - Converting to Hypertext (HTML):
16
39
 
@@ -78,12 +78,12 @@ class Service < Sinatra::Base
78
78
  # return hypertext (html) ## allow /markdown or /m
79
79
  get %r{/(markdown|m)$} do
80
80
 
81
- text = params.delete('text')
81
+ text = params.delete('text') || '' ## if no text param supplied, use empty/blank string
82
82
  to = params.delete('to') || 'html' ## optional - default to html
83
83
  opts = params_to_opts( params )
84
84
 
85
85
  if ['latex','l','tex'].include?( to.downcase )
86
- content_type 'text/latex'
86
+ content_type 'text/latex' ### todo: check if latex content_type exists?
87
87
  text_to_latex( text, opts )
88
88
  else ## assume html (default)
89
89
  content_type 'text/html'
@@ -98,7 +98,7 @@ class Service < Sinatra::Base
98
98
  # note: defaults (uses) GFM - github-flavored markdown mode/input
99
99
  # note: only supports html for now (e.g. does NOT support to=html|latex option etc.)
100
100
  get '/babelmark' do
101
- text = params.delete('text')
101
+ text = params.delete('text') || '' ## if no text param supplied, use empty/blank string
102
102
 
103
103
  data = {
104
104
  name: 'kramdown',
@@ -110,6 +110,15 @@ class Service < Sinatra::Base
110
110
  end
111
111
 
112
112
 
113
+ get %r{/(options|opts|o)$} do ## for debugging/testing "dump" options
114
+ content_type 'text/plain'
115
+
116
+ opts = preprocess_opts( params_to_opts( params ))
117
+ doc = Kramdown::Document.new( '', opts )
118
+ doc.options.inspect
119
+ end
120
+
121
+
113
122
  get '/d*' do
114
123
  erb :debug
115
124
  end
@@ -156,13 +165,19 @@ private
156
165
  def preprocess_opts( opts )
157
166
  ### special case for input opt
158
167
  ## always default to gfm (github-flavored markdown) for now
159
-
168
+
160
169
  input = opts.delete( 'input' ) || 'GFM'
170
+
161
171
  if ['classic', 'std', 'standard', 'kramdown' ].include?( input.downcase )
162
172
  ## skip; "pseudo" input options map to no (zero) standard/classic input
173
+ elsif ['gfm'].include?( input.downcase )
174
+ ## note: GFM **MUST** be uppercase (gets converted to a matching ruby parser class)
175
+ opts[ 'input' ] = 'GFM'
176
+ ## in gfm mode (auto-)add hard_wrap = false unless set
177
+ opts['hard_wrap'] = false if opts['hard_wrap'].nil?
163
178
  else
164
179
  opts[ 'input' ] = input
165
- end
180
+ end
166
181
 
167
182
  puts "opts (preprocessed/effective):"
168
183
  pp opts
@@ -4,9 +4,10 @@
4
4
 
5
5
  ### Heading 3
6
6
 
7
- Welcome to [Markdown](/). We hope you **really** enjoy using this.
7
+ Welcome to the [kramdown Online Editor](/). We hope you **really** enjoy using this.
8
8
 
9
- Just type some [markdown](http://en.wikipedia.org/wiki/Markdown) on the left and see it on the right. *Simple as that.*
9
+ Just type some [markdown](http://en.wikipedia.org/wiki/Markdown)
10
+ on the left and see it on the right. *Simple as that.*
10
11
 
11
12
  > Quote goes here.
12
13
 
@@ -11,6 +11,11 @@
11
11
  text-decoration: underline;
12
12
  }
13
13
 
14
+ .markdown a:hover {
15
+ background-color: gold;
16
+ }
17
+
18
+
14
19
  .markdown em {
15
20
  background-color: #fffeca;
16
21
  padding: 0 0.08em;
@@ -1,15 +1,26 @@
1
1
  body {
2
2
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
3
3
 
4
+
4
5
  a, a:visited {
5
- color: #8B0000;
6
+ color: black; /* was #8B0000; */
6
7
  text-decoration: none; }
7
8
 
8
9
  a:hover {
9
- color: #8B0000;
10
- background-color: gold;
10
+ color: black; /* was #8B0000; */
11
11
  text-decoration: underline; }
12
12
 
13
+ .header .title a,
14
+ .header .title a:visited {
15
+ text-decoration: none;
16
+ }
17
+
18
+ .footer {
19
+ margin: 10px;
20
+ }
21
+
22
+
23
+
13
24
  .params {
14
25
  color: green;
15
26
  font-style: italic;
@@ -3,7 +3,7 @@
3
3
  module KramdownService
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 2
6
+ MINOR = 3
7
7
  PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
@@ -25,3 +25,14 @@
25
25
  request.ip <%= request.ip %>
26
26
  </pre>
27
27
 
28
+
29
+ <h4>kramdown opts</h4>
30
+
31
+ <%
32
+ doc = Kramdown::Document.new( '', preprocess_opts( params_to_opts( params )) )
33
+ %>
34
+
35
+ <pre>
36
+ <%= JSON.pretty_generate( doc.options ) %>
37
+ </pre>
38
+
@@ -1,6 +1,33 @@
1
1
 
2
2
  <%= erb :'_editor_setup' %>
3
3
 
4
+ <table width="100%">
5
+ <tr>
6
+ <td>
7
+
8
+
9
+ <span>
10
+ Use <select id='note-lib'></select>
11
+ </span>
12
+
13
+ <br>
14
+ <a id='output-update' href='#'>[ Update ]</a>
15
+
16
+ <!-- nb: div will break/start new line -->
17
+ <div id='output-loading'></div>
18
+
19
+ </td>
20
+
21
+ <td>
22
+ <div style="font-size: 80%;">
23
+ Options: <br>
24
+ <a id='input-toggle' href='#'>[ Use White Color Theme ]</a>
25
+ <a id='output-toggle' href='#'>[ Show HTML ]</a>
26
+ </div>
27
+ </td>
28
+ <div>
29
+
30
+
4
31
 
5
32
  <table width='100%'>
6
33
  <colgroup>
@@ -24,24 +51,4 @@
24
51
 
25
52
  </td>
26
53
  </tr>
27
- <tr>
28
- <td>
29
- <!-- first column -->
30
-
31
- <span>
32
- Use <select id='note-lib'></select>
33
- </span>
34
-
35
- <a id='output-update' href='#'>[ Update ]</a>
36
- <a id='input-toggle' href='#'>[ Use White Color Theme ]</a>
37
-
38
- <!-- nb: div will break/start new line -->
39
- <div id='output-loading'></div>
40
- </td>
41
- <td style='vertical-align: top;'>
42
- <!-- second column -->
43
- <a id='output-toggle' href='#'>[ Show HTML ]</a>
44
-
45
- </td>
46
- </tr>
47
54
  </table>
@@ -14,7 +14,7 @@
14
14
  <li><b>text</b> - <em>Required</em> string - The markdown text to render</li>
15
15
  </ul>
16
16
  <ul>
17
- <li><b>to</b> - <em>Optional</em> html|latex string - The format to use</li>
17
+ <li><b>to</b> - <em>Optional</em> string - The format to use e.g. html|latex</li>
18
18
  </ul>
19
19
 
20
20
 
@@ -1,6 +1,8 @@
1
1
  <div class='version'>
2
2
  <a href="http://groups.google.com/group/wwwmake">Questions? Comments?</a> |
3
- <a href="https://github.com/writekit/kramdown-service">kramdown-service/<%= KramdownService::VERSION %></a> using
3
+ <span>
4
+ <a href="https://github.com/writekit/kramdown-service">kramdown-service/<%= KramdownService::VERSION %></a> using
5
+ </span>
4
6
  <a href="https://github.com/gettalong/kramdown">kramdown/<%= Kramdown::VERSION %></a> -
5
7
  <span>Ruby/<%= "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}/#{RUBY_PLATFORM})" %> on</span>
6
8
  <span>Sinatra/<%= Sinatra::VERSION %> (<%= ENV['RACK_ENV'] %>)</span>
@@ -3,14 +3,6 @@
3
3
  <%= erb :'_editor' %>
4
4
 
5
5
 
6
- <%= erb :'_libs' %>
7
-
8
-
9
- <%= erb :'_service' %>
10
-
11
-
12
- <%= erb :'_about' %>
13
-
14
6
  <!--
15
7
  <hr>
16
8
 
@@ -9,9 +9,29 @@
9
9
  </head>
10
10
  <body>
11
11
 
12
+
13
+ <table width="100%" class="header">
14
+ <tr>
15
+ <td class="title">
16
+ <h1><a href="/">kramdown Online Editor</a></h1>
17
+ </td>
18
+ <td align="right">
19
+ <a href="/service">HTTP JSON API Service</a> •
20
+ <a href="https://github.com/writekit/kramdown-service">About</a>
21
+ </td>
22
+ </tr>
23
+ </table>
24
+
25
+
12
26
  <%= yield %>
13
27
 
28
+
29
+ <div class="footer" align="center">
30
+ Brought to you by <a href="http://manuscripts.github.io">Manuscripts</a> and friends.
31
+ </div>
32
+
14
33
  <%= erb :'_version' %>
15
34
 
35
+
16
36
  </body>
17
37
  </html>
@@ -1,7 +1,6 @@
1
1
 
2
2
  <%= erb :'_service' %>
3
3
 
4
- <%= erb :'_libs_service' %>
5
4
 
6
5
  <!--
7
6
  <hr>
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # minitest setup
4
+ require 'minitest/autorun'
5
+
6
+
7
+ ## our own code
8
+ require 'kramdown/service'
9
+
10
+
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_babelmark.rb
6
+
7
+
8
+ ENV['RACK_ENV'] = 'test' ## move to helper - why? why not??
9
+
10
+
11
+ require 'helper'
12
+
13
+ require 'rack/test' ## move to helper - why? why not??
14
+
15
+
16
+ class TestBabelmark < MiniTest::Test
17
+ include Rack::Test::Methods
18
+
19
+ def app
20
+ Kramdown::Service
21
+ end
22
+
23
+ def test_hello_world
24
+ get '/babelmark', { text: 'Hello, World!' }
25
+
26
+ assert last_response.ok?
27
+ assert_equal 'application/json', last_response.headers['Content-Type']
28
+
29
+ data = JSON.parse( last_response.body )
30
+ pp data
31
+
32
+ html = "<p>Hello, World!</p>\n"
33
+
34
+ assert_equal 'kramdown', data['name']
35
+ assert_equal Kramdown::VERSION, data['version']
36
+ assert_equal html, data['html']
37
+
38
+ end # method test_hello_world
39
+
40
+ def test_nil
41
+
42
+ get '/babelmark'
43
+
44
+ assert last_response.ok?
45
+ assert_equal 'application/json', last_response.headers['Content-Type']
46
+
47
+ data = JSON.parse( last_response.body )
48
+ pp data
49
+
50
+ html ="\n" # note: empty string w/ kramdown becomes empty string w/ newline
51
+
52
+ assert_equal 'kramdown', data['name']
53
+ assert_equal Kramdown::VERSION, data['version']
54
+ assert_equal html, data['html']
55
+ end # method test_nil
56
+
57
+
58
+ end # class TestBabelmark
59
+
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_kramdown.rb
6
+
7
+
8
+
9
+ require 'helper'
10
+
11
+
12
+ class TestKramdown < MiniTest::Test
13
+
14
+
15
+ def test_kramdown
16
+
17
+ text = 'Hello, World!'
18
+
19
+ doc = Kramdown::Document.new( text )
20
+
21
+ puts "options:"
22
+ pp doc.options
23
+
24
+ html = "<p>Hello, World!</p>\n"
25
+ latex = "Hello, World!\n\n"
26
+
27
+ assert_equal html, doc.to_html
28
+ assert_equal latex, doc.to_latex
29
+ end # method test_kramdown
30
+
31
+
32
+ def test_gfm_w_rouge
33
+
34
+ text = "A Line.\nAnother Line.\n"
35
+
36
+ doc = Kramdown::Document.new( text,
37
+ input: 'GFM',
38
+ hard_wrap: false,
39
+ syntax_highlighter: 'rouge' )
40
+
41
+ puts "options:"
42
+ pp doc.options
43
+
44
+ html = "<p>A Line.\nAnother Line.</p>\n"
45
+
46
+ pp doc.to_html
47
+
48
+ assert_equal html, doc.to_html
49
+ end # method test_gfm_w_rouge
50
+
51
+
52
+
53
+ end # class TestKramdown
54
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_markdown.rb
6
+
7
+
8
+ ENV['RACK_ENV'] = 'test' ## move to helper - why? why not??
9
+
10
+
11
+ require 'helper'
12
+
13
+ require 'rack/test' ## move to helper - why? why not??
14
+
15
+
16
+ class TestMarkdown < MiniTest::Test
17
+ include Rack::Test::Methods
18
+
19
+ def app
20
+ Kramdown::Service
21
+ end
22
+
23
+ def test_hello_world
24
+ get '/markdown', { text: 'Hello, World!' }
25
+
26
+ assert last_response.ok?
27
+ assert_equal 'text/html;charset=utf-8', last_response.headers['Content-Type']
28
+
29
+ pp last_response.body
30
+
31
+ html = "<p>Hello, World!</p>\n"
32
+ assert_equal html, last_response.body
33
+ end # method test_hello_world
34
+
35
+
36
+ def test_latex_hello_world
37
+ get '/markdown', { text: 'Hello, World!', to: 'latex' }
38
+
39
+ assert last_response.ok?
40
+ assert_equal 'text/latex;charset=utf-8', last_response.headers['Content-Type']
41
+
42
+ pp last_response.body
43
+
44
+ latex = "Hello, World!\n\n"
45
+ assert_equal latex, last_response.body
46
+ end # method test_latex_hello_world
47
+
48
+
49
+
50
+ end # class TestMarkdown
51
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-17 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -107,13 +107,10 @@ files:
107
107
  - lib/kramdown/service/public/js/markdown.note.js
108
108
  - lib/kramdown/service/public/style.css
109
109
  - lib/kramdown/service/version.rb
110
- - lib/kramdown/service/views/_about.erb
111
110
  - lib/kramdown/service/views/_debug.erb
112
111
  - lib/kramdown/service/views/_editor.erb
113
112
  - lib/kramdown/service/views/_editor_head.erb
114
113
  - lib/kramdown/service/views/_editor_setup.erb
115
- - lib/kramdown/service/views/_libs.erb
116
- - lib/kramdown/service/views/_libs_service.erb
117
114
  - lib/kramdown/service/views/_service.erb
118
115
  - lib/kramdown/service/views/_version.erb
119
116
  - lib/kramdown/service/views/debug.erb
@@ -121,6 +118,10 @@ files:
121
118
  - lib/kramdown/service/views/index.erb
122
119
  - lib/kramdown/service/views/layout.erb
123
120
  - lib/kramdown/service/views/service.erb
121
+ - test/helper.rb
122
+ - test/test_babelmark.rb
123
+ - test/test_kramdown.rb
124
+ - test/test_markdown.rb
124
125
  homepage: https://github.com/writekit/kramdown-service
125
126
  licenses:
126
127
  - Public Domain
@@ -1,26 +0,0 @@
1
-
2
-
3
- <h3>Kramdown Service Gem / About</h3>
4
-
5
- <p><b>
6
- What's the <code>kramdown-service</code> gem?
7
- </b>
8
- </b>
9
-
10
- The kramdown HTTP JSON API service lets you
11
- convert markdown to HTML or LaTeX.
12
-
13
- <a href='https://github.com/writekit/kramdown-service'>Find out more »</a>
14
- </p>
15
-
16
-
17
- <p>
18
- <b>Questions? Comments?</b>
19
- Send them along to the <a href='http://groups.google.com/group/wwwmake'>wwwmake forum/mailing list</a>.
20
- Thanks!
21
- </p>
22
-
23
- <p><b>License</b>
24
- The kramdown-service scripts are dedicated to the public domain.
25
- Use it as you please with no restrictions whatsoever.
26
- </p>
@@ -1,10 +0,0 @@
1
-
2
- <h3>Kramdown Library</h3>
3
-
4
- <table>
5
- <tr>
6
- <td>kramdown</td>
7
- <td><%= Kramdown::VERSION %></td>
8
- <td><!-- defaults to be done --></td>
9
- </tr>
10
- </table>
@@ -1,24 +0,0 @@
1
-
2
- <h3>Kramdown Library / Live Examples</h3>
3
-
4
- <table class='api'>
5
- <tr>
6
- <td>kramdown</td>
7
- <td> / <%= Kramdown::VERSION %></td>
8
- <td> -
9
- <code>GET
10
- <a href='view-source:<%= url("/markdown?text=Hello+World!") %>'>
11
- /markdown?text=<em>Hello+World!</em>
12
- </a>
13
- </code>
14
- </td>
15
- <td>
16
- <code>&bull; GET
17
- <a href='<%= url("/babelmark?text=Hello+World!") %>'>
18
- /babelmark?text=<em>Hello+World!</em>
19
- </a>
20
- </code>
21
- </td>
22
- </tr>
23
- </table>
24
-