Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > KOReader

Notices

Reply
 
Thread Tools Search this Thread
Old Today, 11:34 AM   #1
lumping-sugar66
Zealot
lumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trollslumping-sugar66 doesn't feed trolls
 
lumping-sugar66's Avatar
 
Posts: 122
Karma: 81981
Join Date: Oct 2023
Location: Ontario, Canada
Device: Kobo Aura Edition 2, Kobo Clara 2E
Lightbulb HTML Replacer plugin - Edit EPUB Content Directly on KOReader

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
  1. Install to
    Code:
    koreader/plugins/htmlreplacer.koplugin/
  2. Open an EPUB → Menu → Style tweaks → HTML content tweaks
  3. Add rules (e.g.,
    Code:
    <span>(.-)</span>
    Code:
    %1
    to remove spans)
  4. Reload with Replacements to preview
  5. Apply Changes when satisfied (backs up original)

Menu Navigation

Tap the top menuStyle tweaksHTML 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!
Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	4
Size:	207.5 KB
ID:	219143   Click image for larger version

Name:	2.png
Views:	4
Size:	216.7 KB
ID:	219144   Click image for larger version

Name:	3.png
Views:	4
Size:	214.7 KB
ID:	219145   Click image for larger version

Name:	4.png
Views:	3
Size:	380.3 KB
ID:	219146  

Last edited by lumping-sugar66; Today at 12:48 PM.
lumping-sugar66 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
KOReader: a document reader for PDF, DJVU, EPUB, FB2, HTML, ... (GPLv3) hawhill Kindle Developer's Corner 1289 04-07-2025 11:18 AM
Edit Book Info directly from PocketBook - epub format & FW6+ only neil_swann80 PocketBook Developer's Corner 7 01-12-2024 12:14 PM
How to send .epub directly on Kindle and read with KOReader Alex305 KOReader 6 05-11-2022 05:33 AM
HTML to ePub stripping out Content text nimblebooks Conversion 6 02-01-2012 02:50 AM
Calibre Recipe HTML content differs from raw html of index.html. krunk Calibre 4 09-20-2010 10:48 PM


All times are GMT -4. The time now is 04:47 PM.


MobileRead.com is a privately owned, operated and funded community.