One-click syntax highlighting tool release on the clipboard

Source: Internet
Author: User
Tags addall

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Discuss newsgroups and documents

I always hope that a tool can easily highlight the syntax, because it can be used in many places. In particular, if I edit files in Google document or office, or write blog articles in Windows Live writer (wlw supports plug-ins, but it is not as convenient as this tool, now I have switched to Google document when I write my blog). I want to easily highlight the syntax, but not all of them are so easy to implement. In particular, plug-in tools such as Google document do not support plug-ins. Because Google document does not support plug-ins and syntax highlighting is not supported, I have not used it as a blog writing tool for a long time, you know, I decided to write a tool to solve this problem. So we have today's tool.

In fact, this program is actually a UI version of the original chc2c tool,Code-highlight-clipboard2clipboardChc2c is a command line tool, which may be rejected by many people. Although I have created some shortcuts, it can achieve more convenient results. Of course, it is convenient to use the UI tool. This function is hosted on Google Code:OnekeycodehighlighterAlready downloaded: clipboardhighlighter0.1.rar

Because gvim is still used to complete the actual work, the installation of gvim is still indispensable. If someone finds that the green simplified version supports syntax highlighting and the vim of tohtml, please recommend it to me, I directly put it in the download package so that you don't need to install gvim. By the way, after installation, add gvim to the path so that I can find and execute it.

You can use config. the annotations in the configuration file are very detailed. simple modifications should be fine. The config file itself is a Python script, as long as you meet your original variable name, you can do many things.
By default, I only added support for C, CPP, Python, Java, and JavaScript syntax highlighting. Configure other syntaxes in config. Besides syntaxsupport, config supports dynamic changes. For example, the file name to be saved, the row number, and the color topic.

The software in use is an icon in the taskbar. Right-click the icon and a menu will appear:

The selected column indicates the syntax highlighted language used. Copy the text that requires syntax highlighting to the clipboard with a CTRL-C, and press win + Z to complete the conversion, then you can paste it directly to any HTML-supporting place. It can be a website editor, Windows Live writer, Office Word, Google document .......... You can also configure the file name you want to save in config. py and directly save it as an HTML file.

The main tool actually compiled is pyqt. This tool has some special functional requirements, such as global shortcuts, for example, using ctypes to call Win32 APIs, for example, using the system tray icon, for example, operating the clipboard, etc, I think these examples can be divided into separate articles. At present, I only post some of the conversion effects of this tool for you to see.
The following are some examples:
Configuration file (Python ):


Mod_alt = 0x0001
Mod_none = 0x000
Mod_control = 0x0002
Mod_shift = 0x0004
Mod_win = 0x0008

# The syntax support you want in the trayicon menu
Syntaxsupport = ["C", "CPP", "Python", "Java", "JavaScript"]

# The Global hotkey define, the modifier can be used is listed above.
Modifier = mod_win
Hotkey = 'Z'

# Do you need display line number before every line?
Islinenumber = false

# Renewal #------------------------------------------------------------------------------------
# You need not change these below at most time if you don't know what it is.
# The color theme you want use. (corresponding to gvim)
Color = 'default'

# If you want to save the transformed in a file.
Filename =''

C ++:


// Activate the OpenGL window
VoidEnableopengl ()
{
Pixelformatdescriptor PFD;
IntIformat;

Ghdc = getdc (ghwnd );

Zeromemory (& PFD,Sizeof(PFD ));
PFD. nsize =Sizeof(PFD );
PFD. nversion = 1; // version, generally set to 1
PFD. dwflags = pfd_draw_to_window | // a set of flags that indicate the Pixel Buffer Characteristics
Pfd_support_opengl;
PFD. ipixeltype = pfd_type_rgba; // whether the data type of the pixel is rgba or color index;
PFD. ccolorbits = 32; // Number of color Bit Planes in each color buffer. The color index method is buffer size.
PFD. cdepthbits = 16;
PFD. ilayertype = pfd_main_plane; // ignored.

Iformat = choosepixelformat (ghdc, & PFD); // select a pixel format

Setpixelformat (ghdc, iformat, & PFD); // set it to DC.

Ghrc = wglcreatecontext (ghdc); // create a Drawing description table
Wglmakecurrent (ghdc, ghrc); // make it the current Drawing description table
}

Java:



//: Holding/addinggroups. Java
Package holding;/* added by eclipse. py */
// Adding groups of elements to collection objects.
Import java. util .*;

Public ClassAddinggroups {
Public Static VoidMain (string [] ARGs ){
Collection Collection =
NewArraylist (Arrays. aslist (1, 2, 3, 4, 5 ));
Integer [] moreints = {6, 7, 8, 9, 10 };
Collection. addall (arrays. aslist (moreints ));
// Runs significantly faster, but you can't
// Construct a collection this way:
Collections. addall (collection, 11, 12, 13, 14, 15 );
Collections. addall (collection, moreints );
// Produces a list "backed by" an array:
List List = arrays. aslist (16, 17, 18, 19, 20 );
List. Set (1, 99); // OK -- modify an element
// List. Add (21); // runtime error because
// Underlying array cannot be resized.
}
}///:~


Javascript:



// This function recursively looks at node N and its descendants,
// Converting all text node data to uppercase
Function upcase (n ){
If(N. nodetype = 3/* node. text_node */){
// If the node is a text node, create a new text node that
// Holds the uppercase version of the node's text, and use
// ReplaceChild () method of the parent node to replace
// Original node with the new uppercase node.
N. Data = n. Data. touppercase ();
}
Else{
// If the node is not a text node, loop through its children
// And recursively call this function on each child.
VaR kids = n. childnodes;
For(VAR I = 0; I [I]);
}
}


Another difference is the python Effect of Delek topic + row number:
 


1
2 mod_alt = 0x0001
3 mod_none = 0x000
4 mod_control = 0x0002
5 mod_shift = 0x0004
6 mod_win = 0x0008
7
8 # The syntax support you want in the trayicon menu
9 syntaxsupport = ["C", "CPP", "Python", "Java", "JavaScript"]
10
11 # The Global hotkey define, the modifier can be used is listed above.
12 modifier = mod_win
13 hotkey = 'Z'
14
15 # Do you need display line number before every line?
16 islinenumber = true
17
18 # renewal #------------------------------------------------------------------------------------
19 # You need not change these below at most time if you don't know what it is.
20 # The color theme you want use. (corresponding to gvim)
21 color = 'delek'
22
23 # If you want to save the transformed in a file.
24 filename =''

 

Haha, is the effect good? The only problem is that Vim is used, so a gvim window is always displayed, which affects the visual effect, but does not affect the usage. I will re-post the supported Syntax:

2 HTML a2ps
A65 AAP ABAP ABAQUS
ABC Abel acedb ADA
Aflex ahdl alsaconf Amiga
AML ampl ant anlr
Apache apachestyle arch Art
ASM asm68k asmh8300 ASN
Aspperl aspvbs asterisk asteriskvm
Atlas autohotkey autoit automake
Ave awk ayacc B
Baan basic BC BDF
Bib bindzone blank BST
BTM bzr C calendar
Catalog CDL cdrdaoconf cdrtoc
Cf CFG ch change
Changelog chaskell cheetah chill
Chordpro Cl clean clipper
Cmake cmusrc COBOL Coco
Colortest conaryrecipe conf config
Context cpp crm crontab
CS CSC CSH CSP
CSS cterm ctrlh Cuda
Cupl cuplsim CVS cvsrc
Cweb cynlib cynpp d
Dcd dcl debchangelog debcontrol
Debsources def denyhosts DESC
Desktop dictconf dictdconf diff
Dircolors diva Django DNS
Docbk docbksgml docbkxml dosbatch
Dosini dot doxygen Dracula
Dsl dtd dtml dtrace
Dylan dylanintr dylanlid MCM
Edif Eiffel elf elinks
Elmfilt Erlang eruby esmtprc
Esqlc Esterel eterm eviews
Exim route CT exports FASM
Fdcc fetchmail fgl flexwiki
Focexec form forth FORTRAN
FoxPro framescript freebasic fstab
FVWM fvwm2m4 GDB GDMO
Gedcom git gitcommit gitconfig
Gitrebase gitsendemail gkrellmrc gnuplot
Gp gpg grads Gretl
Groff groovy group grub
GSP gtkrc haml hamster
Haskell haste hastepreproc HB
Help Hercules hex hitest
Hog hostconf HTML htmlcheetah
Htmldjango htmlm4 htmlos IA64
Ibasic icemenu icon IDL
Idlang indent inform initex
Initng inittab ipfilter ishd
ISS ist Jal jam
Jargon Java javacc Javascript
Jess jgraph jproperties JSP
Kconfig Kix kscript kWt
Lace latte LD ldapconf
Ldif Lex lftp lhaskell
Libao lifelines lilo limits
Lisp lite litestep loginaccess
Logindefs logtalk LOTOS lout
LPC lprolog lscript lSl
LSS Lua Lynx M4
Mail mailaliases mailcap make
Man manconf manual maple
MASM Mason master MATLAB
MAXIMA Mel messages MF
MGL MGP MIB MMA
Mmix MMP modconf Model
Modsim3 modula2 modula3 monk
Moo MP mplayerconf mrxvtrc
Msidl msmessages msql mupad
Mush muttrc MySQL named
Nanorc NASM Nastran natural
NCF netrc netrw nosyntax
Nqc nroff NSIs objc
Objcpp ocaml OCCAM omnimark
Openroad OPL ora pamconf
PAPP Pascal passwd pcap
Pccts PDF Perl pf
Pfmain PHP phtml PIC
Pike pilrc pine pinfo
Plaintex PLM PLP PLSQL
Po pod postscr POV
Povini PPD ppwiz prescribe
Privoxy procmail progress PROLOG
Promela protocols PSF ptcap
Purifylog Pyrex Python QF
Quake R racc radiance
Ratpoison RC rcslog
Readline REBOL Registry
Remind resolv Reva Rexx
Rhelp rib RNC rnoweb
Robots rpcgen RPL RST
RTF Ruby Samba SAS
Sass sather scheme SCILAB
Screen SD SDL SED
Sendpr sensors services setserial
SGML sgmldecl sgmllnx sh
Sicad sieve Simula sinda
Sindacmp sindaout SISU skill
SL slang slice slpconf
Slpreg slpspi slrnrc slrnsc
SM smarty smcl smil
Smith SML snnsnet snnspat
Snnsres snobol4 spec specman
Spice splint spup spyce
SQL sqlanywhere sqlforms sqlinformix
Sqlj sqloracle sqr squid
Sshconfig sshdconfig st Stata
STP strace sudoers SVN
Syncolor synload syntax sysctl
TADS tags Tak takcmp
Takout tar tasm TCL
Tcsh terminfo Tex texinfo
Texmf TF tidy Tilde
Tli tpp trasys Trustees
Tsalt tscl tssgm tssop
UC udevconf udevperm udevrules
UIL updatedb valgrind VB
Vera Tilde into logams vgrindefs
VHDL Vim viminfo virata
Vmasm voscm fig
Wdiff web webmacro wget
Whitespace winbatch WML wsh
Wsml wvdial XBL xdefaults
Xf86conf XHTML xinetd XKB
Xmath XML xmodmap XPM
Xpm2 XQuery Xs XSD
XSLT xxd YACC yaml
Z8a zsh

Supported color themes include:
Blue
Color
Darkblue
Default
Delek
Desert
Elflord
Evening
Koehler
Morning
Murphy
Pablo
Peachpuff
Ron
Shine
Slate
Torte
Zellner

The supported color themes and language syntax are all configured through config. In fact, the operation is to select the language, copy, win + Z, paste ..........

 

The author of the original article retains the copyright reprinted. Please indicate the original author and give a link

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.