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 resulttotal_seconds: Total reading time in secondsformatted: Formatted reading time stringword_count: Word countimage_count: Number of imagescode_block_count: Number of code blocks
-
ReadSpeed: Reading speed configurationwords_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 settingsestimate_with_speed(markdown: str, speed: ReadSpeed) -> ReadTime: Estimate reading time with custom speed settingsminutes(markdown: str) -> int: Get reading time in minutes (rounded up)words(markdown: str) -> int: Get word countformatted(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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70a2275cccac61fdfac191ebbc0a72b956cda753afed5b6077e3797cf64efa7d
|
|
| MD5 |
1a41f4b583a62c5c9ae058f02c50b320
|
|
| BLAKE2b-256 |
3ddacbdc12715b24308933b6d20d4b94639ef96ec52ba2ae64fdbcaa0d8439d0
|
File details
Details for the file markdown_readtime-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: markdown_readtime-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 371.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2816858ea6a13ab0175f1f5cedc1d7d3608ce7a33bd81b51dc741b59a7357d6c
|
|
| MD5 |
168c924b220820be42b4c92f1923317e
|
|
| BLAKE2b-256 |
8ad26711d30293aa1d368b9d426f38d9ede8cdd67e5444941b4b883e755bc062
|