HTML Replacer - Edit EPUB Content Directly on Your Device
Why This Plugin?
You're reading an EPUB and notice issues - missing italics on book titles, typos, weird chapter dividers, or that annoying first-line formatting that CSS tweaks can't catch.
But you're in the middle of reading. You don't want to:
- Close the book
- Fire up Calibre on your computer
- Edit the EPUB
- Transfer it back
- Find where you were reading
This plugin lets you edit EPUBs directly on your device, right in the middle of reading. Apply regex replacements, preview the changes, and continue reading - all without leaving KOReader.
Features- Book-specific regex replacement rules
- Preview changes before applying permanently
- Pattern checker to test your regex
- Backup & revert functionality
- Works entirely on-device, no computer needed
Quick Start
- Install to
Code:
koreader/plugins/htmlreplacer.koplugin/
- Open an EPUB → Menu → Style tweaks → HTML content tweaks
- Add rules (e.g., → to remove spans)
- Reload with Replacements to preview
- Apply Changes when satisfied (backs up original)
Menu Navigation
Tap the
top menu →
Style tweaks →
HTML content tweaks (first item in the Style tweaks submenu)
From there you'll see:
- Toggle Replacement Rules - Quick enable/disable
- Add New Rule - Create a new pattern
- Manage Rules - Edit/delete existing rules
- View Current Rules - See all rules for this book
- Reload with Replacements - Generate preview
- Apply Changes to Original - Make permanent (only when viewing preview)
- Revert to Original - Restore backup (only when backup exists)
- Clear Cache - Remove all cached previews
Example Patterns
Code:
-- Fix missing italics on book titles
"The Lord of the Rings" → <i>The Lord of the Rings</i>
-- Fix typos
" teh " → " the "
-- Change chapter dividers
"<hr.->" → <div class="divider">• • •</div>
-- Remove first-line formatting that CSS won't catch
">([A-Z ]{2,50})" → "><span class="makelowercase">%1"
-- Add missing emphasis
'([^']+)' → <em>'%1'</em>
Download
https://github.com/onatbas/htmlreplacer.koplugin
Important Notes & Disclaimers
1. Apply Overwrites Original EPUB
The
"Apply Changes to Original" step permanently replaces your EPUB file. The original is backed up to
Code:
htmlreplacer_cache/originals/
The metadata should be unaffected but during preview you will lose your tweaks until Apply.
Apply also appends the book-specific style tweaks to the original metadata of the replaced book because in my case html tweaks and css tweaks often go hand in hand.
2. Revert Option Available
If you're reading a modified EPUB and want to go back, use
"Revert to Original" to restore from the backup in the cache folder. Your rules are preserved even after reverting.
3. Don't Start Patterns with Wildcards!
Never start regex patterns with wildcards like .* or .- - this can overpower the CPU and hang your device. Always start with explicit matches, emphasize explicitness as much as possible:
- Good: <span class=".-">
- Bad: .span class=".-">
4. Use the "Check" Button!
Each rule has a
"Check" button that shows you all matches and the before/after results. This will help prevent surprises, 0 matches and broken EPUBs.
5. Lua Patterns Are Different from Standard Regex
KOReader uses Lua patterns, not PCRE/standard regex:
- .- = non-greedy match (not .+? or .*?)
- .+ = greedy match
- %s = whitespace (not \s)
- %d = digit (not \d)
- Use % to escape special chars (not \)
Reference:
https://www.lua.org/manual/5.1/manual.html#5.4.1
6. Tested On- Kobo Clara 2E
- KOReader emulator
Screenshots coming soon...
Questions? Ask in this thread!