Parsing a Custom Markdown-like Syntax in Ruby - implementing Inline HTML Tags Not Rendering Correctly
I'm converting an old project and I'm not sure how to approach I've hit a wall trying to I'm trying to implement I'm writing unit tests and I'm working on a Ruby application that needs to parse a custom markdown-like syntax to convert it into HTML, but I'm running into issues with the inline HTML tags... For instance, my parser successfully converts markdown syntax like `**bold**` to `<strong>bold</strong>`, but when I include inline HTML, such as `<a href="https://example.com">link</a>`, it gets ignored completely. The current approach I'm using involves regular expressions to identify the patterns, but the inline tags seem to be conflicting with my regex rules. Here's a simplified version of my parsing logic: ```ruby class CustomMarkdownParser def parse(input) input.gsub!(/\*\*(.*?)\*\*/, '<strong>\1</strong>') # Bold syntax input.gsub!(/\*(.*?)\*/, '<em>\1</em>') # Italics syntax input.gsub!(/(\<[^>]+>)/, '\1') # Attempting to preserve inline HTML input end end parser = CustomMarkdownParser.new puts parser.parse('This is **bold** and this is <a href="https://example.com">link</a>.') ``` When I run this code, it returns: ``` This is <strong>bold</strong> and this is . ``` As you can see, the inline HTML is completely stripped out. Iβve tried adjusting the regex to not conflict with the HTML tags, but it doesnβt seem to work. Iβm currently using Ruby 3.0.0 and I would appreciate any suggestions on how to improve my regex or any other approach that could guide to correctly parse and render the inline HTML while maintaining the markdown syntax. Any insights would be greatly appreciated! This is for a web app running on Windows 10. What's the correct way to implement this? Could someone point me to the right documentation? This is happening in both development and production on Linux. I've been using Ruby for about a year now. Is there a better approach? Any help would be greatly appreciated!