Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created February 6, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaryorg/82844ef131340b3c359d51277efc306c to your computer and use it in GitHub Desktop.
Save benaryorg/82844ef131340b3c359d51277efc306c to your computer and use it in GitHub Desktop.
How to convert source code to a format suitable for pasting into Mumble('s source code tab).

What?

Sometimes you just want to paste some source code into Mumble and have the others be able to read it properly.

Why?

But sometimes you're also like me and don't mind going two extra steps to give those peers some syntax highlighting.

And then?

You do what's up there. Or down there, I dunno how this gist will do things. Point is, if you execute that command you will have a syntax highlighted HTML version of a command in your clipboard that when sent to someone in Mumble will display (beautifully) a command which can be used to get some HTML in your clipboard which has syntax highlighted some shell script. You can use it for arbitrary Markdown (though the XPath strips out everything but the source code, change as you like).

Also, yes the double indirection is the thing I used to send this to someone else so they can syntax highlight their message.

Dependencies

  • pandoc (get from your package manager or w/e)
  • xmllint (xmllint2 package on most distros I think)
  • css-inline (cargo install, tested using 0.8.0)
#!/usr/bin/env zsh
pandoc --highlight-style breezedark --metadata title=Code --standalone -f markdown -t html4 <<"_END" | css-inline | xmllint --html --nowarning --xpath '/html/body/div[@class="sourceCode"]' - | xsel -b
````bash
pandoc \
--highlight-style breezedark \
--metadata title=Code \
--standalone \
-f markdown -t html4 <<"END" \
| css-inline \
| xmllint --html --nowarning --xpath '/html/body/div[@class="sourceCode"]' - \
| xsel -b
```bash
# foo
bar="$(baz "${quux}_xyz")"
```
END
````
_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment