With ruby gsub(), in string <code>balabala or blank \n another balabala or blank</code>, replacing all \n inside <code>...</code> block into <br>, but do nothing to the content outside <code>...</code>.
I tried /<code>.*(\\n?).*<\/code>/ but not working:
html = '<pre>do \n nothing<code>line \n break</code></pre>'
html = html.gsub(/<code>.*(\\n?).*<\/code>/) { "<br>" }
print html
# actual result: <pre>do \n nothing<br></pre>
# expect result: <pre>do \n nothing<code>line <br> break</code></pre>