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.3.tar.gz (20.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.3-cp312-cp312-manylinux_2_34_x86_64.whl (371.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

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

File hashes

Hashes for markdown_readtime-0.1.3.tar.gz
Algorithm Hash digest
SHA256 70a2275cccac61fdfac191ebbc0a72b956cda753afed5b6077e3797cf64efa7d
MD5 1a41f4b583a62c5c9ae058f02c50b320
BLAKE2b-256 3ddacbdc12715b24308933b6d20d4b94639ef96ec52ba2ae64fdbcaa0d8439d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for markdown_readtime-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2816858ea6a13ab0175f1f5cedc1d7d3608ce7a33bd81b51dc741b59a7357d6c
MD5 168c924b220820be42b4c92f1923317e
BLAKE2b-256 8ad26711d30293aa1d368b9d426f38d9ede8cdd67e5444941b4b883e755bc062

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