WordPress-style shortcodes for Python

Overview

Python Shortcodes

WordPress-style shortcodes for Python

Create and use WordPress-style shortcodes in your Python based app.

Example

# static output
def my_function(atts = None, enclosed_content = ''):
    return "Output of my function"

# using attributes and enclosed content (pretty simple example)    
def tags_around(atts = None, enclosed_content = ''):
    tag = atts['tag']
    return '<' + tag + '>' + enclosed_content + '</' + tag + '>'

Shortcodes.add_shortcode('my-function', my_function)
Shortcodes.add_shortcode('tags-around', tags_around)

content = """Testing: [my-function]. This will be [tags_around tag="b"]bold[/tags_around]."""
print(Shortcodes.do_shortcodes(content))

# will generate output:
Testing: Output of my function. This will be <b>bold</b>.

Why Use Them?

Just have a look at how powerful WordPress shortcodes are. This simple library is giving you the most improtant functionality to use in your Python projects, in Flask or Django apps, any Python based CMS, etc.

Just think about all the possibilities you are giving to the users of your app: admins, editors, or even end users can use powerful, defined by you functions to add all kind of output to user generated content, in widgets, etc.

The shortcodes are most often used in CMS-es to allow authors or editors to include powerful functionality anywhere on the site. You can have shortcodes to create contact forms, quizzes, product lists, dynamic reports - basically everything.

Documentation

  1. You can simply copy the library in a working folder and import: from shortcodes import Shortcodes

  2. Create your custom shortcode functions. Each shortcode function or a class method should accept two optional parameters: atts and enclosed_content

Example:

# accepts name in enclosed content and capitalizes first letter
def ucfirst(atts = None, enclosed_content = ''):
s = enclosed_content
if s == '':
return '' # if no enclosed content this shortcode returns nothing
s = s[0].upper() + s[1:]
return atts['add_text'] + ' ' + s

The function should not have side effects and must return the content. The returned content will replace the shortcode inside your content after calling Shortcodes.do_shortcode() on it. See step 4.

  1. Each shortcode needs to be regusrered with add_shortcode call. Example: Shortcodes.add_shortcode('ucfirst', ucfirst)

Unlike in WordPress, in Python you need to send the function object, and not a string with the function name.

  1. Finally, call Shortcodes.do_shortcodes() on your content to have all shortcodes replaced with the output of the associated function: Shortcodes.do_shortcode(content)

  2. Shortcodes can contain named parameters with their values enclosed in double quotes. Example: [show-time format="%H:%M:%S"] In this example the shortcode function will receive parameter "format" with value %H:%M:%S

  3. Shortcodes can enclose content like this [my-shotcode param1="param 1" param2="param 2"]My content[/my-shortcode] The content will be passed a second argument to your shortcode function, this allowing you to modify it and return it.

Invalid sortcodes will be ignored and just returned in the content.

Have a look at example.py for several use cases and examples. Run it from terminal by calling python example.py

License

MIT

A simple countdown timer in eazy code to show timer with python

Countdown_Timer The simple CLI countdown timer in eazy code to show timer How Work First you fill the input by int-- (Enter the time in Seconds:) for

Yasin Rezvani 3 Nov 15, 2022
Hitchhikers-guide - The Hitchhiker's Guide to Data Science for Social Good

Welcome to the Hitchhiker's Guide to Data Science for Social Good. What is the Data Science for Social Good Fellowship? The Data Science for Social Go

Data Science for Social Good 907 Jan 01, 2023
A service to display a quick summary of a project on GitHub.

A service to display a quick summary of a project on GitHub. Usage 📖 Paste the code below with details filled in as specified below into your Readme.

Rohit V 8 Dec 06, 2022
Gerenciador de processos e registros pessoais do Departamento de Fiscalização de Produtos Controlados.

CRManager Gerenciador de processos e registros pessoais do Departamento de Fiscalização de Produtos Controlados. Descrição Este projeto tem como objet

Wolfgang Almeida 1 Nov 15, 2021
AIST++ API This repo contains starter code for using the AIST++ dataset.

Explainability for Vision Transformers (in PyTorch) This repository implements methods for explainability in Vision Transformers

Google 260 Dec 30, 2022
Ingest openldap data into bloodhound

Bloodhound for Linux Ingest a dumped OpenLDAP ldif into neo4j to be visualized in Bloodhound. Usage: ./ldif_to_neo4j.py ./sample.ldif | cypher-shell -

Guillaume Quéré 71 Nov 09, 2022
Python implementation of an automatic parallel parking system in a virtual environment, including path planning, path tracking, and parallel parking

Automatic Parallel Parking: Path Planning, Path Tracking & Control This repository contains a python implementation of an automatic parallel parking s

134 Jan 09, 2023
Hashcrack: Hash Bruteforse tool using python

HashCrack Hash Bruteforse tool Usage hashcrack.py -n 6 -c lower -l 5 -a md5 -t 3

Lev 1 May 04, 2022
The Blinker Herald includes helpers to easily emit signals using the excellent blinker library.

Blinker Herald The Blinker Herald includes helpers to easily emit signals using the excelent blinker library. Decorate a function or method with @blin

SatelliteQE 7 Nov 03, 2022
Pypot ⚙️ A Python library for Dynamixel motor control

Pypot ⚙️ A Python library for Dynamixel motor control Pypot is a cross-platform Python library making it easy and fast to control custom robots based

Poppy Project 238 Nov 21, 2022
Just a little benchmark for scrapper PC's

PopMark Just a little benchmark for scrapper PC's This benchmark is for old computer that dont support other benchmark because of support. Like lack o

Garry 1 Nov 24, 2021
Extrator de dados do jupiterweb

Extrator de dados do jupiterweb O programa é composto de dois arquivos: Um constando apenas de classes complementares que representam as unidades e as

Bruno Aricó 2 Nov 28, 2022
A set of tools for ripping music from Konami mobile games

Konami Mobile Ripping Toolset A set of tools for ripping music from Konami mobile games Contents nigger.py for niggering konami's website, ripping all

5 Oct 20, 2022
GNU/Linux'u yeni kurulumu bitirmiş olarak açtığınızda sizi karşılayacak bir uygulama.

Hoş Geldiniz GNU/Linux'u yeni kurulumu bitirmiş olarak açtığınızda sizi karşılayacak bir uygulama.

Alperen İsa 96 Oct 30, 2022
本仓库整理了腾讯视频、爱奇艺、优酷、哔哩哔哩等视频网站中,能够观看的「豆瓣电影 Top250 榜单」影片。

Where is top 250 movie ? 本仓库整理了腾讯视频、爱奇艺、优酷、哔哩哔哩等视频网站中,能够观看的「豆瓣电影 Top250 榜单」影片,点击 Badge 可跳转至相应的电影首页。

MayanDev 123 Dec 22, 2022
DRF magic links

drf-magic-links Installation pip install drf-magic-links Add URL patterns # urls.py

Dmitry Kalinin 1 Nov 07, 2021
全局指针统一处理嵌套与非嵌套NER

GlobalPointer 全局指针统一处理嵌套与非嵌套NER。 介绍 博客:https://kexue.fm/archives/8373 效果 人民日报NER 验证集F1 测试集F1 训练速度 预测速度 CRF 96.39% 95.46% 1x 1x GlobalPointer (w/o RoPE

苏剑林(Jianlin Su) 183 Jan 06, 2023
🤖🤖 Jarvis is an virtual assistant which can some tasks easy for you like surfing on web opening an app and much more... 🤖🤖

Jarvis 🤖 🤖 Jarvis is an virtual assistant which can some tasks easy for you like surfing on web opening an app and much more... 🤖 🤖 Developer : su

1 Nov 08, 2021
A proof-of-concept package manager for Cairo contracts/libraries

glyph A proof-of-concept package manager for Cairo contracts/libraries. Distribution through pypi. Installation through existing package managers -- p

Sam Barnes 11 Jun 06, 2022
Proyecto desarrollado para el programa #FutureDevelopers, tabla periódica interactiva.

Tabla_Periodica Proyecto desarrollado para el programa #FutureDevelopers, tabla periódica interactiva. Descripcion primer entregable: Tabla periodica

1 Dec 04, 2021