I'm writing an extension for Redcarpet for a Jekyll-powered website. I want to use {x|y} as a tag in markdown that evaluates to the HTML <ruby> tag (and its associates). I wrote this class as per Jekyll's guide, Redcarpet's guide, and this guide on how to do so:
class Jekyll::Converters::Markdown::HotelDown < Redcarpet::Render::HTML
def preprocess(doc)
s = "<ruby><rb>\\1</rb><rp>(</rp><rt>\\2</rt><rp>)</rp></ruby>"
doc.gsub!(/\[([\s\S]+)\|([\s\S]+)\]/, s)
doc
end
end
But, I seem to be getting a couple errors when I run bundle exec jekyll serve:
Configuration file: C:/Users/Alex/OneDrive/codes/hotelc.me/hotelc.me/_config.yml
plugin_manager.rb:58:in `require': HotelDown.rb:4: syntax error, unexpected tIDENTIFIER, expecting ')' (SyntaxError)
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
^
HotelDown.rb:4: syntax error, unexpected ')', expecting '='
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
^
It seems there's something wrong with my syntax (an extra space, missing parentheses, or something like that). Is there something I've missed?
Your code has some special characters which is causing this error:
syntax error, unexpected ')', expecting '='
doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s)
Replace your current code with this piece of code:
class Jekyll::Converters::Markdown::HotelDown < Redcarpet::Render::HTML
#Overriding the preprocess() function
def preprocess(doc)
s = "<ruby><rb>\\1</rb><rp>(</rp><rt>\\2</rt><rp>)</rp></ruby>"
doc.gsub!(/\[([\s\S]+)\|([\s\S]+)\]/, s)
doc
end
end
markdown = Redcarpet::Markdown.new(HotelDown)
and it should work!
Related
Does any one know why
saved ? redirect '/success' : erb :signup
Throws the following error:
syntax error, unexpected ':', expecting keyword_end
While this does not?
saved ? redirect('/success') : erb(:signup)
I'm attempting to create and use domino to abstract a login page
describe :index, :type => :request do
before do
visit '/'
blah_email_login('user1')
end
...
def blah_email_login(user)
Dom::Email_Link.find_by_name 'Mail'.click
....
end
module Dom
class Email_Link < Domino
selector 'a'
attribute :tab-label
end
here is the html
<a class="tab-label fz-xs accent " href="https://mail.blah.com/..." id="blah"><span class="tab-icon img-sprite"></span><em class="strong tab-link-txt y-link-1 " title="Mail">Mail</em></a>
The process cannot take a dash as indicated my the error I get pre run
C:\blah.rb:93:in `<class:Email_Link>': undefined local variable or method `label' for Dom::Email_Link:Class (NameError)
When I attempted to alter attribute to
attribute :'tab-label'
I got ...
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/domino-0.5.0/lib/domino.rb:114:in `class_eval': (eval):2: syntax error, unexpected '-', expecting ';' or '\n' (SyntaxError)
def tab-label
^
When I included escape characters
attribute :'tab\-label'
I got ...
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/domino-0.5.0/lib/domino.rb:114:in `class_eval': (eval):2: syntax error, unexpected $undefined, expecting ';' or '\n' (SyntaxError)
def tab\-label
^
(eval):4: syntax error, unexpected $undefined, expecting ']'
if value && self.class.callbacks[:tab\-label].is_a?(Proc)
The site I'm working with has many dashed class names, any ideas on how to work with that?
Try:
module Dom
class Email_Link < Domino
selector 'a'
attribute :'tab-label'
end
Update
Domino's default behavior is to replace _ in attribute names to - in class names (see here).
Therefore your attribute name should use underscore:
module Dom
class Email_Link < Domino
selector 'a'
attribute :tab_label
end
While running the RSPEC test as shown below im getting this error:
Using Accessor#strict_set for specs
SyntaxError: /home/sam/projects/logstash.king-foo.dev/ansible/roles/logstash/spec/syslog.rb:6: syntax error, unexpected kEND
end
^
load at org/jruby/RubyKernel.java:1101
(root) at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:1
each at org/jruby/RubyArray.java:1613
load_spec_files at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
load_spec_files at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896
run at /opt/logstash/vendor/bundle/jruby/1.9/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22
I tried messing around with the syntax but without success.
files = Dir['../configs/filter*.conf']
##configuration = String.new
files.sort.each.do |file|
##configuration << File.read(file)
end
describe "my first logstash rspec test", :if => RUBY_ENGINE == "jruby" do
extend LogStash::RSpec
config(##configuration)
... some code here ...
end
Does anybody know what i'm doing wrong?
Why do i get a syntax error for the end statement ander the ##configuration variable?
The error means there was an unexpected end in your code. Just simply replace the 3rd line with
files.sort.each do |file|
I optionally recommend you use { and } instead of do and end. The { and } are space-insensitive and you are less likely to receive an error than do and end.
I'm running into this syntax error with the below code and I can't figure out why ruby is complaining about it.
def user_list
server = Lumberg::Whm::Server.new(
host: "localhost",
hash: IO.read("/root/.accesshash")
)
results = server.account.list
accounts = result[:params][:acct].map {|a| a["user"] }
end
end
Syntax error is as follows:
# bundle exec bin/userscan
bin/userscan:3:in `require': /usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ':', expecting ')' (SyntaxError)
host: "localhost",
^
/usr/src/userscan/lib/userscan.rb:131: syntax error, unexpected ',', expecting kEND
/usr/src/userscan/lib/userscan.rb:133: syntax error, unexpected ')', expecting kEND
from bin/userscan:3
From what I know, the part it's complaining about -should- be okay. Obviously, the semi-colon is actually supposed to be there and the parenthesis should encompass the entirety of the two lines. I've played around with it a bit, but I just keep making it worse rather than better.
Any assistance with what I'm messing up here would be appreciated.
the syntax host: ".." is new to ruby 1.9. If you are using ruby 1.8, you must use the old syntax:
server = Lumberg::Whm::Server.new(
:host => "localhost",
:hash => IO.read("/root/.accesshash") )
any idea how I can pass correct argument to xpath? There must be something about how to use single/double quotes. When I use variable
parser_xpath_identificator = "'//table/tbody[#id=\"threadbits_forum_251\"]/tr'" gives me an incorrect value or
parser_xpath_identificator = "'//table/tbody[#id="threadbits_forum_251"]/tr'" gives me an error syntax error, unexpected tIDENTIFIER, expecting $end
require 'rubygems'
require 'mechanize'
parser_xpath_identificator = "'//table/tbody[#id=\"threadbits_forum_251\"]/tr'"
# parser_xpath_identificator = "'//table/tbody[#id="threadbits_forum_251"]/tr'"
#gives an error: syntax error, unexpected tIDENTIFIER, expecting $end
agent = WWW::Mechanize.new
page = agent.get("http://www.vbulletin.org/forum/index.php")
page = page.link_with(:text=>'vB4 General Discussions').click
puts "Page title: #{page.title}"
puts "\nfrom variable: #{page.parser.xpath(parser_xpath_identificator).length}"
puts "directly: #{page.parser.xpath('//table/tbody[#id="threadbits_forum_251"]/tr').length}"
In both cases you're nesting single-quotes directly inside double-quotes, which I don't think is correct. Try this:
parser_xpath_identificator = '//table/tbody[#id="threadbits_forum_251"]/tr'