HtmlReadmeReader.java

/*
 * Copyright © 2024-2025 The CTAN Team and individual authors
 *
 * This file is distributed under the 3-clause BSD license.
 * See file LICENSE for details.
 */

package org.ctan.site.services.texarchive.readme;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;

import org.jsoup.Jsoup;

/**
 * The class <code>TextReadmeReader</code> contains the reader for HTML.
 *
 * @author <a href="mailto:gene@ctan.org">Gerd Neugebauer</a>
 */
public class HtmlReadmeReader extends ReadmeReader {

    /**
     * This is the constructor for <code>HtmlReadmeReader</code>.
     *
     * @param name the file name
     */
    public HtmlReadmeReader(String name) {

        super(name);
    }

    /**
     * {@inheritDoc}
     *
     * @see org.ctan.site.services.texarchive.readme.ReadmeReader#read(
     *     java.io.File)
     */
    @Override
    public String read(File file)
            throws UnsupportedEncodingException,
                IOException {

        var doc = Jsoup
            .parse(new String(Files.readAllBytes(file.toPath()), "UTF8"));
        return "<div>" + doc.body().html() + "</div>";
    }

}