从剪贴板中获取代码并为MongoDB幻灯片格式化。

moncode的Python项目详细描述


蒙古德

Moncode是一个小型的CLI工具,它从剪贴板获取源代码, 使用MongoDB演示配色方案和代码字体对其进行格式化, 然后把结果放回剪贴板。在

结果看起来有点像这样:

A Python slide with lovely syntax-highlighted code.

安装它

我建议您使用pipx 将moncode安装为命令行工具。 如果您有pipx,可以这样安装:

pipx install moncode

如果你不想安装pipx,你可以用pip安装它, 但并不推荐:

^{pr2}$

使用它

Moncode有完整的文档记录。 您可能最常使用的命令是format,如下所示:

moncode格式

我是这样使用它的:

  1. 从我的IDE复制一些Python代码
  2. 在终端窗口中运行moncode format -l python。 现在,剪贴板中的Python代码已经被语法高亮显示的Python代码替换了。在
  3. 将结果粘贴到Google幻灯片(或Powerpoint或其他任何东西)

有很多其他方法可以使用这个工具, 从stdin或磁盘上的文件中获取输入, 并将结果发送到stdout或磁盘上的文件。 命令选项有完整的文档记录:

# 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.

运行moncode format时,我建议您传递-l标志, 指定输入代码的编程语言。 如果你不这样做,moncode会猜到它的语言,而且很可能会弄错。 支持哪些语言? 很高兴你问。。。在

蒙科语言

要获取所有支持的输入语言的列表,请运行moncode languages。 结果会像这样。。。在

$ 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

嘘!有很多种语言,不是吗? 这些值中的任何一个都受-l选项的支持moncode format

发展

运行以下命令将项目(和开发依赖项)安装到活动virtualenv中:

pip install -e .[dev]

使用以下内容运行测试:

make test

在不同版本的Python下运行测试:

tox

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将异步类的结果放入mainActivity EditText   java LDAP目录管理器服务提供,OutOfMemory   java Cassandra NoHostAvailableException,但仍存在活动节点   springboot应用程序的java启动线程   如果poll不一定返回第一项,那么java是ConcurrentLinkedQueue的好选择吗?   解析XML时JSON中出现java意外字符串   当'key'是两个整数时,如何输出Java HashMap键?   java为什么不显示在jsp页面中   java使用流式API转换映射列表中的值   JavaJPA+Spring:基于在持久化实体之前接收到的值,将外键列映射到ID   java如何使用selenium读取pdf文件   Canny之后的java对象提取   DSpace没有列出集合,java。lang.NumberFormatException:null   java我可以为数据库表主键设置一个最大值吗?   java如何定义Javadoc链接,可以通过单击   @java/spring中的SessionAttribute是否丢失数据?