Tilt (kramdown) preventing ERB processing when rendering markdown

后端 未结 1 1892
再見小時候
再見小時候 2021-01-25 00:47

I am building a website with Middleman. I am storing a lot of information in data files, as I am going to use the same information on multiple pages. (Partials wouldn\'t work fo

相关标签:
1条回答
  • 2021-01-25 01:04

    Since you already have HAML parsing correctly, and when you render verbatim links it works, try using a helper to directly inject the links without needing to go to ERB. Since HAML will already run Ruby code, I see no need to pass it through ERB too. I think eval will allow you to get the same effect you're using ERB for. Something like this:

    def refonly(text)
      text.scan(/ref\.(page[A-Z])/).each do |groups|
        page_name = groups[0]
        text.gsub!(/ref\.#{page_name}/, eval("data.pages.#{page_name}.link"))
      end
      text
    end
    

    EDIT: Scanning the text will allow you to get each page_name so you can loop through each one and replace each page reference with its link.

    0 讨论(0)
提交回复
热议问题