【问题标题】:syntax error, unexpected ')', expecting '='语法错误,意外 ')',期待 '='
【发布时间】:2015-10-14 03:51:15
【问题描述】:

我正在为基于 Jekyll 的网站编写 Redcarpet 扩展程序。我想使用{x|y} 作为markdown 中的一个标签,它评估为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)
                                                            ^

我的语法似乎有问题(多余的空格、缺少括号或类似的东西)。有什么我错过的吗?

【问题讨论】:

    标签: ruby markdown jekyll redcarpet


    【解决方案1】:

    您的代码有一些特殊字符导致此错误:

    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)
    

    它应该可以工作!

    【讨论】:

    • 啊!当然:当我第一次写代码时,我不小心用日文键盘输入了一些字符。
    • 另外,我想知道堆栈跟踪中的那些破折号是什么......现在我知道了。谢谢!
    猜你喜欢
    • 2017-09-12
    • 2019-12-06
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多