February 20 - Markdown Heading Parser in Ruby with Heredocs
This guide examines how to parse a Ruby Heredoc object and convert any lines with a hashtag to HTML H1 headings.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Parse a Ruby Heredoc and replace any lines that start with a hashtag with HTML H1 heading tags.
Exercise Description
Given a Ruby Heredoc string, replace any lines that start with a hashtag and wrap them in HTML H1 heading tags.
Sample Input
content = <<-EOF # Hey there Some content # Another heading More content EOF
Expected Output
"<h1>Hey there</h1>\n\nSome content\n\n<h1>Another heading</h1>\n\nMore content\n"
Real World Usage
When it comes to working with Rails helper methods, it's important to understand how to parse large strings and replace patterns with other strings.