lib/kramdown/service.rb in kramdown-service-0.2.0 vs lib/kramdown/service.rb in kramdown-service-0.3.0
- old
+ new
@@ -76,16 +76,16 @@
end
# return hypertext (html) ## allow /markdown or /m
get %r{/(markdown|m)$} do
- text = params.delete('text')
+ text = params.delete('text') || '' ## if no text param supplied, use empty/blank string
to = params.delete('to') || 'html' ## optional - default to html
opts = params_to_opts( params )
if ['latex','l','tex'].include?( to.downcase )
- content_type 'text/latex'
+ content_type 'text/latex' ### todo: check if latex content_type exists?
text_to_latex( text, opts )
else ## assume html (default)
content_type 'text/html'
text_to_html( text, opts )
end
@@ -96,11 +96,11 @@
# return babelmark2/dingus-style json
# return html wrapped in json (follows babelmark2 dingus service api)
# note: defaults (uses) GFM - github-flavored markdown mode/input
# note: only supports html for now (e.g. does NOT support to=html|latex option etc.)
get '/babelmark' do
- text = params.delete('text')
+ text = params.delete('text') || '' ## if no text param supplied, use empty/blank string
data = {
name: 'kramdown',
html: Kramdown::Document.new( text, input: 'GFM' ).to_html,
version: Kramdown::VERSION
@@ -108,10 +108,19 @@
json_or_jsonp( data.to_json )
end
+ get %r{/(options|opts|o)$} do ## for debugging/testing "dump" options
+ content_type 'text/plain'
+
+ opts = preprocess_opts( params_to_opts( params ))
+ doc = Kramdown::Document.new( '', opts )
+ doc.options.inspect
+ end
+
+
get '/d*' do
erb :debug
end
@@ -154,16 +163,22 @@
def preprocess_opts( opts )
### special case for input opt
## always default to gfm (github-flavored markdown) for now
-
+
input = opts.delete( 'input' ) || 'GFM'
+
if ['classic', 'std', 'standard', 'kramdown' ].include?( input.downcase )
## skip; "pseudo" input options map to no (zero) standard/classic input
+ elsif ['gfm'].include?( input.downcase )
+ ## note: GFM **MUST** be uppercase (gets converted to a matching ruby parser class)
+ opts[ 'input' ] = 'GFM'
+ ## in gfm mode (auto-)add hard_wrap = false unless set
+ opts['hard_wrap'] = false if opts['hard_wrap'].nil?
else
opts[ 'input' ] = input
- end
+ end
puts "opts (preprocessed/effective):"
pp opts
opts