JavaScript (ES8), 266 262252 bytes
s=>` _2
13
-2
7\\5\\ 3^__^1^__^
8\\10\\ (oo)\\_7\\_5
119(__)\\ 75)${q=`\\\\/\\
15||<>`}13||-4w6w |
15||13|| 5||`7||`.replace(/.(>|\d+\d+)/g,(s,n)=>n^1=>n^3?s[i=0].repeat(n^2?n:wn^2||w):a.map(s=>q[j='7019'[s=>'|\\/<'[j=!i++*2|!a[i]]]+sa[i]]+s.padEnd(w)+q[-~j]+'|/\\>'[j]).join`
`,a=s.split`
`.map(w=s=>` ${w>(v=s.length+2)?0:w=v,s} `))
How?
We first split the input string into lines surrounded with 2 spaces and compute the width w
of the biggest line (including said spaces):
a = s.split`\n`.map(w = s => ` ${w > (v = s.length + 2) ? 0 : w = v, s} `)
We define q
as:
"\/\[LF] 15||<>"
^^ ^ ^
01 7 9
This string is used simultaneously as a substring of our template (except the <>
part which is removed) and as a lookup string for the surrounding characters of the text bubble, using the marked positions above.
Each number n
in the template string is interpreted as follows:
2
: repeat the preceding characterw
times (for the top and bottom borders of the text bubble)13
: insert the text bubble:a.map(s => q[j'|\\/<'[j = '7019'[!i++ * 2 | !a[i]]]a[i]] + s.padEnd(w) + q[-~j]'|/\\>'[j] ) .join`\n`
anything else: repeat the preceding character
n XOR 2
times
We actually match /.(>|\d+)/g
, which means that the substring <>
is interpreted as '<'.repeat('>')
, resulting in an empty string.