Let's for once do something useful.

Given the text from a Try It Online codegolf submission, produce the equivalent Chat Mini Challenge submission, which is of the form

Language, N bytes: [code](URL)


or (if submission is a single byte – TIO will add a trailing s on the first line only if needed)

Language, 1 byte: [code](URL)


You may assume that the submission

• has only one line
• does not contain backticks ()
• has a regular format like in the examples below; the code line is indented with four spaces ( ), not with HTML tags (<pre><code></code></pre>), i.e. no trailing whitespace.

Note that the submission may have a syntax highlighting tag. See last example.

You may optionally include the title text, i.e. …url "Language - Try It Online".

Examples

Given

# [05AB1E], 1 byte

Ô

[Try it online!][TIO-j3v72bss]

[TIO-j3v72bss]: https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online"


return

05AB1E, 1 byte: [Ô](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA)


or

05AB1E, 1 byte: [Ô](https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA "05AB1E – Try It Online")


Given

# [Brachylog], 4 bytes

ḅhᵐc

[Try it online!][TIO-j3v75978]

[Brachylog]: https://github.com/JCumin/Brachylog
[TIO-j3v75978]: https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA "Brachylog – Try It Online"


return

Brachylog, 4 bytes: [ḅhᵐc](https://tio.run/##SypKTM6ozMlPN/r//@GO1oyHWyck//@vlJGampOTDwZK/6MA)


Given

# [APL (Dyalog Unicode)], 15 bytes

<!-- language-all: lang-apl -->

⍴⍨¨⍳

[Try it online!][TIO-j44jgrps]

[APL (Dyalog Unicode)]: https://www.dyalog.com/
[TIO-j44jgrps]: https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ "APL (Dyalog Unicode) – Try It Online"


return

APL (Dyalog Unicode), 15 bytes: [⍴⍨¨⍳](https://tio.run/##AScA2P9hcGwtZHlhbG9n//9m4oaQ4o204o2owqjijbP//zcxNjDijLZmIDQ)

• Can we assume the language name does not contain a ]? – ETHproductions Jun 19 '17 at 18:58
• No language name on TIO has ] though. – Leaky Nun Jun 19 '17 at 18:59
• True, I guess. May we assume the answer does not have any leading whitespace? – ETHproductions Jun 19 '17 at 19:00
• @ETHproductions Yes, because otherwise the backticks won't work. I'll edit. – Adám Jun 19 '17 at 19:04
• Code golf is useful ಠ_ಠ – Conor O'Brien Jun 19 '17 at 19:41

V, 37, 35 bytes

ç^</dj
H3xf]x3Ji[A]Jd2/:
xr(A)


Try it online!

• I tried using the surround plugin that's sort of bundled with V, but it kept trimming whitespace off the end, which I think disqualifies it. – nmjcman101 Jun 19 '17 at 19:35
• Can I bother you to add support for the syntax highlighting tag? – Adám Jun 19 '17 at 19:36
• @nmjcman101 Umm, I think you can assume trailing whitespace doesn't exist. – Erik the Outgolfer Jun 19 '17 at 19:39
• @Adám Well, that kinda seems like pointlessly changing the spec in the middle, but I guess I can support it. – James Jun 19 '17 at 19:42
• @nmjcman101 Yeah, I did know about the difference between ys$[ and ys$], but since we're surrounding it with backticks and brackets, it's actually shorter to just put them in manually. – James Jun 19 '17 at 19:58

Python 3, 11310398 91 bytes

-1 byte thanks to Value Ink.

If you can, I could totally use some help with the regex. ><

lambda s:re.sub('(?s)# .(.*)](.*?)\n.* {4}(.*?)\n.+: (.*)',r'\1\2: [\3](\4)',s)
import re


Try it online!

• Can I bother you to add support for the syntax highlighting tag? – Adám Jun 19 '17 at 19:37
• Great, thanks. Sorry about that. – Adám Jun 19 '17 at 19:46
• No need to use \s to match the code block part; replace it with a literal space character. Also the expected output doesn't have the "Language - Try It Online" segment, so you need to change your last group to (\S*) to match correctly, so the byte count comes out around the same. – Value Ink Jun 19 '17 at 21:27
• Actually, it turns out you can keep that Try It Online part. In that case, changing \s to a space will save 1 byte. – Value Ink Jun 19 '17 at 21:35
• Yup, I was the one who asked that question. ;) – totallyhuman Jun 19 '17 at 21:48

JavaScript (ES6), 73 bytes

f=
s=>s.replace(/...(.*)](.*)[^]+    (.*)[^]+: (.*) ".*/,"$1$2: [$3]($4)")
<textarea rows=8 cols=75 oninput=o.textContent=this.value==f(this.value)?:f(this.value)></textarea><pre id=o>

• The answer I was waiting for. Can this be made into a bookmarklet? Otherwise I'll just bookmark it. – Adám Jun 19 '17 at 23:04
• @Adám alert(prompt().replace(...)) might work, if the prompt will let you paste multiple lines in some way (the regexp doesn't actually need the newlines to be present). – Neil Jun 19 '17 at 23:10
• Hm, I get the unmodified post as result. Maybe we can inject your code into TIO… – Adám Jun 20 '17 at 9:25
• I was also working on a similar solution, but I didn't know about [^] to match anything. I have learnt something new from your solution. Thanks! – Arjun Jun 20 '17 at 13:36

Retina, 54485257 48 bytes

Saved 1 byte thanks to @MartinEnder, 1 byte thanks to @Riley

...(.+)[^@]+    (.+)[^@]+:
$1: [$2](
1]

$)  Try it online! This assumes there won't be an @ in the language name, which should be fine... • you could just replace ^# $ with ^... I think – Martin Ender Jun 19 '17 at 19:20 • @MartinEnder Thanks, I think that works... – ETHproductions Jun 19 '17 at 19:25 • Can you skip the ^ and ? It should always match the whole string anyway. – Riley Jun 19 '17 at 19:26 • @Riley That would fail if... oh shoot, mine does too... – ETHproductions Jun 19 '17 at 19:27 • This doesn't work if the code contains <space>", but I don't know if you need to handle that. I'm guessing you just noticed that to. – Riley Jun 19 '17 at 19:28 05AB1E, 50 bytes ']¡J¦¦¦|J|‚ʒнðQ}ðÛ|Dθ'"Êi\|ë\}θ#1èr"ÿ: [ÿ](ÿ)  Try it online! Now supports syntax highlighting too! н is replaced by 0è and θ is replaced by ®è since those aren't pulled to TIO yet. I just wonder how to shorten ¦¦¦... Ruby, 85 bytes ->s{s[/.*/].gsub(/# .|$/){}+": [#{s[/(?<= )\S.*/]}](#{s=~/TIO-\w+.: (\S+)/;$1})"}


Try it online!

@(a)strjoin(regexprep(strsplit(a,'\n'),{'$.+$: (.+) ".+','^[$<].+','# $$(.+)$(.+)','^ +'},{'](1)','','12: [',''}),'')  This should work. For MATLAB it won't work with Unicode characters though I don't think, mostly because MATLAB sucks when it comes to odd characters. However it will work with Unicode for Octave, or at least TIO seems to be able to cope. It should also handle submissions both with and without the <-- --> syntax highlighting. Updates: 1. Added 4 bytes as I missed the @(a) when copying over 2. Added 2 bytes to add back ticks around the code in the output Try it online! • Can this be run on TIO Octave? – Adám Jun 20 '17 at 12:14 • @Adám it does indeed. I've updated the answer with TIO link. – Tom Carpenter Jun 20 '17 at 12:26 Python 2, 101 bytes a=input().split('\n') print'%s%s: [%s](%s)'%tuple(a[0][3:].split(']')+[a[-6][4:],a[-1].split()[1]])  PHP, 92 bytes <?=preg_filter("<...(.+)$$(, \d+ \w+).* {4}(\S+).*: (\S+).*>s","$1$2: [$3]($4)",\$_GET[0]);


Try it online!

Pip, 4339 38 bytes

[a@>3DC']": ["g@-6|>s"]("(g@v^s1)')]


Try it online!

Takes the lines as separate command-line arguments. An example invocation could look like:

> pip.py -f convert.pip "# [05AB1E], 1 byte" "" "    Ô" "" "[Try it online!][TIO-j3v72bss]" "" "[05AB1E]: https://github.com/Adriandmen/05AB1E" "[TIO-j3v72bss]: https://tio.run/##MzBNTDJM/f//8JT//zNSgSAnJycfDAA \"05AB1E – Try It Online\""


though actually this doesn't work for me because Windows cmd complains about the Ô... [inarticulate muttering]

--At any rate, it works on TIO. Or, use the -r flag and take input from lines of stdin instead.

Assumes that the language name will not contain ] (which would break the markdown anyway).

Explanation

                                        g is list of cmdline args; a is 1st arg;
s is space; v is -1 (implicit)
[                                    ]  Build a list with these elements:
a@>3                                    1st line, sans first three characters,
DC']                                 with the ] character deleted
": ["                          This string
g@-6                      6th line from the end (the code)
"]("              This string
`