Skip to main content

Django-precise-bbcode is a Django application providing a way to create textual contents based on BBCodes.

BBCode is a special implementation of HTML. BBCode itself is similar in style to HTML, tags are enclosed in square brackets [ and ] rather than < and > and it offers greater control over what and how something is displayed.

This application includes a BBCode compiler aimed to render any BBCode content to HTML and allows the use of BBCodes tags in models, forms and admin forms. The BBCode parser comes with built-in tags (the default ones ; b, u, etc) and allows the use of smilies, custom BBCode placeholders and custom BBCode tags. These can be added in two different ways:

  • Custom tags can be defined in the Django administration panel and stored into the database ; doing this allows any non-technical admin to add BBCode tags by defining the HTML replacement string associated with each tag

  • Tags can also be manually registered to be used by the parser by defining a tag class aimed to render a given bbcode tag and its content to the corresponding HTML markup

Documentation

Online browsable documentation is available at https://django-precise-bbcode.readthedocs.org.

Requirements

  • Python 3.6+

  • Django 3.2+

  • PIL or Pillow (required for smiley tags)

Installation

Just run:

pip install django-precise-bbcode

Once installed you can configure your project to use django-precise-bbcode with the following steps.

Add precise_bbcode to INSTALLED_APPS in your project’s settings module:

INSTALLED_APPS = (
    # other apps
    'precise_bbcode',
)

Then install the models:

python manage.py migrate

Usage

Rendering bbcodes

Django-precise-bbcode comes with a BBCode parser that allows you to transform a textual content containing BBCode tags to the corresponding HTML markup. To do this, simply import the get_parser shortcut and use the render method of the BBCode parser:

>>> from precise_bbcode.bbcode import get_parser
>>> parser = get_parser()
>>> parser.render('[b]Hello [u]world![/u][/b]')
'<strong>Hello <u>world!</u></strong>'

It’s that easy!

As you may need to render bbcodes inside one of your Django template, this parser can be used as a template filter or as a template tag after loading bbcode_tags:

{% load bbcode_tags %}
{% bbcode entry.bbcode_content %}
{{ "[b]Write some bbcodes![/b]"|bbcode }}

The BBCode content included in the entry.bbcode_content field will be converted to HTML and displayed. The last statement will output <strong>Write some bbcodes!</strong>.

Storing bbcodes

While you can use the Django built-in models.TextField to add your BBCode contents to your models, a common need is to store both the BBCode content and the corresponding HTML markup in the database. To address this django-precise-bbcode provides a BBCodeTextField.

from django.db import models
from precise_bbcode.fields import BBCodeTextField

class Post(models.Model):
    content = BBCodeTextField()

This field will store both the BBCode content and the correspondign HTML markup. The HTML content of such a field can then be displayed in any template by using its rendered attribute:

{{ post.content.rendered }}

And more…

Head over to the documentation for all the details on how to use the BBCode parser and how to define custom BBcode tags, placeholders and smilies.

Authors

Morgan Aubert (@ellmetha) and contributors

License

BSD. See LICENSE for more details.

Release files for django-precise-bbcode 1.2.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-precise-bbcode 1.2.16
File Size Uploaded
django_precise_bbcode-1.2.16.tar.gz 27.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-precise-bbcode 1.2.16
File Interpreter ABI Platform
django_precise_bbcode-1.2.16-py3-none-any.whl Python 3 none any Details

Total release size: 65.9 kB

Release files / django_precise_bbcode-1.2.16.tar.gz

Download URL django_precise_bbcode-1.2.16.tar.gz
Size 27.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f3c9d38a3fe8d8495d0f742128aaa17a1922e71d7542597f1125b27736f7d67a
BLAKE2b-256 checksum
How to use checksums
c7c3f7dac7c2463060a1c0584c1e368615e88f08e4c27b5d17d8dc3901195933
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Darwin/22.3.0

Release files / django_precise_bbcode-1.2.16-py3-none-any.whl

Download URL django_precise_bbcode-1.2.16-py3-none-any.whl
Size 38.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fc815c2a52202a6eb5a8bc562b770d760c6af1b719b833541b3b112e71229f2
BLAKE2b-256 checksum
How to use checksums
4169c207101d7eff5c0c4605371af042983cedd54dfef76d8920cbe1c9968c03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Darwin/22.3.0

Release history Release notifications | RSS feed

This release

1.2.16 This release

2 release files

1.2.15

2 release files

1.2.14

2 release files

1.2.13

2 release files

1.2.12

2 release files

1.2.11

2 release files

1.2.10

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0

2 release files

0.5

2 release files

0.4.2

2 release files

0.4.1

1 release file

0.4.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page