API Docs

Jinja utilities for Invenio.

class invenio_formatter.ext.InvenioFormatter(app=None)[source]

Invenio-Formatter extension.

Extension initialization.

Parameters:app – The Flask application. (Default: None)
init_app(app)[source]

Flask application initialization.

Parameters:app – The Flask application.
static init_config(app)[source]

Initialize configuration.

Note

If CairoSVG is installed then the configuration FORMATTER_BADGES_ENABLE is True.

Parameters:app – The Flask application.

Context preprocessors

Badges context processor.

invenio_formatter.context_processors.badges.badges_processor()[source]

Context processor for badges.

invenio_formatter.context_processors.badges.generate_badge_png(title, value, color='#007ec6')[source]

Generate the badge in PNG format.

invenio_formatter.context_processors.badges.generate_badge_svg(title, value, color='#007ec6')[source]

Generate the SVG.

Parameters:
  • title – The badge title.
  • value – The badge content.
  • color – The badge color. (Default: '#007ec6')
Returns:

The SVG badge.

invenio_formatter.context_processors.badges.get_text_length(*args)[source]

Measure the size of string rendered with a TTF no-nomospaced fonts.

Parameters:*args – List of strings to be measured.
Returns:The length of the strings.

Filters

Datetime Jinja filters.

invenio_formatter.filters.datetime.format_arrow(value, format_string)[source]

Format an arrow datetime object.

Parameters:
  • value – The arrow datetime object.
  • format_string – The date format string
Returns:

Returns a string representation of the given arrow datetime object, formatted according to the given format string.

Note

Do not use this filter to format date/times presented to an end user. Instead use datetimeformat or dateformat from Invenio-I18N.

invenio_formatter.filters.datetime.from_isodate(value, strict=False)[source]

Convert an ISO formatted date into a Date object.

Parameters:
  • value – The ISO formatted date.
  • strict – If value is None, then if strict is True it returns the Date object of today, otherwise it returns None. (Default: False)
Returns:

The Date object or None.

invenio_formatter.filters.datetime.from_isodatetime(value, strict=False)[source]

Convert an ISO formatted datetime into a Date object.

Parameters:
  • value – The ISO formatted datetime.
  • strict – If value is None, then if strict is True it returns the Date object of today, otherwise it returns None. (Default: False)
Returns:

The Date object or None.

invenio_formatter.filters.datetime.to_arrow(value)[source]

Convert a Date object to an arrow datetime object.

HTML sanitisation Jinja filters.

invenio_formatter.filters.html.sanitize_html(value, tags=None, attributes=None)[source]

Sanitize HTML.

Parameters:
  • tags – Allowed HTML tags. Configuration set by Invenio-Config.
  • attributes – Allowed HTML attributes. Configuration set by Invenio-Config.

Use this function when you need to include unescaped HTML that contain user provided data.

Views

View method for Invenio-Formatter.

invenio_formatter.views.create_badge_blueprint(allowed_types)[source]

Create the badge blueprint.

Parameters:allowed_types – A list of allowed types.
Returns:A Flask blueprint.