lib/parade/renderers/command_line_renderer.rb in parade-0.8.0 vs lib/parade/renderers/command_line_renderer.rb in parade-0.8.1
- old
+ new
@@ -33,21 +33,37 @@
# @return [String] the same html content if there is no commandline class
# or the new rendered html content with the new required HTML elements.
#
def self.render(html_content)
- html = Nokogiri::XML.fragment(html_content)
+ html = Nokogiri::HTML.fragment(html_content)
parser = CommandlineParser.new
html.css('.commandline pre').each do |code|
out = code.text
code.content = ''
tree = parser.parse(out)
transform = Parslet::Transform.new do
rule(:prompt => simple(:prompt), :input => simple(:input), :output => simple(:output)) do
command = Nokogiri::XML::Node.new('pre', html)
command.set_attribute('class', 'command')
- command.content = "#{prompt} #{input}"
+
+ node_prompt = Nokogiri::XML::Node.new('span', html)
+ # The 'nv' class specifically gives it the same code syntax highlighting
+ node_prompt.set_attribute('class','prompt nv')
+ node_prompt.content = prompt
+
+ separator = Nokogiri::XML::Text.new(' ',html)
+
+ node_input = Nokogiri::XML::Node.new('span',html)
+ node_input.content = input
+ # The 'nb' class specifically gives it the same syntax highlighting
+ node_input.set_attribute('class','input nb')
+
+ command << node_prompt
+ command << separator
+ command << node_input
+
code << command
# Add newline after the input so that users can
# advance faster than the typewriter effect
# and still keep inputs on separate lines.
\ No newline at end of file