diff --git a/md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb b/md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb index 637d213ad..0139cb5f3 100644 --- a/md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb +++ b/md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb @@ -51,7 +51,49 @@ def call File.read(full_path), language: 'Hack', ); - node.replace(code) + code_node = node.replace(code) + # If the example has HHVM output associated with it, then print it + # after the code example. However, if both a .example.hhvm.out and + # .hhvm.expect exist, that is an error + output_header = doc.document.create_element( + 'em', + "Output", + ); + if (File.exists? (full_path + ".hhvm.expect")) ^ (File.exists? (full_path + ".example.hhvm.out")) + if File.exists? (full_path + ".hhvm.expect") + output_path = full_path + ".hhvm.expect" + else + output_path = full_path + ".example.hhvm.out" + end + output = doc.document.create_element( + 'pre', + File.read(output_path), + language: 'Text', + ); + code_node.after(output).after(output_header) + elsif (File.exists? (full_path + ".hhvm.expect")) && (File.exists? (full_path + ".example.hhvm.out")) + text = "Both .hhvm.expect and .example.hhvm.out exist. Remove one: #{full_path}" + STDERR.write( + text.red.bold + "\n" + ) + warning = doc.document.create_element( + 'h1', + text, + style: 'color: red', + ) + code_node.after(warning).after(output_header) + elsif File.exists? (full_path + ".hhconfig") # We have some include .php files that we don't want output for. Files that are test run have a .hhconfig + text = "Neither .hhvm.expect or .example.hhvm.out exist. Add one: #{full_path}" + STDERR.write( + text.red.bold + "\n" + ) + warning = doc.document.create_element( + 'h1', + text, + style: 'color: red', + ) + code_node.after(warning).after(output_header) + end end doc end