Skip to content

Custom Table Styling

This recipe demonstrates how to customize the visual appearance of the tables, such as changing the symbols for boolean values and text alignment.

Configuration

In your mkdocs.yml:

plugins:
  - sqlalchemy:
      base_class: "table_style.models.Base"
      app_path: "src"
      table_style:
        tick: "y"
        cross: "n"
        heading_level: 2
        text_align: left

Usage

In your markdown file:

# MkDocs SqlAlchemy Plugin

{% sqlalchemy %}

This will render tables with "y" and "n" instead of icons, use level 2 headings for table names, and left-align text.


Result

Table: posts

column type nullable default primary_key unique foreign_key
id INTEGER n y n
title VARCHAR(200) n n n
content TEXT y n n
is_published BOOLEAN y False n n
user_id INTEGER y n n users.id
created_at DATETIME y utcnow n n
updated_at DATETIME y utcnow n n

Indexes:

  • ix_posts_updated_at: updated_at

Constraints:

  • pk_posts (PrimaryKeyConstraint)
  • fk_posts_user_id_users (ForeignKeyConstraint)

Table: user_profiles

column type nullable default primary_key unique foreign_key
id INTEGER n y n
user_id INTEGER y n y users.id
first_name VARCHAR(50) y n n
last_name VARCHAR(50) y n n
bio TEXT y n n

Indexes: None

Constraints:

  • pk_user_profiles (PrimaryKeyConstraint)
  • uq_user_profiles_user_id (UniqueConstraint)
  • fk_user_profiles_user_id_users (ForeignKeyConstraint)

Table: users

column type nullable default primary_key unique foreign_key
id INTEGER n y n
username VARCHAR(50) n n y
email VARCHAR(120) n n y
is_active BOOLEAN y True n n
created_at DATETIME y utcnow n n

Indexes: None

Constraints:

  • uq_users_username (UniqueConstraint)
  • uq_users_email (UniqueConstraint)
  • pk_users (PrimaryKeyConstraint)