DEV Community

Mike Clarke
Mike Clarke

Posted on

The cleanup code that ate every code block in our published articles

Liquid syntax error: Variable '{{% raw %}' was not properly terminated with regexp: /\}\}/

Top comments (1)

Collapse
 
topstar_ai profile image
Luis Cruz

I appreciate how the article highlights the importance of understanding the context in which string replacement operations are performed, as seen in the extractJson function's initial implementation using replaceAll. The fact that replaceAll stripped all occurrences of


 without regard to their position within the JSON structure led to the removal of code fences inside the `body_markdown` field. The corrected approach, which extracts the JSON by finding its actual boundaries, is a great example of how a more targeted solution can prevent unintended side effects. It's also interesting to see how the use of a validation schema with Zod adds an extra layer of defense against malformed responses. Have you considered exploring other potential edge cases that might arise from the model's output, such as nested JSON objects or unexpected characters?
Enter fullscreen mode Exit fullscreen mode