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.2.tar.gz (20.6 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.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for markdown_readtime-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a0b995c94faf5258ccd28a9b3295a8c341721d5d74d7242ae4d05d83c4f5861
MD5 ef0b665a443f99501147f5fff8cafbc6
BLAKE2b-256 579eec2ecad507b6d5a2fb281a1c71c9f4389d5a4ad1edc991868700c47d0375

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for markdown_readtime-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 630d4c42e66e393c0e12b5c86edafd9975dfc2ef501337c148b4024bea032f35
MD5 65d4d7c5970a210311ff9d3a1223c85d
BLAKE2b-256 8540559d942929dd26acb5e24e1bba5b119f8f7be24481af6f916b333c61ab2d

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