// Path: src/main/java/org/terasology/launcher/util/BundleUtils.java
// public final class BundleUtils {
// 
//     private static final Logger logger = LoggerFactory.getLogger(BundleUtils.class);
// 
//     private static final String LABELS_BUNDLE = "org.terasology.launcher.bundle.LabelsBundle";
//     private static final String MESSAGE_BUNDLE = "org.terasology.launcher.bundle.MessageBundle";
//     private static final String URI_BUNDLE = "org.terasology.launcher.bundle.URIBundle";
//     private static final String IMAGE_BUNDLE = "org.terasology.launcher.bundle.ImageBundle";
//     private static final String FXML_BUNDLE = "org.terasology.launcher.bundle.FXMLBundle";
// 
//     private BundleUtils() {
//     }
// 
//     public static String getLabel(String key) {
//         return getLabel(Languages.getCurrentLocale(), key);
//     }
// 
//     public static String getLabel(Locale locale, String key) {
//         try {
//             String label = ResourceBundle.getBundle(LABELS_BUNDLE, locale).getString(key);
//             if (label.length() == 0) {
//                 throw new IllegalArgumentException();
//             }
//             return label;
//         } catch (MissingResourceException | IllegalArgumentException e) {
//             logger.error("Missing label translation! key={}, locale={}", key, locale);
//             return ResourceBundle.getBundle(LABELS_BUNDLE, Languages.DEFAULT_LOCALE).getString(key);
//         }
//     }
// 
//     public static String getMessage(String key, Object... arguments) {
//         String pattern;
//         try {
//             pattern = ResourceBundle.getBundle(MESSAGE_BUNDLE, Languages.getCurrentLocale()).getString(key);
//             if (pattern.length() == 0) {
//                 throw new IllegalArgumentException();
//             }
//         } catch (MissingResourceException | IllegalArgumentException e) {
//             logger.error("Missing message translation! key={}, locale={}", key, Languages.getCurrentLocale());
//             pattern = ResourceBundle.getBundle(MESSAGE_BUNDLE, Languages.DEFAULT_LOCALE).getString(key);
//         }
//         final MessageFormat messageFormat = new MessageFormat(pattern, Languages.getCurrentLocale());
//         return messageFormat.format(arguments, new StringBuffer(), null).toString();
//     }
// 
//     public static URI getURI(String key) {
//         final String uriStr = ResourceBundle.getBundle(URI_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         try {
//             return new URI(uriStr);
//         } catch (URISyntaxException e) {
//             logger.error("Could not create URI '{}' for key '{}'!", uriStr, key, e);
//         }
//         return null;
//     }
// 
//     /**
//      * Loads a JavaFX {@code Image} from the image path specified by the key in the image bundle file.
//      *
//      * @param key the key as specified in the image bundle file
//      * @return the JavaFX image
//      * @throws MissingResourceException if no resource for the specified key can be found
//      */
//     public static Image getFxImage(String key) throws MissingResourceException {
//         final String imagePath = ResourceBundle.getBundle(IMAGE_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return new Image(BundleUtils.class.getResource(imagePath).toExternalForm());
//     }
// 
//     public static FXMLLoader getFXMLLoader(String key) {
//         return new FXMLLoader(getFXMLUrl(key), ResourceBundle.getBundle("org.terasology.launcher.bundle.LabelsBundle", Languages.getCurrentLocale()));
//     }
// 
//     public static URL getFXMLUrl(String key) {
//         final String url = ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return BundleUtils.class.getResource(url);
//     }
// 
//     public static URL getFXMLUrl(String key, String relative) {
//         final String url = ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return BundleUtils.class.getResource(url + '/' + relative);
//     }
// 
//     public static String getStylesheet(String key) {
//         return ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//     }
// }


import com.vladsch.flexmark.ext.emoji.EmojiExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataSet;
import javafx.fxml.FXML;
import javafx.scene.effect.BlendMode;
import javafx.scene.web.WebView;
import org.terasology.launcher.util.BundleUtils;
import java.util.Arrays;
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.ui;



public class ChangelogViewController {

    @FXML
    private WebView changelogView;

    private HtmlRenderer renderer;
    private Parser parser;

    public ChangelogViewController() {
        MutableDataSet options = new MutableDataSet();
        options.set(Parser.EXTENSIONS, Arrays.asList(EmojiExtension.create()));
        parser = Parser.builder(options).build();
        renderer = HtmlRenderer.builder(options).build();
    }

    /**
     * Update the displayed changelog based on the selected package.
     *
     * @param changes list of changes
     */
    void update(final String changes) {
        changelogView.getEngine().loadContent(makeHtml(changes));
        changelogView.setBlendMode(BlendMode.LIGHTEN);
// Path: src/main/java/org/terasology/launcher/util/BundleUtils.java
// public final class BundleUtils {
// 
//     private static final Logger logger = LoggerFactory.getLogger(BundleUtils.class);
// 
//     private static final String LABELS_BUNDLE = "org.terasology.launcher.bundle.LabelsBundle";
//     private static final String MESSAGE_BUNDLE = "org.terasology.launcher.bundle.MessageBundle";
//     private static final String URI_BUNDLE = "org.terasology.launcher.bundle.URIBundle";
//     private static final String IMAGE_BUNDLE = "org.terasology.launcher.bundle.ImageBundle";
//     private static final String FXML_BUNDLE = "org.terasology.launcher.bundle.FXMLBundle";
// 
//     private BundleUtils() {
//     }
// 
//     public static String getLabel(String key) {
//         return getLabel(Languages.getCurrentLocale(), key);
//     }
// 
//     public static String getLabel(Locale locale, String key) {
//         try {
//             String label = ResourceBundle.getBundle(LABELS_BUNDLE, locale).getString(key);
//             if (label.length() == 0) {
//                 throw new IllegalArgumentException();
//             }
//             return label;
//         } catch (MissingResourceException | IllegalArgumentException e) {
//             logger.error("Missing label translation! key={}, locale={}", key, locale);
//             return ResourceBundle.getBundle(LABELS_BUNDLE, Languages.DEFAULT_LOCALE).getString(key);
//         }
//     }
// 
//     public static String getMessage(String key, Object... arguments) {
//         String pattern;
//         try {
//             pattern = ResourceBundle.getBundle(MESSAGE_BUNDLE, Languages.getCurrentLocale()).getString(key);
//             if (pattern.length() == 0) {
//                 throw new IllegalArgumentException();
//             }
//         } catch (MissingResourceException | IllegalArgumentException e) {
//             logger.error("Missing message translation! key={}, locale={}", key, Languages.getCurrentLocale());
//             pattern = ResourceBundle.getBundle(MESSAGE_BUNDLE, Languages.DEFAULT_LOCALE).getString(key);
//         }
//         final MessageFormat messageFormat = new MessageFormat(pattern, Languages.getCurrentLocale());
//         return messageFormat.format(arguments, new StringBuffer(), null).toString();
//     }
// 
//     public static URI getURI(String key) {
//         final String uriStr = ResourceBundle.getBundle(URI_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         try {
//             return new URI(uriStr);
//         } catch (URISyntaxException e) {
//             logger.error("Could not create URI '{}' for key '{}'!", uriStr, key, e);
//         }
//         return null;
//     }
// 
//     /**
//      * Loads a JavaFX {@code Image} from the image path specified by the key in the image bundle file.
//      *
//      * @param key the key as specified in the image bundle file
//      * @return the JavaFX image
//      * @throws MissingResourceException if no resource for the specified key can be found
//      */
//     public static Image getFxImage(String key) throws MissingResourceException {
//         final String imagePath = ResourceBundle.getBundle(IMAGE_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return new Image(BundleUtils.class.getResource(imagePath).toExternalForm());
//     }
// 
//     public static FXMLLoader getFXMLLoader(String key) {
//         return new FXMLLoader(getFXMLUrl(key), ResourceBundle.getBundle("org.terasology.launcher.bundle.LabelsBundle", Languages.getCurrentLocale()));
//     }
// 
//     public static URL getFXMLUrl(String key) {
//         final String url = ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return BundleUtils.class.getResource(url);
//     }
// 
//     public static URL getFXMLUrl(String key, String relative) {
//         final String url = ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//         return BundleUtils.class.getResource(url + '/' + relative);
//     }
// 
//     public static String getStylesheet(String key) {
//         return ResourceBundle.getBundle(FXML_BUNDLE, Languages.getCurrentLocale()).getString(key);
//     }
// }


// Path: src/main/java/org/terasology/launcher/ui/ChangelogViewController.java
import com.vladsch.flexmark.ext.emoji.EmojiExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataSet;
import javafx.fxml.FXML;
import javafx.scene.effect.BlendMode;
import javafx.scene.web.WebView;
import org.terasology.launcher.util.BundleUtils;
import java.util.Arrays;

// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.launcher.ui;



public class ChangelogViewController {

    @FXML
    private WebView changelogView;

    private HtmlRenderer renderer;
    private Parser parser;

    public ChangelogViewController() {
        MutableDataSet options = new MutableDataSet();
        options.set(Parser.EXTENSIONS, Arrays.asList(EmojiExtension.create()));
        parser = Parser.builder(options).build();
        renderer = HtmlRenderer.builder(options).build();
    }

    /**
     * Update the displayed changelog based on the selected package.
     *
     * @param changes list of changes
     */
    void update(final String changes) {
        changelogView.getEngine().loadContent(makeHtml(changes));
        changelogView.setBlendMode(BlendMode.LIGHTEN);
        changelogView.getEngine().setUserStyleSheetLocation(BundleUtils.getFXMLUrl("css_webview").toExternalForm());