Skip to main content

A library to estimate reading time for Markdown content with support for Chinese and English texts

Project description

markdown-readtime

A library to estimate reading time for Markdown content with support for Chinese and English texts.

Features

  • 📊 Accurate estimation of Markdown text reading time
  • 🌍 Support for both Chinese and English texts
  • 😊 Emoji processing support
  • 🖼️ Image reading time calculation
  • 💻 Code block reading time calculation
  • ⚙️ Customizable reading speed parameters
  • 📦 Lightweight, zero dependencies (optional serde support)

Installation

pip install markdown-readtime

Usage

Basic Usage

from markdown_readtime import estimate, minutes, words, formatted

markdown_content = """
# My First Blog Post

This is some sample content to demonstrate how to use the markdown-readtime library.

## Subtitle

We can also add some lists:
- First item
- Second item
- Third item
"""

# Get full reading time information
read_time = estimate(markdown_content)
print(f"Total reading time: {read_time.total_seconds} seconds")
print(f"Formatted time: {read_time.formatted}")
print(f"Word count: {read_time.word_count}")

# Or use shortcut functions
print(f"Approximately {minutes(markdown_content)} minutes to read")
print(f"About {words(markdown_content)} words")
print(f"Reading time: {formatted(markdown_content)}")

Custom Reading Speed

from markdown_readtime import estimate_with_speed, ReadSpeed

markdown_content = "# Sample Article\n\nThis is test content for reading."

# Create custom reading speed configuration
speed = ReadSpeed(200, 15, 25, True, True)  # wpm, seconds_per_image, seconds_per_code_block, count_emoji, chinese
read_time = estimate_with_speed(markdown_content, speed)
print(f"Custom reading time: {read_time.total_seconds} seconds")

API

Classes

  • ReadTime: Reading time estimation result

    • total_seconds: Total reading time in seconds
    • formatted: Formatted reading time string
    • word_count: Word count
    • image_count: Number of images
    • code_block_count: Number of code blocks
  • ReadSpeed: Reading speed configuration

    • words_per_minute: Words per minute (default: 200)
    • seconds_per_image: Extra time per image in seconds (default: 12)
    • seconds_per_code_block: Extra time per code block in seconds (default: 20)
    • count_emoji: Whether to count emojis (default: True)
    • chinese: Whether text is Chinese (default: True)

Functions

  • estimate(markdown: str) -> ReadTime: Estimate reading time with default speed settings
  • estimate_with_speed(markdown: str, speed: ReadSpeed) -> ReadTime: Estimate reading time with custom speed settings
  • minutes(markdown: str) -> int: Get reading time in minutes (rounded up)
  • words(markdown: str) -> int: Get word count
  • formatted(markdown: str) -> str: Get formatted reading time string

Building from Source

To build this package from source:

# Install maturin if you haven't already
pip install maturin

# Build the package
maturin develop  # For development
# or
maturin build    # To create a wheel

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markdown_readtime-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markdown_readtime-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl (370.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file markdown_readtime-0.1.1.tar.gz.

File metadata

  • Download URL: markdown_readtime-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for markdown_readtime-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c71cf50546b0327072d98dd04f33f70996d408585601f5c757749dac16b76f86
MD5 547e713e42a1a6380c055c1f2545d3bc
BLAKE2b-256 e33902e34fd42d823de3e8d5d20358250a7e0184bea8491868339c0e27058180

See more details on using hashes here.

File details

Details for the file markdown_readtime-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for markdown_readtime-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6fbbf490a1189ce7bada5e53d95da2a0680313bbdc3e3021e5be463a387ccf2c
MD5 2683afa225b55519819674acd3816a63
BLAKE2b-256 1a1564b1e1cf853cfcb4a7bcd02dcfc218f456c6c4b0e8c91023e9a673fbe853

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page