Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
.. |travis| image:: https://travis-ci.org/ducent/spenx.svg?branch=master :target: https://travis-ci.org/ducent/spenx
.. |cover| image:: https://codecov.io/gh/ducent/spenx/branch/master/graph/badge.svg :target: https://codecov.io/gh/ducent/spenx
.. |pypi| image:: https://badge.fury.io/py/spenx.svg :target: https://badge.fury.io/py/spenx
.. |license| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg :target: https://www.gnu.org/licenses/gpl-3.0
Tiny template parser which will convert a pugjs <https://github.com/kakulukia/pypugjs>
_ like syntax to HTML with the help of popular template engines.
spenx is not a direct port of the javascript pugjs library but has been heavily influenced by it so don't expect full pugjs features to work. That being said, if you need to add a feature, don't hesitate to submit your pull requests or open an issue!
In spenx, statements, like conditions and loops, are not processed and outputted "as it" to be processed by the template engine you wish to use.
At the time being, only Jinja2 and Mako has been tested but adding support for anything else should be easy.
I know there's a lot of port of jade, pugjs and so on for python. But everyone seems to be unmaintained. I really like the syntax use by pug and want something simplier and easier to maintain in the future with a strict set of features.
This is why the parser is defined using Arpeggio <https://github.com/textX/Arpeggio>
_ and the cleanpeg syntax. It's easier to read, understand and maintain.
The spenx code is really tiny, check it yourself!
.. code-block:: console
$ pip install spenx
Using spenx is fairly easy:
.. code-block:: python
from spenx import Parser
parser = Parser()
parser.parse(""" p Hello world """)
Hello world
from spenx.ext.jinja import Spenx from jinja import Environment
env = Environment( # Common jinja parameters extensions=[Spenx], # And the spenx extension )
env.spenx_process_extensions = ['.pug', '.spenx'] # Those are the default
from spenx.ext.mako import preprocessor from mako.template import Template
tpl = Template("p Hello world", preprocessor=preprocessor)
If you're already using pugjs, you should feel familiar with the syntax (see the tests/
folder for more insights).
Valid attributes values are:
'
or \`` (
type='text'`)required=True
)value=42.0
).. code-block:: text
html(lang='en') head meta(charset='utf-8') title My first spenx webpage! body h1 spenx p.welcome | Did I said you'll feel right at home if you're using pugjs? | Because I guess that's right! .container p Without a tag defined, div will be assumed strong pretty cool huh?
And this is what's rendered by spenx:
.. code-block:: text
My first spenx webpage!Did I said you'll feel right at home if you're using pugjs? Because I guess that's right!
Without a tag defined, div will be assumed pretty cool huh?
And after using BeautifulSoup:
.. code-block:: text
My first spenx webpage!Did I said you'll feel right at home if you're using pugjs? Because I guess that's right!
Without a tag defined, div will be assumed pretty cool huh?
.. code-block:: bash
$ pip install -e .[test] $ python -m nose --with-doctest -v --with-coverage --cover-package=spenx
FAQs
Python 3 template parser to generate HTML from a pug/jade like syntax
We found that spenx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.