Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract the web API access into its own method

  • Loading branch information...
commit 85df899d24e561f78472eae00d1fbd823fcda985 1 parent 113affd
@marcoow marcoow authored
Showing with 11 additions and 7 deletions.
  1. +11 −7 lib/simplabs/highlight.rb
View
18 lib/simplabs/highlight.rb
@@ -1,4 +1,6 @@
require 'cgi'
+require 'net/http'
+require 'uri'
module Simplabs
@@ -105,13 +107,7 @@ def self.highlight(language, code)
language = get_language_sym(language)
return CGI.escapeHTML(code) unless language
if Simplabs::Highlight.use_web_api
- require 'net/http'
- require 'uri'
- request = Net::HTTP.post_form(URI.parse(WEB_API_URL), {
- 'lang' => language,
- 'code' => code
- })
- request.body.gsub(/\A\<div class=\"highlight\"\>\<pre\>/, '').gsub(/\n\<\/pre\>\<\/div\>\n/, '')
+ highlight_with_web_api(language, code)
else
Simplabs::Highlight::PygmentsWrapper.new(code, language).highlight
end
@@ -165,6 +161,14 @@ def highlight(language, code = nil, &block)
private
+ def self.highlight_with_web_api(language, code)
+ request = Net::HTTP.post_form(URI.parse(WEB_API_URL), {
+ 'lang' => language,
+ 'code' => code
+ })
+ request.body.gsub(/\A\<div class=\"highlight\"\>\<pre\>/, '').gsub(/\n\<\/pre\>\<\/div\>\n/, '')
+ end
+
def self.get_language_sym(name)
SUPPORTED_LANGUAGES.each_pair do |key, value|
return key if value.any? { |lang| lang == name.to_s }
Please sign in to comment.
Something went wrong with that request. Please try again.