[icoFolderApps.png]Program files
[icoFolderApps.png] Program files[icoJava.png] src2xml
 src2xml (23oct2010)
A command line portable utility that creates a tagged XML file from a source code snippet for highlighting purposes. This is a SBVEH (Stupid But Very Expandable Highlighter), characterized by an inefficient but very customizable structure. Features/shortcomings:
  • The highlight rules are chosen by input file extension
  • A remarkable freedom on highlighter customization: add new languages, new regions, etc... Peek the XML config file (automatically created if missing) you should then figure out how to obtain advanced highlighting features
  • Supports multi syntax highlight in the same file
  • Edit yourself a proper CSS file to style the source code as you prefer, starting from the template produced with option -css
  • Specify "html" extension in output file name to obtain a ready to use html file, otherwise use xml extension
  • When using regular expressions with lookbehind (ex in html lang definition) the parsing takes a long loooong time...
C:> java -jar src2xml.jar  [paths] [options]
Command line arguments can be:
  • path Add a file/folder in the input files list
  • -r Recursively process input subfolders
  • -out=path Add a file/folder in the output files list
  • -cfg=config-file Explicitly indicate a configuration file
  • -css=css-file Generate (if not existing) a dummy stylesheet file (use as a template); in case of html output also links to this stylesheet
  • -ext=file-ext Select output mode by file extension
C:> java -jar src2xml.jar "C:\my code\code.cpp" -out="C:\some web\code.html"

C:> java -jar src2xml.jar code1.cpp -out=code1.html code2.cpp -out=code2.html

C:> java -jar "Snippets\" -out="Dest\"

C:> java -jar "Snippets\*.?pp" -out="Dest\" -r -ext=xml
I developed this in java using NetBeans, as exercise; the code snippets in this website are obtained using this utility. Here is the original (note the highlighting...) batch file that performs my snippets conversion:
 Create code snippets.bat
@echo off title **** Create code snippets **** rem src2xml improved, no more need to call for each file! GOTO NEWFASHION :OLDFASHION set indir=xml\snippets set outdir=html\snippets set src2html=java -jar "bin\src2xml.jar" -conf="bin\src2xml-config.xml" echo Iterating files in %indir% setlocal EnableDelayedExpansion for %%I in (%indir%\*.*) do ( rem extract file name set outfile=%%~nI%%~xI.xhtml rem do some operation echo %src2html% "%%I" "%outdir%\!outfile!" -all %src2html% "%%I" "%outdir%\!outfile!" -all if not errorlevel 0 (echo !outfile! : ERROR & pause) else (echo !outfile! : OK) ) :NEWFASHION java -jar "bin\src2xml.jar" "xml\snippets" -out="html\snippets" -cfg="bin\src2xml-config.xml" -ext=xhtml
Download this utility (including sources): [ico7zArchive.png]src2xml.7z (60KB)