2015-10-14 195 views
2

我正在为Jekyll供电的网站编写Redcarpet的扩展。我想在标记中使用{x|y}作为标记,评估为HTML <ruby>标记(及其关联)。我写了这个类按照Jekyll's guideRedcarpet's guidethis guide如何做到这一点:语法错误,意外的')',期待'='

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.gs­ub!(/\[([\­s\S]+)\|([­\s\S]+)\]/­, s) 
     doc 
    end 
end 

但是,我似乎得到了几个错误,当我运行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) 
                  ^

似乎有我的语法错了(额外的空间,缺少括号或类似的东西)。有什么我错过了吗?

回答

3

您的代码,这是造成此错误的一些特殊字符:

syntax error, unexpected ')', expecting '=' 
      doc.gs-ub!(/\[([\-s\S]+)\|([-\s\S]+)\]/-, s) 

用这段代码替换当前的代码:

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) 

,它应该工作!

+1

啊!当然:当我第一次写代码的时候,我不小心用日文键盘输入了一些字符。 – HotelCalifornia

+1

此外,我想知道堆栈跟踪中的那些破折号是什么......现在我知道了。谢谢! – HotelCalifornia

+0

非常欢迎:)很高兴它解决了您的问题。 –

相关问题