Nitin Jain
Nitin Jain

Reputation: 3083

Separate multiline Code blocks form text

Description -as\r\n [code]a = b+ 4\r\nc= a +j\r\n\r\n[/code]\r\nagain text\r\n[code]a = c + 4\r\n[/code]"

output i need is to pass the text enclosed in [code] to coderay for formatting. or you can say as similar to stackoverflow where we can see code part and text part separated . i am following Separate Code blocks form text which is working if code block is with in one line.

Upvotes: 0

Views: 108

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89557

You can use this to avoid the newline problem:

str.gsub(/\[code\]((?>[^\[]++|\[(?!\/code]))*+)\[\/code\]/) do |match, replace|
   ...

The content enclosed between [code] tags is in the first capturing group.

Upvotes: 1

Related Questions