[BangPypers] Code Extractor in Python
Gopalakrishnan Subramani
gopalakrishnan.subramani at gmail.com
Thu Jun 13 03:20:08 CEST 2013
All,
I am looking for possibility to pull out the code from source file without
specifying the line numbers explicitly. I am writing a blog and book on
Java script AngularJS using Markdown, I wanted that to be driven as
code-text blog.
Small example,
------------------------------------------
File: math.js
function sum(a, b) {
return a + b;
}
function mul(a, b) {
return a * b;
}
-----------------------------------------
On Markdown, the explanation shall be in Function.txt,
---------------------------------------------------------------------------------
File: Function.txt
Basic Functions
============
Here is the simple *function* example that adds two numbers and return the
result.
{{{insertCode math.js, function:sum}}}
---------------------------------------------------------------
{{{insertCode math.js, function:sum}}} is very abstract, I am ok with any
syntax, something that can be put on Jinja2 templates, in Python. But I
would like to pull the code from a file, function or specific class (for
other languages).
The idea is, store the source code in Github/separate file, the markdown
text shall be stored in Dropbox, I can display the code, and execute the
output, display the result underneath. Any changes to Github will be
reflected automatically, right now, I copy paste the code into markdown.
Alternative ideas or tools are welcome. Python based tools are preferred,
I use Flask, Markdown, Jinja2. Sometimes, I put Jinja2 templates inside
Markdown, so I can extend the template.
Python inspect is doing similar for Python but that is purely on run time,
I am looking for options to pull out code from Python, HTML. I tried, HTML,
it is possible with BS4.
Thank you,
GK
More information about the BangPypers
mailing list