Select, prettify publish snippets in multiple languages from within a GIST module

I posted how to include and prettify snippets from GAS, Gist, and scriptDB the other day, adding the ability to select particular functions from within modules. See the Excel liberation site for more detailWith Google Apps Script, we only had to worry about how to pick out functions from a javascript module. Now that Gists are supported – well, they could be any language. Turns out though that it’s pretty straightforward to add new languages. Here’s an example of selecting a couple of functions from a module of many VBA functions, stored in a gist.

http://xliberation.com/p/gaspubcontainer.html?
source=gist&library=3623968&func=swCleanSheet,swGetTables

which, when put in an iFrame, gives us the code snippet below.

http://xliberation.com/p/gaspubcontainer.html?source=gist&library=3623968&func=swCleanSheet,swGetTables

Here’s the code that figures out where the functions start and finish. (This time we’re showing some javascript hosted in a Google Apps Script shared library)

http://xliberation.com/p/gaspubcontainer.html?
source=script&library=mcpher&module=gasPub&func=getGist,getFunctions,getFunction,getFunPos

http://xliberation.com/p/gaspubcontainer.html?source=script&library=mcpher&module=gasPub&func=getGist,getFunctions,getFunction,getFunPos

Challenge for you
Anybody want to contribute appropriate regexes for other languages (or improve the basic ones being used here) to be able to find the beginning and end of functions? See the snippets above for how.

Author: bm082975

Leave a Reply

Your email address will not be published. Required fields are marked *