2

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.gs­ub!(/\[([\­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?

sawa
  • 165,429
  • 45
  • 277
  • 381
HotelCalifornia
  • 317
  • 5
  • 16

1 Answers1

3

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!

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110