Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to add two content CSS selectors in the same chapter? #1636

Open
mrclfr opened this issue Jan 18, 2025 · 1 comment
Open

Comments

@mrclfr
Copy link

mrclfr commented Jan 18, 2025

Hello

I would like to know if you could make a feature that would allow us to add two CSS selectors for the content in one chapter.

I will put an example below

Image

@dteviot
Copy link
Owner

dteviot commented Jan 21, 2025

@mrclfr

I would like to know if you could make a feature that would allow us to add two CSS selectors for the content in one chapter.

While such a change could be done, I'm not willing to do it. Mostly because I think it would make this interface more difficult for people to understand and use, for the small number of users it would benefit.

That said, I can tell you how to achieve what you're after.

The steps are:

  1. In WebToEpub, provide the CSS selector for an element that is a parent of both the elements you're actually interested in.
  2. Create the epub. Each chapter in the epub will now have both elements you want. (Along with some garbage.)
  3. You can now use a script with EpubEditor to process the epub and remove the garbage.

Example script.
Assume the parent selector is div.article, then the script would be something like

let parent = dom.querySelector("div.article");
let review = dom.querySelector("div.review-item");
let author = dom.querySelector("div.author-info");

if (review) {
    parent.replaceWith(review);
    if (author) {
        review.appendChild(author);
    }
    return true;
} else if (author) {
    parent.replaceWith(author);
    return true;
}
return false;

Note, if you can provide me with URL of story you want processed, I'll be able to test the script.

Notes
Time taken: 18 minutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants