Skip to main content

Take code from the clipboard and format it for MongoDB slides.

Project description

moncode

Moncode is a small CLI tool which takes source code from the clipboard, formats it using the MongoDB presentation color-scheme and code font, and then puts the result back on the clipboard.

The result looks a bit like this:

A Python slide with lovely syntax-highlighted code.

Installing it

I recommend you use pipx to install moncode as a command-line tool. If you have pipx you can install it like this:

pipx install moncode

If you don't want to install pipx, you can install it with pip, but it's not really recommended:

# This will install moncode into your system python:
pip install moncode

Using it

Moncode is fully documented. The command you'll probably use most is format, like this:

moncode format

This is the way I use it:

  1. Copy some Python code from my IDE
  2. Run moncode format -l python in a terminal window. Now the Python code in my clipboard has been repaced by syntax-highlighted Python code.
  3. Paste the result into Google Slides (or Powerpoint or whatever.)

There are a bunch of other ways to use the tool, taking input from stdin or a file on disk, and sending the results to stdout or a file on disk. The command options are fully documented:

# Copy code from the clipboard, format it as RTF and then copy the result to the clipboard.
moncode format

# Specify the language if the guess is wrong:
moncode format --language ruby

# Read code from stdin and copy result to clipboard:
cat sample_inputs/sample.js | moncode format

# Read from sample.py and write to output.rtf:
moncode format -i sample.py -o output.rtf

# Read from the clipboard, and write to stdout:
moncode format -o -

# Format the code from the clipboard as HTML and write to output.html
moncode format -o output.html -f html
Options:
  -l, --language TEXT      The programming language to be formatted. If not
                           supplied, this will be guessed from the file name
                           or content. It's better to supply it if you can.
                           Run `moncode languages` to see a list of supported
                           input languages.

  -i, --input FILENAME     The path to a code file to be formatted. If not
                           supplied, either code will be read from stdin, or
                           else copied from the clipboard.

  -o, --output FILENAME    The path to write output to.
  -f, --format [html|rtf]  The output format. Defaults to 'rtf' (which is good
                           for copy-pasting).

  -q, --quiet              Run quietly.
  -v, --verbose            Run loudly.
  --help                   Show this message and exit.

When running moncode format, I recommend you pass the -l flag, specifying the programming language of the input code. If you don't, moncode will guess the language, and likely get it wrong. What languages are supported? Glad you asked...

moncode languages

To get a list of all the supported input languages, run moncode languages. The result will look something like this...

$ moncode languages
abap, abnf, ada, adl, agda, aheui, ahk, alloy, ampl, antlr, antlr-as, antlr-cpp, antlr-csharp, antlr-java, antlr-objc, antlr-perl, antlr-python, antlr-ruby, apacheconf, apl, applescript, arduino, as, as3, aspectj, aspx-cs, aspx-vb, asy, at, augeas, autoit, awk
basemake, bash, bat, bbcbasic, bbcode, bc, befunge, bib, blitzbasic, blitzmax, bnf, boa, boo, boogie, brainfuck, bst, bugs
c, c-objdump, ca65, cadl, camkes, capdl, capnp, cbmbas, ceylon, cfc, cfengine3, cfm, cfs, chai, chapel, charmci, cheetah, cirru, clay, clean, clojure, clojurescript, cmake, cobol, cobolfree, coffee-script, common-lisp, componentpascal, console, control, coq, cpp, cpp-objdump, cpsa, cr, crmsh, croc, cryptol, csharp, csound, csound-document, csound-score, css, css+django, css+erb, css+genshitext, css+lasso, css+mako, css+mozpreproc, css+myghty, css+php, css+smarty, cucumber, cuda, cypher, cython
d, d-objdump, dart, dasm16, delphi, dg, diff, django, docker, doscon, dpatch, dtd, duel, dylan, dylan-console, dylan-lid
earl-grey, easytrieve, ebnf, ec, ecl, eiffel, elixir, elm, emacs, email, erb, erl, erlang, evoque, extempore, ezhil
factor, fan, fancy, felix, fennel, fish, flatline, floscript, forth, fortran, fortranfixed, foxpro, freefem, fsharp
gap, gas, genshi, genshitext, glsl, gnuplot, go, golo, gooddata-cl, gosu, groff, groovy, gst
haml, handlebars, haskell, haxeml, hexdump, hlsl, hsail, hspec, html, html+cheetah, html+django, html+evoque, html+genshi, html+handlebars, html+lasso, html+mako, html+myghty, html+ng2, html+php, html+smarty, html+twig, html+velocity, http, hx, hybris, hylang
i6t, icon, idl, idris, iex, igor, inform6, inform7, ini, io, ioke, irc, isabelle
j, jags, jasmin, java, javascript+mozpreproc, jcl, jlcon, js, js+cheetah, js+django, js+erb, js+genshitext, js+lasso, js+mako, js+myghty, js+php, js+smarty, jsgf, json, json-object, jsonld, jsp, julia, juttle
kal, kconfig, kmsg, koka, kotlin
lagda, lasso, lcry, lean, less, lhs, lidr, lighty, limbo, liquid, live-script, llvm, llvm-mir, llvm-mir-body, logos, logtalk, lsl, lua
make, mako, maql, mask, mason, mathematica, matlab, matlabsession, md, mime, minid, modelica, modula2, monkey, monte, moocode, moon, mosel, mozhashpreproc, mozpercentpreproc, mql, ms, mscgen, mupad, mxml, myghty, mysql
nasm, ncl, nemerle, nesc, newlisp, newspeak, ng2, nginx, nim, nit, nixos, notmuch, nsis, numpy, nusmv
objdump, objdump-nasm, objective-c, objective-c++, objective-j, ocaml, octave, odin, ooc, opa, openedge
pacmanconf, pan, parasail, pawn, peg, perl, perl6, php, pig, pike, pkgconfig, plpgsql, pony, postgresql, postscript, pot, pov, powershell, praat, prolog, properties, protobuf, ps1con, psql, pug, puppet, py2tb, pycon, pypylog, pytb, python, python2
qbasic, qml, qvto
racket, ragel, ragel-c, ragel-cpp, ragel-d, ragel-em, ragel-java, ragel-objc, ragel-ruby, raw, rb, rbcon, rconsole, rd, reason, rebol, red, redcode, registry, resource, rexx, rhtml, ride, rnc, roboconf-graph, roboconf-instances, robotframework, rql, rsl, rst, rts, rust
sarl, sas, sass, sc, scala, scaml, scdoc, scheme, scilab, scss, sgf, shen, shexc, sieve, silver, slash, slim, slurm, smali, smalltalk, smarty, sml, snobol, snowball, solidity, sourceslist, sp, sparql, spec, splus, sql, sqlite3, squidconf, ssp, stan, stata, swift, swig, systemverilog
tads3, tap, tasm, tcl, tcsh, tcshcon, tea, termcap, terminfo, terraform, tex, text, thrift, todotxt, toml, trac-wiki, treetop, ts, tsql, ttl, turtle, twig, typoscript, typoscriptcssdata, typoscripthtmldata
ucode, unicon, urbiscript, usd
vala, vb.net, vbscript, vcl, vclsnippets, vctreestatus, velocity, verilog, vgl, vhdl, vim
wdiff, webidl, whiley
x10, xml, xml+cheetah, xml+django, xml+erb, xml+evoque, xml+lasso, xml+mako, xml+myghty, xml+php, xml+smarty, xml+velocity, xorg.conf, xquery, xslt, xtend, xul+mozpreproc
yaml, yaml+jinja
zeek, zephir, zig

Phew! That's a lot of languages, isn't it? Any of these values are supported by the -l option to moncode format

Development

Run the following to install the project (and dev dependencies) into your active virtualenv:

pip install -e .[dev]

Run tests with:

make test

Run tests under different versions of Python with:

tox

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moncode-0.0.2.tar.gz (65.0 kB view details)

Uploaded Source

Built Distribution

moncode-0.0.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file moncode-0.0.2.tar.gz.

File metadata

  • Download URL: moncode-0.0.2.tar.gz
  • Upload date:
  • Size: 65.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for moncode-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6c771eef8c79ac3dc9708941ba6b61c3b788c10b88d5f383e2de1f44e3039e1a
MD5 28ea43bedcaef60641d0c6eff8924c36
BLAKE2b-256 6010af2f48b5dea838b2bac5f4c75e731c69f2910255574bb97e1084a80d47aa

See more details on using hashes here.

File details

Details for the file moncode-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: moncode-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0

File hashes

Hashes for moncode-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46dd6d4cffededc029fb791cdc9d60678bb906beb4abce645db8b0c483de5e0b
MD5 8b5830fdadd04e3700ca1de48c2da661
BLAKE2b-256 066074ad4ee17c348a68e6b5b7fe6f4f71655bf7d479c99aab7e25c29ff4b452

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page