kramdown-service 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -5
- data/README.md +2 -10
- data/Rakefile +2 -1
- data/lib/kramdown/service.rb +115 -57
- data/lib/kramdown/service/docs/welcome.md +3 -3
- data/lib/kramdown/service/public/js/kramdown.js +64 -0
- data/lib/kramdown/service/public/js/markdown.note.js +51 -13
- data/lib/kramdown/service/version.rb +2 -2
- data/lib/kramdown/service/views/_about.erb +4 -1
- data/lib/kramdown/service/views/_editor_head.erb +1 -4
- data/lib/kramdown/service/views/_libs_service.erb +2 -2
- data/lib/kramdown/service/views/_service.erb +35 -6
- metadata +17 -7
- data/lib/kramdown/service/public/js/lib3rd/pagedown.js +0 -1412
- data/lib/kramdown/service/public/js/lib3rd/showdown.min.js +0 -62
- data/lib/kramdown/service/public/js/markdown.api.js +0 -99
- data/lib/kramdown/service/public/js/markdown.lib.js +0 -82
- data/lib/kramdown/service/public/note.html +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065d0c7fe06c3a2639983020f3a36bf20cf91850
|
4
|
+
data.tar.gz: c93f8547c5059f71d79fbb9bbaae3e2da700026a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f55ec265130e94db23e8a3fcee6a5914ac2b270649476f8084ea4e1bb4be6be44b3a176bb78ea68fabb69c0ffd8663764e813dda3b3b729cc0ad6ace42faff3b
|
7
|
+
data.tar.gz: 4d5137c11efb8524a441427803037000cd94e7b5f0c3cd7b63afac9dfa8d931bff388bc07323861001354399bbfc952dcceca43c66a014f5c6fb22804c64b863
|
data/Manifest.txt
CHANGED
@@ -7,13 +7,9 @@ lib/kramdown/service/docs/welcome.md
|
|
7
7
|
lib/kramdown/service/public/css/markdown/note.css
|
8
8
|
lib/kramdown/service/public/css/markdown/themes/basic.css
|
9
9
|
lib/kramdown/service/public/i/dots-white.gif
|
10
|
+
lib/kramdown/service/public/js/kramdown.js
|
10
11
|
lib/kramdown/service/public/js/lib3rd/jquery-2.0.1.min.js
|
11
|
-
lib/kramdown/service/public/js/lib3rd/pagedown.js
|
12
|
-
lib/kramdown/service/public/js/lib3rd/showdown.min.js
|
13
|
-
lib/kramdown/service/public/js/markdown.api.js
|
14
|
-
lib/kramdown/service/public/js/markdown.lib.js
|
15
12
|
lib/kramdown/service/public/js/markdown.note.js
|
16
|
-
lib/kramdown/service/public/note.html
|
17
13
|
lib/kramdown/service/public/style.css
|
18
14
|
lib/kramdown/service/version.rb
|
19
15
|
lib/kramdown/service/views/_about.erb
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
Try the `markdown` HTTP (JSON) API running
|
12
12
|
on Heroku [`trykramdown.herokuapp.com`](http://trykramdown.herokuapp.com).
|
13
13
|
|
14
|
+
|
14
15
|
Example 1 - Converting to Hypertext (HTML):
|
15
16
|
|
16
17
|
GET /markdown?text=Hello+World!
|
@@ -20,20 +21,11 @@ Example 1 - Converting to Hypertext (HTML):
|
|
20
21
|
|
21
22
|
Example 2 - Converting to LaTeX:
|
22
23
|
|
23
|
-
GET /markdown?text=Hello+World!&
|
24
|
+
GET /markdown?text=Hello+World!&to=latex
|
24
25
|
|
25
26
|
Hello World!
|
26
27
|
|
27
|
-
<!-- todo/check:
|
28
|
-
- use format or output ??? for parameter
|
29
|
-
-->
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
## Dependencies / Building Blocks
|
34
28
|
|
35
|
-
[Markdown Note](https://github.com/writekit/markdown-note) - Another simple single-page, server-less Markdown editor
|
36
|
-
in JavaScript & Hypertext.
|
37
29
|
|
38
30
|
|
39
31
|
## License
|
data/Rakefile
CHANGED
data/lib/kramdown/service.rb
CHANGED
@@ -8,17 +8,15 @@
|
|
8
8
|
# run Kramdown::Service
|
9
9
|
|
10
10
|
|
11
|
+
require 'json'
|
12
|
+
|
13
|
+
|
11
14
|
# 3rd party libs/gems
|
12
15
|
|
13
16
|
require 'sinatra/base'
|
14
17
|
|
15
18
|
require 'kramdown'
|
16
19
|
|
17
|
-
|
18
|
-
# require 'logutils'
|
19
|
-
# require 'logutils/activerecord'
|
20
|
-
|
21
|
-
|
22
20
|
# our own code
|
23
21
|
|
24
22
|
require 'kramdown/service/version' # let version always go first
|
@@ -44,61 +42,66 @@ class Service < Sinatra::Base
|
|
44
42
|
##############################################
|
45
43
|
# Controllers / Routing / Request Handlers
|
46
44
|
|
47
|
-
def welcome_markdown
|
48
|
-
## todo: rotate welcome / use random number for index
|
49
|
-
# place markdown docs in server/docs
|
50
|
-
text = File.read( "#{KramdownService.root}/lib/markdown/service/docs/welcome.md" )
|
51
|
-
text
|
52
|
-
end
|
53
|
-
|
54
45
|
|
55
46
|
get %r{/(service|services|srv|s)$} do
|
47
|
+
## just a "live" docu page
|
56
48
|
erb :service
|
57
49
|
end
|
58
50
|
|
59
|
-
get %r{/(note|notes|n)$} do
|
60
|
-
# for testing/debugging use copied sources 1:1 from markdown-notepad repo
|
61
|
-
redirect '/note.html'
|
62
|
-
end
|
63
|
-
|
64
51
|
get %r{/(editor|edit|ed|e)$} do
|
65
|
-
#
|
66
|
-
|
67
|
-
|
52
|
+
# note: allow optional params e.g. text and opts
|
53
|
+
## note: for now only html supported on get form/url params
|
54
|
+
text = params.delete('text') || welcome_markdown
|
55
|
+
to = params.delete('to') || 'html' ## optional - default to html
|
56
|
+
opts = params_to_opts( params )
|
57
|
+
|
58
|
+
@welcome_markdown = text
|
59
|
+
@welcome_html = text_to_html( text, opts )
|
68
60
|
|
69
61
|
erb :editor
|
70
62
|
end
|
71
63
|
|
72
64
|
get '/' do
|
73
|
-
|
74
|
-
|
65
|
+
# note: allow optional params e.g. text and opts
|
66
|
+
## note: for now only html supported on get form/url params
|
67
|
+
text = params.delete('text') || welcome_markdown
|
68
|
+
to = params.delete('to') || 'html' ## optional - default to html
|
69
|
+
opts = params_to_opts( params )
|
70
|
+
|
71
|
+
@welcome_markdown = text
|
72
|
+
@welcome_html = text_to_html( text, opts )
|
75
73
|
|
76
74
|
erb :index
|
77
75
|
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
77
|
+
# return hypertext (html) ## allow /markdown or /m
|
78
|
+
get %r{/(markdown|m)$} do
|
79
|
+
|
80
|
+
text = params.delete('text')
|
81
|
+
to = params.delete('to') || 'html' ## optional - default to html
|
82
|
+
opts = params_to_opts( params )
|
83
|
+
|
84
|
+
if ['latex','l','tex'].include?( to.downcase )
|
85
|
+
content_type 'text/latex'
|
86
|
+
text_to_latex( text, opts )
|
87
|
+
else ## assume html (default)
|
88
|
+
content_type 'text/html'
|
89
|
+
text_to_html( text, opts )
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
93
|
|
94
94
|
|
95
95
|
# return babelmark2/dingus-style json
|
96
|
-
|
97
|
-
|
96
|
+
# return html wrapped in json (follows babelmark2 dingus service api)
|
97
|
+
# note: defaults (uses) GFM - github-flavored markdown mode/input
|
98
|
+
# note: only supports html for now (e.g. does NOT support to=html|latex option etc.)
|
99
|
+
get '/babelmark' do
|
100
|
+
text = params.delete('text')
|
98
101
|
|
99
102
|
data = {
|
100
|
-
name:
|
101
|
-
html:
|
103
|
+
name: 'kramdown',
|
104
|
+
html: Kramdown::Document.new( text, input: 'GFM' ).to_html,
|
102
105
|
version: Kramdown::VERSION
|
103
106
|
}
|
104
107
|
|
@@ -106,34 +109,89 @@ class Service < Sinatra::Base
|
|
106
109
|
end
|
107
110
|
|
108
111
|
|
109
|
-
|
110
|
-
|
111
|
-
content_type 'text/html'
|
112
|
-
markdownify( params )
|
112
|
+
get '/d*' do
|
113
|
+
erb :debug
|
113
114
|
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def welcome_markdown
|
120
|
+
## todo: rotate welcome / use random number for index
|
121
|
+
# place markdown docs in server/docs
|
122
|
+
text = File.read( "#{KramdownService.root}/lib/kramdown/service/docs/welcome.md" )
|
123
|
+
text
|
124
|
+
end
|
125
|
+
|
126
|
+
def params_to_opts( params )
|
127
|
+
## convert (web form) params to kramdown (ruby) opts
|
128
|
+
|
129
|
+
puts "params : #{params.class.name}:"
|
130
|
+
pp params
|
131
|
+
|
132
|
+
opts = {}
|
133
|
+
|
134
|
+
## map true/false strings to boolean
|
135
|
+
params.each do |k,v|
|
136
|
+
puts " k: >#{k}< : #{k.class.name}, v: >#{v}< : #{v.class.name}"
|
137
|
+
|
138
|
+
## skip "built-in" sinatra "internal" params
|
139
|
+
## - todo - use splice and whitelist instead - why? why not?
|
140
|
+
next if ['splat', 'captures'].include?( k )
|
118
141
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
142
|
+
if v.is_a?( String ) && ['t', 'true'].include?( v.downcase )
|
143
|
+
opts[ k ] = true
|
144
|
+
elsif v.is_a?( String ) && ['f', 'false'].include?( v.downcase )
|
145
|
+
opts[ k ] = false
|
146
|
+
else
|
147
|
+
opts[ k ] = v
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
opts
|
126
152
|
end
|
127
153
|
|
128
154
|
|
129
|
-
|
130
|
-
|
155
|
+
def preprocess_opts( opts )
|
156
|
+
### special case for input opt
|
157
|
+
## always default to gfm (github-flavored markdown) for now
|
158
|
+
|
159
|
+
input = opts.delete( 'input' ) || 'GFM'
|
160
|
+
if ['classic', 'std', 'standard', 'kramdown' ].include?( input.downcase )
|
161
|
+
## skip; "pseudo" input options map to no (zero) standard/classic input
|
162
|
+
else
|
163
|
+
opts[ 'input' ] = input
|
164
|
+
end
|
165
|
+
|
166
|
+
puts "opts (preprocessed/effective):"
|
167
|
+
pp opts
|
168
|
+
|
169
|
+
opts
|
170
|
+
end
|
171
|
+
|
172
|
+
def text_to_html( text, opts={} )
|
173
|
+
puts "text_to_html:"
|
174
|
+
pp text
|
175
|
+
pp opts
|
176
|
+
|
177
|
+
opts = preprocess_opts( opts ) ## defaults to GFM input etc.
|
178
|
+
|
179
|
+
Kramdown::Document.new( text, opts ).to_html
|
180
|
+
end
|
181
|
+
|
182
|
+
def text_to_latex( text, opts={} )
|
183
|
+
puts "text_to_latex:"
|
184
|
+
pp text
|
185
|
+
pp opts
|
186
|
+
|
187
|
+
opts = preprocess_opts( opts ) ## defaults to GFM input etc.
|
188
|
+
|
189
|
+
Kramdown::Document.new( text, opts ).to_latex
|
131
190
|
end
|
132
191
|
|
133
192
|
|
134
193
|
### helper for json or jsonp response (depending on callback para)
|
135
194
|
|
136
|
-
private
|
137
195
|
def json_or_jsonp( json )
|
138
196
|
callback = params.delete('callback')
|
139
197
|
response = ''
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
var kramdown_new = function( opts ) {
|
4
|
+
|
5
|
+
var settings; // NB: defaults + opts merged => settings
|
6
|
+
|
7
|
+
var defaults = {
|
8
|
+
api_url: 'http://trykramdown.herokuapp.com/markdown'
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
function _debug( msg )
|
13
|
+
{
|
14
|
+
if(window.console && window.console.log )
|
15
|
+
window.console.log( "[debug] " + msg );
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
function _init( opts ) {
|
20
|
+
settings = $.extend( {}, defaults, opts );
|
21
|
+
}
|
22
|
+
|
23
|
+
_init( opts );
|
24
|
+
|
25
|
+
|
26
|
+
function _convert( text, more_params, handler )
|
27
|
+
{
|
28
|
+
var params = $.extend( { text: text }, more_params ); // merge in more params; use text for required param
|
29
|
+
|
30
|
+
$.get( settings.api_url, params, function( data ) {
|
31
|
+
handler( data );
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
function convert_to_html( text, handler ) {
|
36
|
+
// note: make gfm (github-flavored markdown) the default parser
|
37
|
+
_convert( text, { to: 'html' }, handler );
|
38
|
+
}
|
39
|
+
|
40
|
+
function convert_to_html_with_syntax_highlighter( text, handler ) {
|
41
|
+
// note: make gfm (github-flavored markdown) the default parser
|
42
|
+
_convert( text, { to: 'html', syntax_highlighter: 'rouge' }, handler );
|
43
|
+
}
|
44
|
+
|
45
|
+
function convert_to_html_with_classic( text, handler ) {
|
46
|
+
// note: use "classic" "standard" kramdown parser/reader
|
47
|
+
_convert( text, { to: 'html', input: 'classic' }, handler );
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
function convert_to_latex( text, handler ) {
|
53
|
+
_convert( text, { to: 'latex' }, handler );
|
54
|
+
}
|
55
|
+
|
56
|
+
return {
|
57
|
+
convert_to_html: convert_to_html,
|
58
|
+
convert_to_html_with_syntax_highlighter: convert_to_html_with_syntax_highlighter,
|
59
|
+
convert_to_html_with_classic: convert_to_html_with_classic,
|
60
|
+
convert_to_latex: convert_to_latex
|
61
|
+
}
|
62
|
+
|
63
|
+
} // fn kramdown_new
|
64
|
+
|
@@ -4,15 +4,28 @@ var markdown_note_new = function( opts ) {
|
|
4
4
|
|
5
5
|
// use module pattern (see JavaScript - The Good Parts)
|
6
6
|
|
7
|
+
|
8
|
+
var getUrl = window.location;
|
9
|
+
// note: host includes hostname + port; yes!
|
10
|
+
var baseUrl = getUrl.protocol + "//" + getUrl.host;
|
11
|
+
|
12
|
+
console.log( window.location );
|
13
|
+
console.log( baseUrl );
|
14
|
+
|
15
|
+
|
16
|
+
var kramdown = kramdown_new( { api_url: baseUrl + '/markdown' } );
|
17
|
+
// e.g. http://localhost:9292/markdown or http://trykramdown.herokuapp.com/markdown
|
18
|
+
// kramdown api service / engine (see kramdown.js)
|
19
|
+
|
7
20
|
var engines = [
|
8
|
-
{ name: '
|
9
|
-
|
10
|
-
{ name: '
|
11
|
-
|
12
|
-
{ name: '
|
13
|
-
|
14
|
-
{ name: '
|
15
|
-
|
21
|
+
{ name: 'kramdown in GitHub-Flavored Markdown (GFM) Mode', format: 'HTML',
|
22
|
+
markdown: kramdown.convert_to_html },
|
23
|
+
{ name: 'kramdown in GitHub-Flavored Markdown (GFM) Mode w/ Syntax Highlighter (rouge)', format: 'HTML',
|
24
|
+
markdown: kramdown.convert_to_html_with_syntax_highlighter },
|
25
|
+
{ name: 'kramdown in "Classic" Mode', format: 'HTML',
|
26
|
+
markdown: kramdown.convert_to_html_with_classic },
|
27
|
+
{ name: 'kramdown in GitHub-Flavored Markdown (GFM) Mode', format: 'LaTeX',
|
28
|
+
markdown: kramdown.convert_to_latex }
|
16
29
|
];
|
17
30
|
|
18
31
|
var welcome = {
|
@@ -69,7 +82,29 @@ var markdown_note_new = function( opts ) {
|
|
69
82
|
|
70
83
|
var show_html = false;
|
71
84
|
var use_white_color_theme = false;
|
85
|
+
var show_latex = false;
|
86
|
+
|
87
|
+
function show_latex_output() {
|
88
|
+
show_latex = true;
|
72
89
|
|
90
|
+
$output.hide();
|
91
|
+
$output_toggle.hide(); // hide toggle show html button
|
92
|
+
$output_source.show();
|
93
|
+
}
|
94
|
+
|
95
|
+
function restore_html_output() {
|
96
|
+
// restore output view to before entering "latex" mode
|
97
|
+
if (show_latex == true) {
|
98
|
+
show_latex = false;
|
99
|
+
|
100
|
+
$output_toggle.show();
|
101
|
+
if( !show_html ) { // switch back in "preview" mode ?
|
102
|
+
$output_source.hide();
|
103
|
+
$output.show();
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
73
108
|
function toggle_output()
|
74
109
|
{
|
75
110
|
show_html = !show_html;
|
@@ -112,13 +147,17 @@ var markdown_note_new = function( opts ) {
|
|
112
147
|
|
113
148
|
var engine = settings.engines[engine_index];
|
114
149
|
|
115
|
-
|
116
|
-
$output_loading.show();
|
150
|
+
$output_loading.show(); // show progress bar/spinner
|
117
151
|
|
118
152
|
engine.markdown( text, function( html ) {
|
119
153
|
$output.html( html );
|
120
154
|
$output_source.html( html );
|
121
155
|
$output_loading.hide();
|
156
|
+
|
157
|
+
if( engine.format == 'LaTeX' ) // for latex always show source (only)
|
158
|
+
show_latex_output();
|
159
|
+
else
|
160
|
+
restore_html_output();
|
122
161
|
});
|
123
162
|
}
|
124
163
|
|
@@ -126,8 +165,7 @@ var markdown_note_new = function( opts ) {
|
|
126
165
|
function _init( opts )
|
127
166
|
{
|
128
167
|
settings = $.extend( {}, defaults, opts );
|
129
|
-
|
130
|
-
|
168
|
+
|
131
169
|
$output = $( settings.output );
|
132
170
|
$output_source = $( settings.output_source );
|
133
171
|
$output_update = $( settings.output_update );
|
@@ -157,7 +195,7 @@ var markdown_note_new = function( opts ) {
|
|
157
195
|
if( index == 0 ) {
|
158
196
|
markdown_opts += 'selected="selected"'
|
159
197
|
}
|
160
|
-
markdown_opts += '>' + engine.name + '</option>';
|
198
|
+
markdown_opts += '>' + engine.format + ' - ' + engine.name + '</option>';
|
161
199
|
|
162
200
|
_debug( 'add markdown engine [' + index + ']: ' + engine.name );
|
163
201
|
});
|