Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/rouge/lexers/gherkin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,29 @@ def self.detect?(text)
rule %r/[ \r\t]+/, Text
end

state :annotated_string do
rule %r((""")(\S*)(.*?)("""))m do |m|
open, lang, content, close = m.captures

token Str, open
token Str::Escape, lang

sublexer = Rouge::Lexer.find(lang.strip)

if sublexer
delegate sublexer, content
else
token Str, content
end

token Str, close
end
end

state :root do
mixin :basic
rule %r(\n), Text
rule %r(""".*?""")m, Str
mixin :annotated_string
rule %r(@[^\s@]+), Name::Tag
mixin :has_table
mixin :has_examples
Expand Down
49 changes: 49 additions & 0 deletions spec/visual/samples/gherkin
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,52 @@ Feature: Highlander
Then he (or she) will live forever ;-)

Rule: There can be Two (in some cases)

Scenario: Code samples
Given I have some code examples
"""ruby
class Calculator
def multiply(x, y)
x * y
end
end
"""
And I have some code examples
"""rust
fn safe_divide(x: f64, y: f64) -> Result<f64, &'static str> {
match y {
0.0 => Err("Division by zero"),
_ => Ok(x / y),
}
}
"""
And I have some code examples
"""ocaml
let rec factorial = function
| 0 -> 1
| n -> n * factorial (n - 1)

let () = Printf.printf "%d\n" (factorial 5)
"""
And I have some code examples
"""json
{
"calculator": {
"operations": ["add", "subtract", "multiply", "divide"],
"precision": 2,
"enabled": true
}
}
"""
And I have some code examples
"""nonexistent-lang
proc divide(x, y) {
return x / y;
}
"""
And I have some code examples
"""
def add(a, b)
a + b
end
"""