aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml10
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt14
-rw-r--r--COPYING.md41
-rw-r--r--flatpak/org.prismlauncher.PrismLauncher.yml1
-rw-r--r--launcher/Application.cpp42
-rw-r--r--launcher/Application.h4
-rw-r--r--launcher/CMakeLists.txt20
-rw-r--r--launcher/FileSystem.cpp5
-rw-r--r--launcher/HoeDown.h76
-rw-r--r--launcher/LaunchController.cpp10
-rw-r--r--launcher/Markdown.h34
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp4
-rw-r--r--launcher/minecraft/mod/tasks/LocalModParseTask.cpp9
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.cpp2
-rw-r--r--launcher/resources/backgrounds/backgrounds.qrc12
-rw-r--r--launcher/resources/backgrounds/teawie-bday.pngbin0 -> 190586 bytes
-rw-r--r--launcher/resources/backgrounds/teawie-spooky.pngbin0 -> 204756 bytes
-rw-r--r--launcher/resources/backgrounds/teawie-xmas.pngbin0 -> 200137 bytes
-rw-r--r--launcher/resources/backgrounds/teawie.pngbin0 -> 187972 bytes
-rw-r--r--launcher/ui/MainWindow.cpp34
-rw-r--r--launcher/ui/WinDarkmode.cpp32
-rw-r--r--launcher/ui/WinDarkmode.h60
-rw-r--r--launcher/ui/dialogs/AboutDialog.cpp6
-rw-r--r--launcher/ui/dialogs/ModUpdateDialog.cpp11
-rw-r--r--launcher/ui/dialogs/UpdateDialog.cpp5
-rw-r--r--launcher/ui/pages/global/LauncherPage.cpp105
-rw-r--r--launcher/ui/pages/global/LauncherPage.ui161
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.cpp76
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.h14
-rw-r--r--launcher/ui/pages/instance/InstanceSettingsPage.ui42
-rw-r--r--launcher/ui/pages/instance/ManagedPackPage.cpp6
-rw-r--r--launcher/ui/pages/modplatform/ModPage.cpp11
-rw-r--r--launcher/ui/pages/modplatform/ftb/FtbPage.cpp5
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp6
-rw-r--r--launcher/ui/setupwizard/SetupWizard.cpp3
-rw-r--r--launcher/ui/setupwizard/ThemeWizardPage.cpp70
-rw-r--r--launcher/ui/setupwizard/ThemeWizardPage.h43
-rw-r--r--launcher/ui/setupwizard/ThemeWizardPage.ui371
-rw-r--r--launcher/ui/themes/CustomTheme.cpp31
-rw-r--r--launcher/ui/themes/ITheme.cpp40
-rw-r--r--launcher/ui/themes/ITheme.h48
-rw-r--r--launcher/ui/themes/SystemTheme.cpp21
-rw-r--r--launcher/ui/themes/SystemTheme.h44
-rw-r--r--launcher/ui/themes/ThemeManager.cpp310
-rw-r--r--launcher/ui/themes/ThemeManager.h109
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.cpp150
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.h77
-rw-r--r--launcher/ui/widgets/ThemeCustomizationWidget.ui132
-rw-r--r--libraries/README.md8
m---------libraries/cmark0
-rw-r--r--libraries/hoedown/CMakeLists.txt26
-rw-r--r--libraries/hoedown/LICENSE15
-rw-r--r--libraries/hoedown/README.md9
-rw-r--r--libraries/hoedown/include/hoedown/autolink.h46
-rw-r--r--libraries/hoedown/include/hoedown/buffer.h134
-rw-r--r--libraries/hoedown/include/hoedown/document.h172
-rw-r--r--libraries/hoedown/include/hoedown/escape.h28
-rw-r--r--libraries/hoedown/include/hoedown/html.h84
-rw-r--r--libraries/hoedown/include/hoedown/stack.h52
-rw-r--r--libraries/hoedown/include/hoedown/version.h33
-rw-r--r--libraries/hoedown/src/autolink.c281
-rw-r--r--libraries/hoedown/src/buffer.c308
-rw-r--r--libraries/hoedown/src/document.c2958
-rw-r--r--libraries/hoedown/src/escape.c188
-rw-r--r--libraries/hoedown/src/html.c754
-rw-r--r--libraries/hoedown/src/html_blocks.c240
-rw-r--r--libraries/hoedown/src/html_smartypants.c435
-rw-r--r--libraries/hoedown/src/stack.c79
-rw-r--r--libraries/hoedown/src/version.c9
-rw-r--r--nix/default.nix2
71 files changed, 1503 insertions, 6668 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b6e179e1..1373815c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -61,7 +61,7 @@ jobs:
qt_ver: 6
qt_host: windows
qt_arch: ''
- qt_version: '6.4.0'
+ qt_version: '6.4.2'
qt_modules: 'qt5compat qtimageformats'
qt_tools: ''
@@ -73,7 +73,7 @@ jobs:
qt_ver: 6
qt_host: windows
qt_arch: 'win64_msvc2019_arm64'
- qt_version: '6.4.0'
+ qt_version: '6.4.2'
qt_modules: 'qt5compat qtimageformats'
qt_tools: ''
@@ -105,6 +105,7 @@ jobs:
INSTALL_APPIMAGE_DIR: "install-appdir"
BUILD_DIR: "build"
CCACHE_VAR: ""
+ HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
steps:
##
@@ -135,6 +136,7 @@ jobs:
quazip-qt6:p
ccache:p
qt6-5compat:p
+ cmark:p
- name: Force newer ccache
if: runner.os == 'Windows' && matrix.msystem == '' && inputs.build_type == 'Debug'
@@ -143,7 +145,7 @@ jobs:
- name: Setup ccache
if: (runner.os != 'Windows' || matrix.msystem == '') && inputs.build_type == 'Debug'
- uses: hendrikmuhs/ccache-action@v1.2.5
+ uses: hendrikmuhs/ccache-action@v1.2.8
with:
key: ${{ matrix.os }}-qt${{ matrix.qt_ver }}-${{ matrix.architecture }}
@@ -165,7 +167,7 @@ jobs:
- name: Retrieve ccache cache (Windows MinGW-w64)
if: runner.os == 'Windows' && matrix.msystem != '' && inputs.build_type == 'Debug'
- uses: actions/cache@v3.2.2
+ uses: actions/cache@v3.2.3
with:
path: '${{ github.workspace }}\.ccache'
key: ${{ matrix.os }}-mingw-w64
diff --git a/.gitmodules b/.gitmodules
index 95274f15..87703fee 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,3 +16,6 @@
[submodule "libraries/extra-cmake-modules"]
path = libraries/extra-cmake-modules
url = https://github.com/KDE/extra-cmake-modules
+[submodule "libraries/cmark"]
+ path = libraries/cmark
+ url = https://github.com/commonmark/cmark.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7ba9e9f..2194317b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -266,6 +266,9 @@ if(NOT Launcher_FORCE_BUNDLED_LIBS)
# Find ghc_filesystem
find_package(ghc_filesystem QUIET)
+
+ # Find cmark
+ find_package(cmark QUIET)
endif()
include(ECMQtDeclareLoggingCategory)
@@ -374,7 +377,6 @@ option(NBT_BUILD_TESTS "Build NBT library tests" OFF) #FIXME: fix unit tests.
add_subdirectory(libraries/libnbtplusplus)
add_subdirectory(libraries/systeminfo) # system information library
-add_subdirectory(libraries/hoedown) # markdown parser
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
add_subdirectory(libraries/javacheck) # java compatibility checker
if(NOT ZLIB_FOUND)
@@ -408,6 +410,16 @@ if(NOT tomlplusplus_FOUND)
else()
message(STATUS "Using system tomlplusplus")
endif()
+if(NOT cmark_FOUND)
+ message(STATUS "Using bundled cmark")
+ set(CMARK_STATIC ON CACHE BOOL "Build static libcmark library" FORCE)
+ set(CMARK_SHARED OFF CACHE BOOL "Build shared libcmark library" FORCE)
+ set(CMARK_TESTS OFF CACHE BOOL "Build cmark tests and enable testing" FORCE)
+ add_subdirectory(libraries/cmark EXCLUDE_FROM_ALL) # Markdown parser
+ add_library(cmark::cmark ALIAS cmark_static)
+else()
+ message(STATUS "Using system cmark")
+endif()
add_subdirectory(libraries/katabasis) # An OAuth2 library that tried to do too much
add_subdirectory(libraries/gamemode)
add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API
diff --git a/COPYING.md b/COPYING.md
index 75a5c0eb..0221d1b0 100644
--- a/COPYING.md
+++ b/COPYING.md
@@ -1,7 +1,7 @@
## Prism Launcher
Prism Launcher - Minecraft Launcher
- Copyright (C) 2022 Prism Launcher Contributors
+ Copyright (C) 2022-2023 Prism Launcher Contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -156,23 +156,34 @@
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
-## Hoedown
+## cmark
- Copyright (c) 2008, Natacha Porté
- Copyright (c) 2011, Vicent Martí
- Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
+ Copyright (c) 2014, John MacFarlane
- Permission to use, copy, modify, and distribute this software for any
- purpose with or without fee is hereby granted, provided that the above
- copyright notice and this permission notice appear in all copies.
+ All rights reserved.
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## Batch icon set
diff --git a/flatpak/org.prismlauncher.PrismLauncher.yml b/flatpak/org.prismlauncher.PrismLauncher.yml
index fca306d7..071772c6 100644
--- a/flatpak/org.prismlauncher.PrismLauncher.yml
+++ b/flatpak/org.prismlauncher.PrismLauncher.yml
@@ -39,6 +39,7 @@ modules:
sources:
- type: dir
path: ../
+ builddir: true
- name: openjdk
buildsystem: simple
build-commands:
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 8d7ff044..5f70ab94 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -62,15 +62,11 @@
#include "ui/pages/global/APIPage.h"
#include "ui/pages/global/CustomCommandsPage.h"
-#ifdef Q_OS_WIN
-#include "ui/WinDarkmode.h"
-#include <versionhelpers.h>
-#endif
-
#include "ui/setupwizard/SetupWizard.h"
#include "ui/setupwizard/LanguageWizardPage.h"
#include "ui/setupwizard/JavaWizardPage.h"
#include "ui/setupwizard/PasteWizardPage.h"
+#include "ui/setupwizard/ThemeWizardPage.h"
#include "ui/dialogs/CustomMessageBox.h"
@@ -514,7 +510,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
// Theming
m_settings->registerSetting("IconTheme", QString("pe_colored"));
- m_settings->registerSetting("ApplicationTheme", QString("system"));
+ m_settings->registerSetting("ApplicationTheme", QString());
m_settings->registerSetting("BackgroundCat", QString("kitteh"));
// Remembered state
@@ -863,10 +859,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
});
{
- setIconTheme(settings()->get("IconTheme").toString());
- qDebug() << "<> Icon theme set.";
- setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
- qDebug() << "<> Application theme set.";
+ applyCurrentlySelectedTheme();
}
updateCapabilities();
@@ -909,7 +902,8 @@ bool Application::createSetupWizard()
return false;
}();
bool pasteInterventionRequired = settings()->get("PastebinURL") != "";
- bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired;
+ bool themeInterventionRequired = settings()->get("ApplicationTheme") == "";
+ bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired;
if(wizardRequired)
{
@@ -928,6 +922,12 @@ bool Application::createSetupWizard()
{
m_setupWizard->addPage(new PasteWizardPage(m_setupWizard));
}
+
+ if (themeInterventionRequired)
+ {
+ settings()->set("ApplicationTheme", QString("system")); // set default theme after going into theme wizard
+ m_setupWizard->addPage(new ThemeWizardPage(m_setupWizard));
+ }
connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished);
m_setupWizard->show();
return true;
@@ -1135,9 +1135,14 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}
-void Application::setApplicationTheme(const QString& name, bool initial)
+void Application::applyCurrentlySelectedTheme()
+{
+ m_themeManager->applyCurrentlySelectedTheme();
+}
+
+void Application::setApplicationTheme(const QString& name)
{
- m_themeManager->setApplicationTheme(name, initial);
+ m_themeManager->setApplicationTheme(name);
}
void Application::setIconTheme(const QString& name)
@@ -1365,16 +1370,7 @@ MainWindow* Application::showMainWindow(bool minimized)
m_mainWindow = new MainWindow();
m_mainWindow->restoreState(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowState").toByteArray()));
m_mainWindow->restoreGeometry(QByteArray::fromBase64(APPLICATION->settings()->get("MainWindowGeometry").toByteArray()));
-#ifdef Q_OS_WIN
- if (IsWindows10OrGreater())
- {
- if (QString::compare(settings()->get("ApplicationTheme").toString(), "dark") == 0) {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
- } else {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
- }
- }
-#endif
+
if(minimized)
{
m_mainWindow->showMinimized();
diff --git a/launcher/Application.h b/launcher/Application.h
index cd90088e..4991f4cc 100644
--- a/launcher/Application.h
+++ b/launcher/Application.h
@@ -120,9 +120,11 @@ public:
void setIconTheme(const QString& name);
+ void applyCurrentlySelectedTheme();
+
QList<ITheme*> getValidApplicationThemes();
- void setApplicationTheme(const QString& name, bool initial);
+ void setApplicationTheme(const QString& name);
shared_qobject_ptr<UpdateChecker> updateChecker() {
return m_updateChecker;
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index a3520e72..65f58667 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -631,7 +631,7 @@ SET(LAUNCHER_SOURCES
DesktopServices.cpp
VersionProxyModel.h
VersionProxyModel.cpp
- HoeDown.h
+ Markdown.h
# Super secret!
KonamiCode.h
@@ -683,6 +683,8 @@ SET(LAUNCHER_SOURCES
ui/setupwizard/LanguageWizardPage.h
ui/setupwizard/PasteWizardPage.cpp
ui/setupwizard/PasteWizardPage.h
+ ui/setupwizard/ThemeWizardPage.cpp
+ ui/setupwizard/ThemeWizardPage.h
# GUI - themes
ui/themes/FusionTheme.cpp
@@ -922,6 +924,8 @@ SET(LAUNCHER_SOURCES
ui/widgets/ProgressWidget.cpp
ui/widgets/WideBar.h
ui/widgets/WideBar.cpp
+ ui/widgets/ThemeCustomizationWidget.h
+ ui/widgets/ThemeCustomizationWidget.cpp
# GUI - instance group view
ui/instanceview/InstanceProxyModel.cpp
@@ -937,18 +941,9 @@ SET(LAUNCHER_SOURCES
ui/instanceview/VisualGroup.h
)
-if(WIN32)
- set(LAUNCHER_SOURCES
- ${LAUNCHER_SOURCES}
-
- # GUI - dark titlebar for Windows 10/11
- ui/WinDarkmode.h
- ui/WinDarkmode.cpp
- )
-endif()
-
qt_wrap_ui(LAUNCHER_UI
ui/setupwizard/PasteWizardPage.ui
+ ui/setupwizard/ThemeWizardPage.ui
ui/pages/global/AccountListPage.ui
ui/pages/global/JavaPage.ui
ui/pages/global/LauncherPage.ui
@@ -981,6 +976,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/widgets/CustomCommands.ui
ui/widgets/InfoFrame.ui
ui/widgets/ModFilterWidget.ui
+ ui/widgets/ThemeCustomizationWidget.ui
ui/dialogs/CopyInstanceDialog.ui
ui/dialogs/ProfileSetupDialog.ui
ui/dialogs/ProgressDialog.ui
@@ -1057,7 +1053,7 @@ target_link_libraries(Launcher_logic
)
target_link_libraries(Launcher_logic
QuaZip::QuaZip
- hoedown
+ cmark::cmark
LocalPeer
Launcher_rainbow
)
diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp
index 7a135811..aee5245d 100644
--- a/launcher/FileSystem.cpp
+++ b/launcher/FileSystem.cpp
@@ -57,6 +57,7 @@
#include <shlobj.h>
#include <shobjidl.h>
#include <sys/utime.h>
+#include <versionhelpers.h>
#include <windows.h>
#include <winnls.h>
#include <string>
@@ -251,6 +252,10 @@ bool trash(QString path, QString *pathInTrash)
// FIXME: Figure out trash in Flatpak. Qt seemingly doesn't use the Trash portal
if (DesktopServices::isFlatpak())
return false;
+#if defined Q_OS_WIN32
+ if (IsWindowsServer())
+ return false;
+#endif
return QFile::moveToTrash(path, pathInTrash);
#endif
}
diff --git a/launcher/HoeDown.h b/launcher/HoeDown.h
deleted file mode 100644
index cb62de6c..00000000
--- a/launcher/HoeDown.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Copyright 2013-2021 MultiMC Contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-#include <hoedown/html.h>
-#include <hoedown/document.h>
-#include <QString>
-#include <QByteArray>
-
-/**
- * hoedown wrapper, because dealing with resource lifetime in C is stupid
- */
-class HoeDown
-{
-public:
- class buffer
- {
- public:
- buffer(size_t unit = 4096)
- {
- buf = hoedown_buffer_new(unit);
- }
- ~buffer()
- {
- hoedown_buffer_free(buf);
- }
- const char * cstr()
- {
- return hoedown_buffer_cstr(buf);
- }
- void put(QByteArray input)
- {
- hoedown_buffer_put(buf, reinterpret_cast<uint8_t *>(input.data()), input.size());
- }
- const uint8_t * data() const
- {
- return buf->data;
- }
- size_t size() const
- {
- return buf->size;
- }
- hoedown_buffer * buf;
- } ib, ob;
- HoeDown()
- {
- renderer = hoedown_html_renderer_new((hoedown_html_flags) 0,0);
- document = hoedown_document_new(renderer, (hoedown_extensions) 0, 8);
- }
- ~HoeDown()
- {
- hoedown_document_free(document);
- hoedown_html_renderer_free(renderer);
- }
- QString process(QByteArray input)
- {
- ib.put(input);
- hoedown_document_render(document, ob.buf, ib.data(), ib.size());
- return ob.cstr();
- }
-private:
- hoedown_document * document;
- hoedown_renderer * renderer;
-};
diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp
index 11e3de15..9741fd95 100644
--- a/launcher/LaunchController.cpp
+++ b/launcher/LaunchController.cpp
@@ -112,7 +112,15 @@ void LaunchController::decideAccount()
}
}
- m_accountToUse = accounts->defaultAccount();
+ // Select the account to use. If the instance has a specific account set, that will be used. Otherwise, the default account will be used
+ auto instanceAccountId = m_instance->settings()->get("InstanceAccountId").toString();
+ auto instanceAccountIndex = accounts->findAccountByProfileId(instanceAccountId);
+ if (instanceAccountIndex == -1) {
+ m_accountToUse = accounts->defaultAccount();
+ } else {
+ m_accountToUse = accounts->at(instanceAccountIndex);
+ }
+
if (!m_accountToUse)
{
// If no default account is set, ask the user which one to use.
diff --git a/launcher/Markdown.h b/launcher/Markdown.h
new file mode 100644
index 00000000..f115dd57
--- /dev/null
+++ b/launcher/Markdown.h
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Joshua Goins <josh@redstrate.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <QString>
+#include <cmark.h>
+
+static QString markdownToHTML(const QString& markdown)
+{
+ const QByteArray markdownData = markdown.toUtf8();
+ char* buffer = cmark_markdown_to_html(markdownData.constData(), markdownData.length(), CMARK_OPT_NOBREAKS | CMARK_OPT_UNSAFE);
+
+ QString htmlStr(buffer);
+
+ free(buffer);
+
+ return htmlStr;
+} \ No newline at end of file
diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp
index 1d37224a..d0a5ed31 100644
--- a/launcher/minecraft/MinecraftInstance.cpp
+++ b/launcher/minecraft/MinecraftInstance.cpp
@@ -192,6 +192,10 @@ void MinecraftInstance::loadSpecificSettings()
m_settings->registerSetting("JoinServerOnLaunch", false);
m_settings->registerSetting("JoinServerOnLaunchAddress", "");
+ // Use account for instance, this does not have a global override
+ m_settings->registerSetting("UseAccountForInstance", false);
+ m_settings->registerSetting("InstanceAccountId", "");
+
qDebug() << "Instance-type specific settings were loaded!";
setSpecificSettingsLoaded(true);
diff --git a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
index 8bfe2c84..91cb747f 100644
--- a/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
+++ b/launcher/minecraft/mod/tasks/LocalModParseTask.cpp
@@ -17,7 +17,7 @@
namespace ModUtils {
// NEW format
-// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/6f62b37cea040daf350dc253eae6326dd9c822c3
+// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/c8d8f1929aff9979e322af79a59ce81f3e02db6a
// OLD format:
// https://github.com/MinecraftForge/FML/wiki/FML-mod-information-file/5bf6a2d05145ec79387acc0d45c958642fb049fc
@@ -74,10 +74,11 @@ ModDetails ReadMCModInfo(QByteArray contents)
version = Json::ensureString(val, "").toInt();
if (version != 2) {
- qCritical() << "BAD stuff happened to mod json:";
- qCritical() << contents;
- return {};
+ qWarning() << QString(R"(The value of 'modListVersion' is "%1" (expected "2")! The file may be corrupted.)").arg(version);
+ qWarning() << "The contents of 'mcmod.info' are as follows:";
+ qWarning() << contents;
}
+
auto arrVal = jsonDoc.object().value("modlist");
if (arrVal.isUndefined()) {
arrVal = jsonDoc.object().value("modList");
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
index ae45e096..aec45a73 100644
--- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
@@ -87,7 +87,7 @@ void Modrinth::loadExtraPackData(ModPlatform::IndexedPack& pack, QJsonObject& ob
pack.extraData.donate.append(donate);
}
- pack.extraData.body = Json::ensureString(obj, "body");
+ pack.extraData.body = Json::ensureString(obj, "body").remove("<br>");
pack.extraDataLoaded = true;
}
diff --git a/launcher/resources/backgrounds/backgrounds.qrc b/launcher/resources/backgrounds/backgrounds.qrc
index e55faf15..e63a25b5 100644
--- a/launcher/resources/backgrounds/backgrounds.qrc
+++ b/launcher/resources/backgrounds/backgrounds.qrc
@@ -13,5 +13,17 @@
<file alias="rory-flat-xmas">rory-flat-xmas.png</file>
<file alias="rory-flat-bday">rory-flat-bday.png</file>
<file alias="rory-flat-spooky">rory-flat-spooky.png</file>
+ <!-- teawie images -->
+ <!-- copyright (c) SympathyTea 2023 -->
+ <!-- these are licensed under the CC BY-SA 4.0 and have been unmodified aside from downscaling -->
+ <!-- the full license with appropriate notices is avalible at https://creativecommons.org/licenses/by-sa/4.0/ -->
+ <file alias="teawie">teawie.png</file>
+ <!-- https://commons.wikimedia.org/wiki/File:Teawie.png -->
+ <file alias="teawie-xmas">teawie-xmas.png</file>
+ <!-- https://commons.wikimedia.org/wiki/File:Teawie_Holiday.png -->
+ <file alias="teawie-bday">teawie-bday.png</file>
+ <!-- https://commons.wikimedia.org/wiki/File:Teawie_Party.png -->
+ <file alias="teawie-spooky">teawie-spooky.png</file>
+ <!-- https://commons.wikimedia.org/wiki/File:Teawie_Halloween.png -->
</qresource>
</RCC>
diff --git a/launcher/resources/backgrounds/teawie-bday.png b/launcher/resources/backgrounds/teawie-bday.png
new file mode 100644
index 00000000..f4ecf247
--- /dev/null
+++ b/launcher/resources/backgrounds/teawie-bday.png
Binary files differ
diff --git a/launcher/resources/backgrounds/teawie-spooky.png b/launcher/resources/backgrounds/teawie-spooky.png
new file mode 100644
index 00000000..cefc6c85
--- /dev/null
+++ b/launcher/resources/backgrounds/teawie-spooky.png
Binary files differ
diff --git a/launcher/resources/backgrounds/teawie-xmas.png b/launcher/resources/backgrounds/teawie-xmas.png
new file mode 100644
index 00000000..55fb7cfc
--- /dev/null
+++ b/launcher/resources/backgrounds/teawie-xmas.png
Binary files differ
diff --git a/launcher/resources/backgrounds/teawie.png b/launcher/resources/backgrounds/teawie.png
new file mode 100644
index 00000000..dc32c51f
--- /dev/null
+++ b/launcher/resources/backgrounds/teawie.png
Binary files differ
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 1a2b1497..4e830b6c 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -111,6 +111,7 @@
#include "ui/dialogs/ExportInstanceDialog.h"
#include "ui/dialogs/ImportResourceDialog.h"
#include "ui/themes/ITheme.h"
+#include "ui/themes/ThemeManager.h"
#include "minecraft/mod/tasks/LocalResourceParse.h"
#include "minecraft/mod/ModFolderModel.h"
@@ -1345,7 +1346,7 @@ void MainWindow::updateThemeMenu()
themeAction->setActionGroup(themesGroup);
connect(themeAction, &QAction::triggered, [theme]() {
- APPLICATION->setApplicationTheme(theme->id(),false);
+ APPLICATION->setApplicationTheme(theme->id());
APPLICATION->settings()->set("ApplicationTheme", theme->id());
});
}
@@ -1651,32 +1652,9 @@ void MainWindow::onCatToggled(bool state)
APPLICATION->settings()->set("TheCat", state);
}
-namespace {
-template <typename T>
-T non_stupid_abs(T in)
-{
- if (in < 0)
- return -in;
- return in;
-}
-}
-
void MainWindow::setCatBackground(bool enabled)
{
- if (enabled)
- {
- QDateTime now = QDateTime::currentDateTime();
- QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
- QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
- QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
- QString cat = APPLICATION->settings()->get("BackgroundCat").toString();
- if (non_stupid_abs(now.daysTo(xmas)) <= 4) {
- cat += "-xmas";
- } else if (non_stupid_abs(now.daysTo(halloween)) <= 4) {
- cat += "-spooky";
- } else if (non_stupid_abs(now.daysTo(birthday)) <= 12) {
- cat += "-bday";
- }
+ if (enabled) {
view->setStyleSheet(QString(R"(
InstanceView
{
@@ -1687,10 +1665,8 @@ InstanceView
background-repeat: none;
background-color:palette(base);
})")
- .arg(cat));
- }
- else
- {
+ .arg(ThemeManager::getCatImage()));
+ } else {
view->setStyleSheet(QString());
}
}
diff --git a/launcher/ui/WinDarkmode.cpp b/launcher/ui/WinDarkmode.cpp
deleted file mode 100644
index eac68e4f..00000000
--- a/launcher/ui/WinDarkmode.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <QWidget>
-
-#include "WinDarkmode.h"
-
-namespace WinDarkmode {
-
-/* See https://github.com/statiolake/neovim-qt/commit/da8eaba7f0e38b6b51f3bacd02a8cc2d1f7a34d8 */
-void setDarkWinTitlebar(WId winid, bool darkmode)
-{
- HWND hwnd = reinterpret_cast<HWND>(winid);
- BOOL dark = (BOOL) darkmode;
-
- HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
- HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
- fnAllowDarkModeForWindow AllowDarkModeForWindow
- = reinterpret_cast<fnAllowDarkModeForWindow>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(133)));
- fnSetPreferredAppMode SetPreferredAppMode
- = reinterpret_cast<fnSetPreferredAppMode>(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135)));
- fnSetWindowCompositionAttribute SetWindowCompositionAttribute
- = reinterpret_cast<fnSetWindowCompositionAttribute>(GetProcAddress(hUser32, "SetWindowCompositionAttribute"));
-
- SetPreferredAppMode(AllowDark);
- AllowDarkModeForWindow(hwnd, dark);
- WINDOWCOMPOSITIONATTRIBDATA data = {
- WCA_USEDARKMODECOLORS,
- &dark,
- sizeof(dark)
- };
- SetWindowCompositionAttribute(hwnd, &data);
-}
-
-}
diff --git a/launcher/ui/WinDarkmode.h b/launcher/ui/WinDarkmode.h
deleted file mode 100644
index 5b567c6b..00000000
--- a/launcher/ui/WinDarkmode.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#pragma once
-
-#include <windows.h>
-#include <dwmapi.h>
-
-
-namespace WinDarkmode {
-
-void setDarkWinTitlebar(WId winid, bool darkmode);
-
-enum PreferredAppMode {
- Default,
- AllowDark,
- ForceDark,
- ForceLight,
- Max
-};
-
-enum WINDOWCOMPOSITIONATTRIB {
- WCA_UNDEFINED = 0,
- WCA_NCRENDERING_ENABLED = 1,
- WCA_NCRENDERING_POLICY = 2,
- WCA_TRANSITIONS_FORCEDISABLED = 3,
- WCA_ALLOW_NCPAINT = 4,
- WCA_CAPTION_BUTTON_BOUNDS = 5,
- WCA_NONCLIENT_RTL_LAYOUT = 6,
- WCA_FORCE_ICONIC_REPRESENTATION = 7,
- WCA_EXTENDED_FRAME_BOUNDS = 8,
- WCA_HAS_ICONIC_BITMAP = 9,
- WCA_THEME_ATTRIBUTES = 10,
- WCA_NCRENDERING_EXILED = 11,
- WCA_NCADORNMENTINFO = 12,
- WCA_EXCLUDED_FROM_LIVEPREVIEW = 13,
- WCA_VIDEO_OVERLAY_ACTIVE = 14,
- WCA_FORCE_ACTIVEWINDOW_APPEARANCE = 15,
- WCA_DISALLOW_PEEK = 16,
- WCA_CLOAK = 17,
- WCA_CLOAKED = 18,
- WCA_ACCENT_POLICY = 19,
- WCA_FREEZE_REPRESENTATION = 20,
- WCA_EVER_UNCLOAKED = 21,
- WCA_VISUAL_OWNER = 22,
- WCA_HOLOGRAPHIC = 23,
- WCA_EXCLUDED_FROM_DDA = 24,
- WCA_PASSIVEUPDATEMODE = 25,
- WCA_USEDARKMODECOLORS = 26,
- WCA_LAST = 27
-};
-
-struct WINDOWCOMPOSITIONATTRIBDATA {
- WINDOWCOMPOSITIONATTRIB Attrib;
- PVOID pvData;
- SIZE_T cbData;
-};
-
-using fnAllowDarkModeForWindow = BOOL (WINAPI *)(HWND hWnd, BOOL allow);
-using fnSetPreferredAppMode = PreferredAppMode (WINAPI *)(PreferredAppMode appMode);
-using fnSetWindowCompositionAttribute = BOOL (WINAPI *)(HWND hwnd, WINDOWCOMPOSITIONATTRIBDATA *);
-
-}
diff --git a/launcher/ui/dialogs/AboutDialog.cpp b/launcher/ui/dialogs/AboutDialog.cpp
index a36e4a3d..76e3d8ed 100644
--- a/launcher/ui/dialogs/AboutDialog.cpp
+++ b/launcher/ui/dialogs/AboutDialog.cpp
@@ -39,12 +39,11 @@
#include <QIcon>
#include "Application.h"
#include "BuildConfig.h"
+#include "Markdown.h"
#include <net/NetJob.h>
#include <qobject.h>
-#include "HoeDown.h"
-
namespace {
QString getLink(QString link, QString name) {
return QString("&lt;<a href='%1'>%2</a>&gt;").arg(link).arg(name);
@@ -114,10 +113,9 @@ QString getCreditsHtml()
QString getLicenseHtml()
{
- HoeDown hoedown;
QFile dataFile(":/documents/COPYING.md");
dataFile.open(QIODevice::ReadOnly);
- QString output = hoedown.process(dataFile.readAll());
+ QString output = markdownToHTML(dataFile.readAll());
return output;
}
diff --git a/launcher/ui/dialogs/ModUpdateDialog.cpp b/launcher/ui/dialogs/ModUpdateDialog.cpp
index cedd4a96..2704243e 100644
--- a/launcher/ui/dialogs/ModUpdateDialog.cpp
+++ b/launcher/ui/dialogs/ModUpdateDialog.cpp
@@ -7,6 +7,7 @@
#include "FileSystem.h"
#include "Json.h"
+#include "Markdown.h"
#include "tasks/ConcurrentTask.h"
@@ -17,7 +18,6 @@
#include "modplatform/flame/FlameCheckUpdate.h"
#include "modplatform/modrinth/ModrinthCheckUpdate.h"
-#include <HoeDown.h>
#include <QTextBrowser>
#include <QTreeWidgetItem>
@@ -369,14 +369,7 @@ void ModUpdateDialog::appendMod(CheckUpdateTask::UpdatableMod const& info)
QString text = info.changelog;
switch (info.provider) {
case ModPlatform::Provider::MODRINTH: {
- HoeDown h;
- // HoeDown bug?: \n aren't converted to <br>
- text = h.process(info.changelog.toUtf8());
-
- // Don't convert if there's an HTML tag right after (Qt rendering weirdness)
- text.remove(QRegularExpression("(\n+)(?=<)"));
- text.replace('\n', "<br>");
-
+ text = markdownToHTML(info.changelog.toUtf8());
break;
}
default:
diff --git a/launcher/ui/dialogs/UpdateDialog.cpp b/launcher/ui/dialogs/UpdateDialog.cpp
index 9e82531a..349d768f 100644
--- a/launcher/ui/dialogs/UpdateDialog.cpp
+++ b/launcher/ui/dialogs/UpdateDialog.cpp
@@ -41,7 +41,7 @@
#include <Json.h>
#include "BuildConfig.h"
-#include "HoeDown.h"
+#include "Markdown.h"
UpdateDialog::UpdateDialog(bool hasUpdate, QWidget *parent) : QDialog(parent), ui(new Ui::UpdateDialog)
{
@@ -89,8 +89,7 @@ void UpdateDialog::loadChangelog()
QString reprocessMarkdown(QByteArray markdown)
{
- HoeDown hoedown;
- QString output = hoedown.process(markdown);
+ QString output = markdownToHTML(markdown);
// HACK: easier than customizing hoedown
output.replace(QRegularExpression("GH-([0-9]+)"), "<a href=\"https://github.com/PrismLauncher/PrismLauncher/issues/\\1\">GH-\\1</a>");
diff --git a/launcher/ui/pages/global/LauncherPage.cpp b/launcher/ui/pages/global/LauncherPage.cpp
index cae0635f..69a8e3df 100644
--- a/launcher/ui/pages/global/LauncherPage.cpp
+++ b/launcher/ui/pages/global/LauncherPage.cpp
@@ -286,72 +286,6 @@ void LauncherPage::applySettings()
}
s->set("UpdateChannel", m_currentUpdateChannel);
- auto original = s->get("IconTheme").toString();
- //FIXME: make generic
- switch (ui->themeComboBox->currentIndex())
- {
- case 0:
- s->set("IconTheme", "pe_colored");
- break;
- case 1:
- s->set("IconTheme", "pe_light");
- break;
- case 2:
- s->set("IconTheme", "pe_dark");
- break;
- case 3:
- s->set("IconTheme", "pe_blue");
- break;
- case 4:
- s->set("IconTheme", "breeze_light");
- break;
- case 5:
- s->set("IconTheme", "breeze_dark");
- break;
- case 6:
- s->set("IconTheme", "OSX");
- break;
- case 7:
- s->set("IconTheme", "iOS");
- break;
- case 8:
- s->set("IconTheme", "flat");
- break;
- case 9:
- s->set("IconTheme", "flat_white");
- break;
- case 10:
- s->set("IconTheme", "multimc");
- break;
- case 11:
- s->set("IconTheme", "custom");
- break;
- }
-
- if(original != s->get("IconTheme"))
- {
- APPLICATION->setIconTheme(s->get("IconTheme").toString());
- }
-
- auto originalAppTheme = s->get("ApplicationTheme").toString();
- auto newAppTheme = ui->themeComboBoxColors->currentData().toString();
- if(originalAppTheme != newAppTheme)
- {
- s->set("ApplicationTheme", newAppTheme);
- APPLICATION->setApplicationTheme(newAppTheme, false);
- }
-
- switch (ui->themeBackgroundCat->currentIndex()) {
- case 0: // original cat
- s->set("BackgroundCat", "kitteh");
- break;
- case 1: // rory the cat
- s->set("BackgroundCat", "rory");
- break;
- case 2: // rory the cat flat edition
- s->set("BackgroundCat", "rory-flat");
- break;
- }
s->set("MenuBarInsteadOfToolBar", ui->preferMenuBarCheckBox->isChecked());
@@ -401,45 +335,6 @@ void LauncherPage::loadSettings()
}
m_currentUpdateChannel = s->get("UpdateChannel").toString();
- //FIXME: make generic
- auto theme = s->get("IconTheme").toString();
- QStringList iconThemeOptions{"pe_colored",
- "pe_light",
- "pe_dark",
- "pe_blue",
- "breeze_light",
- "breeze_dark",
- "OSX",
- "iOS",
- "flat",
- "flat_white",
- "multimc",
- "custom"};
- ui->themeComboBox->setCurrentIndex(iconThemeOptions.indexOf(theme));
-
- auto cat = s->get("BackgroundCat").toString();
- if (cat == "kitteh") {
- ui->themeBackgroundCat->setCurrentIndex(0);
- } else if (cat == "rory") {
- ui->themeBackgroundCat->setCurrentIndex(1);
- } else if (cat == "rory-flat") {
- ui->themeBackgroundCat->setCurrentIndex(2);
- }
-
- {
- auto currentTheme = s->get("ApplicationTheme").toString();
- auto themes = APPLICATION->getValidApplicationThemes();
- int idx = 0;
- for(auto &theme: themes)
- {
- ui->themeComboBoxColors->addItem(theme->name(), theme->id());
- if(currentTheme == theme->id())
- {
- ui->themeComboBoxColors->setCurrentIndex(idx);
- }
- idx++;
- }
- }
// Toolbar/menu bar settings (not applicable if native menu bar is present)
ui->toolsBox->setEnabled(!QMenuBar().isNativeMenuBar());
diff --git a/launcher/ui/pages/global/LauncherPage.ui b/launcher/ui/pages/global/LauncherPage.ui
index c44718a1..65f4a9d5 100644
--- a/launcher/ui/pages/global/LauncherPage.ui
+++ b/launcher/ui/pages/global/LauncherPage.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>514</width>
+ <width>511</width>
<height>629</height>
</rect>
</property>
@@ -38,7 +38,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>1</number>
</property>
<widget class="QWidget" name="featuresTab">
<attribute name="title">
@@ -243,150 +243,9 @@
<property name="title">
<string>Theme</string>
</property>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label_3">
- <property name="text">
- <string>&amp;Icons</string>
- </property>
- <property name="buddy">
- <cstring>themeComboBox</cstring>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="themeComboBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <item>
- <property name="text">
- <string>Simple (Colored Icons)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Simple (Light Icons)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Simple (Dark Icons)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Simple (Blue Icons)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Breeze Light</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Breeze Dark</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">OSX</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string notr="true">iOS</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Flat</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Flat (White)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Legacy</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Custom</string>
- </property>
- </item>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_4">
- <property name="text">
- <string>&amp;Colors</string>
- </property>
- <property name="buddy">
- <cstring>themeComboBoxColors</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QComboBox" name="themeComboBoxColors">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>C&amp;at</string>
- </property>
- <property name="buddy">
- <cstring>themeBackgroundCat</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QComboBox" name="themeBackgroundCat">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="focusPolicy">
- <enum>Qt::StrongFocus</enum>
- </property>
- <item>
- <property name="text">
- <string>Background Cat (from MultiMC)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Rory ID 11 (drawn by Ashtaka)</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Rory ID 11 (flat edition, drawn by Ashtaka)</string>
- </property>
- </item>
- </widget>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="ThemeCustomizationWidget" name="themeCustomizationWidget" native="true"/>
</item>
</layout>
</widget>
@@ -570,6 +429,14 @@
</item>
</layout>
</widget>
+ <customwidgets>
+ <customwidget>
+ <class>ThemeCustomizationWidget</class>
+ <extends>QWidget</extends>
+ <header>ui/widgets/ThemeCustomizationWidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>autoUpdateCheckBox</tabstop>
@@ -582,8 +449,6 @@
<tabstop>iconsDirBrowseBtn</tabstop>
<tabstop>sortLastLaunchedBtn</tabstop>
<tabstop>sortByNameBtn</tabstop>
- <tabstop>themeComboBox</tabstop>
- <tabstop>themeComboBoxColors</tabstop>
<tabstop>showConsoleCheck</tabstop>
<tabstop>autoCloseConsoleCheck</tabstop>
<tabstop>showConsoleErrorCheck</tabstop>
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.cpp b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
index af2ba7c8..4b4c73dc 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.cpp
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.cpp
@@ -48,18 +48,23 @@
#include "JavaCommon.h"
#include "Application.h"
+#include "minecraft/auth/AccountList.h"
#include "java/JavaInstallList.h"
#include "java/JavaUtils.h"
#include "FileSystem.h"
-
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
{
m_settings = inst->settings();
ui->setupUi(this);
+ accountMenu = new QMenu(this);
+ // Use undocumented property... https://stackoverflow.com/questions/7121718/create-a-scrollbar-in-a-submenu-qt
+ accountMenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
+ ui->instanceAccountSelector->setMenu(accountMenu);
+
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
@@ -275,6 +280,13 @@ void InstanceSettingsPage::applySettings()
m_settings->reset("JoinServerOnLaunchAddress");
}
+ // Use an account for this instance
+ bool useAccountForInstance = ui->instanceAccountGroupBox->isChecked();
+ m_settings->set("UseAccountForInstance", useAccountForInstance);
+ if (!useAccountForInstance) {
+ m_settings->reset("InstanceAccountId");
+ }
+
// FIXME: This should probably be called by a signal instead
m_instance->updateRuntimeContext();
}
@@ -372,6 +384,9 @@ void InstanceSettingsPage::loadSettings()
ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
+
+ ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
+ updateAccountsMenu();
}
void InstanceSettingsPage::on_javaDetectBtn_clicked()
@@ -437,6 +452,65 @@ void InstanceSettingsPage::on_javaTestBtn_clicked()
checker->run();
}
+void InstanceSettingsPage::updateAccountsMenu()
+{
+ accountMenu->clear();
+
+ auto accounts = APPLICATION->accounts();
+ int accountIndex = accounts->findAccountByProfileId(m_settings->get("InstanceAccountId").toString());
+ MinecraftAccountPtr defaultAccount = accounts->defaultAccount();
+
+ if (accountIndex != -1 && accounts->at(accountIndex)) {
+ defaultAccount = accounts->at(accountIndex);
+ }
+
+ if (defaultAccount) {
+ ui->instanceAccountSelector->setText(defaultAccount->profileName());
+ ui->instanceAccountSelector->setIcon(getFaceForAccount(defaultAccount));
+ } else {
+ ui->instanceAccountSelector->setText(tr("No default account"));
+ ui->instanceAccountSelector->setIcon(APPLICATION->getThemedIcon("noaccount"));
+ }
+
+ for (int i = 0; i < accounts->count(); i++) {
+ MinecraftAccountPtr account = accounts->at(i);
+ QAction* action = new QAction(account->profileName(), this);
+ action->setData(i);
+ action->setCheckable(true);
+ if (accountIndex == i) {
+ action->setChecked(true);
+ }
+ action->setIcon(getFaceForAccount(account));
+ accountMenu->addAction(action);
+ connect(action, SIGNAL(triggered(bool)), this, SLOT(changeInstanceAccount()));
+ }
+}
+
+QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account)
+{
+ if (auto face = account->getFace(); !face.isNull()) {
+ return face;
+ }
+
+ return APPLICATION->getThemedIcon("noaccount");
+}
+
+void InstanceSettingsPage::changeInstanceAccount()
+{
+ QAction* sAction = (QAction*)sender();
+
+ Q_ASSERT(sAction->data().type() == QVariant::Type::Int);
+
+ QVariant data = sAction->data();
+ int index = data.toInt();
+ auto accounts = APPLICATION->accounts();
+ auto account = accounts->at(index);
+ m_settings->set("InstanceAccountId", account->profileId());
+
+ ui->instanceAccountSelector->setText(account->profileName());
+ ui->instanceAccountSelector->setIcon(getFaceForAccount(account));
+}
+
void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i)
{
updateThresholds();
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.h b/launcher/ui/pages/instance/InstanceSettingsPage.h
index 7450188d..cb6fbae0 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.h
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.h
@@ -37,12 +37,13 @@
#include <QWidget>
-#include "java/JavaChecker.h"
-#include "BaseInstance.h"
#include <QObjectPtr.h>
-#include "ui/pages/BasePage.h"
-#include "JavaCommon.h"
+#include <QMenu>
#include "Application.h"
+#include "BaseInstance.h"
+#include "JavaCommon.h"
+#include "java/JavaChecker.h"
+#include "ui/pages/BasePage.h"
class JavaChecker;
namespace Ui
@@ -92,9 +93,14 @@ private slots:
void globalSettingsButtonClicked(bool checked);
+ void updateAccountsMenu();
+ QIcon getFaceForAccount(MinecraftAccountPtr account);
+ void changeInstanceAccount();
+
private:
Ui::InstanceSettingsPage *ui;
BaseInstance *m_instance;
SettingsObjectPtr m_settings;
unique_qobject_ptr<JavaCommon::TestCheck> checker;
+ QMenu *accountMenu = nullptr;
};
diff --git a/launcher/ui/pages/instance/InstanceSettingsPage.ui b/launcher/ui/pages/instance/InstanceSettingsPage.ui
index b064367d..1b986184 100644
--- a/launcher/ui/pages/instance/InstanceSettingsPage.ui
+++ b/launcher/ui/pages/instance/InstanceSettingsPage.ui
@@ -609,6 +609,48 @@
</widget>
</item>
<item>
+ <widget class="QGroupBox" name="instanceAccountGroupBox">
+ <property name="title">
+ <string>Override default account</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_15">
+ <item>
+ <layout class="QGridLayout" name="instanceAccountLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="instanceAccountNameLabel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Account:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QToolButton" name="instanceAccountSelector">
+ <property name="popupMode">
+ <enum>QToolButton::InstantPopup</enum>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
<spacer name="verticalSpacerMiscellaneous">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp
index 4de80468..8d56d894 100644
--- a/launcher/ui/pages/instance/ManagedPackPage.cpp
+++ b/launcher/ui/pages/instance/ManagedPackPage.cpp
@@ -9,14 +9,13 @@
#include <QProxyStyle>
#include <QStyleFactory>
-#include <HoeDown.h>
-
#include "Application.h"
#include "BuildConfig.h"
#include "InstanceImportTask.h"
#include "InstanceList.h"
#include "InstanceTask.h"
#include "Json.h"
+#include "Markdown.h"
#include "modplatform/modrinth/ModrinthPackManifest.h"
@@ -263,8 +262,7 @@ void ModrinthManagedPackPage::suggestVersion()
auto index = ui->versionsComboBox->currentIndex();
auto version = m_pack.versions.at(index);
- HoeDown md_parser;
- ui->changelogTextBrowser->setHtml(md_parser.process(version.changelog.toUtf8()));
+ ui->changelogTextBrowser->setHtml(markdownToHTML(version.changelog.toUtf8()));
ManagedPackPage::suggestVersion();
}
diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp
index 75be25b2..0f30689e 100644
--- a/launcher/ui/pages/modplatform/ModPage.cpp
+++ b/launcher/ui/pages/modplatform/ModPage.cpp
@@ -43,13 +43,11 @@
#include <QRegularExpression>
#include <memory>
-#include <HoeDown.h>
-
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "ui/dialogs/ModDownloadDialog.h"
#include "ui/widgets/ProjectItem.h"
-
+#include "Markdown.h"
ModPage::ModPage(ModDownloadDialog* dialog, BaseInstance* instance, ModAPI* api)
: QWidget(dialog)
@@ -427,11 +425,6 @@ void ModPage::updateUi()
text += "<hr>";
- HoeDown h;
-
- // hoedown bug: it doesn't handle markdown surrounded by block tags (like center, div) so strip them
- current.extraData.body.remove(QRegularExpression("<[^>]*(?:center|div)\\W*>"));
-
- ui->packDescription->setHtml(text + (current.extraData.body.isEmpty() ? current.description : h.process(current.extraData.body.toUtf8())));
+ ui->packDescription->setHtml(text + (current.extraData.body.isEmpty() ? current.description : markdownToHTML(current.extraData.body)));
ui->packDescription->flush();
}
diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
index b08f3bc4..7d59a6ae 100644
--- a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
+++ b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
@@ -43,7 +43,7 @@
#include "ui/dialogs/NewInstanceDialog.h"
#include "modplatform/modpacksch/FTBPackInstallTask.h"
-#include "HoeDown.h"
+#include "Markdown.h"
FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent)
: QWidget(parent), ui(new Ui::FtbPage), dialog(dialog)
@@ -175,8 +175,7 @@ void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second)
selected = filterModel->data(first, Qt::UserRole).value<ModpacksCH::Modpack>();
- HoeDown hoedown;
- QString output = hoedown.process(selected.description.toUtf8());
+ QString output = markdownToHTML(selected.description.toUtf8());
ui->packDescription->setHtml(output);
// reverse foreach, so that the newest versions are first
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index 8ab2ad1d..0bb11d83 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -42,11 +42,10 @@
#include "BuildConfig.h"
#include "InstanceImportTask.h"
#include "Json.h"
+#include "Markdown.h"
#include "ui/widgets/ProjectItem.h"
-#include <HoeDown.h>
-
#include <QComboBox>
#include <QKeyEvent>
#include <QPushButton>
@@ -280,8 +279,7 @@ void ModrinthPage::updateUI()
text += "<hr>";
- HoeDown h;
- text += h.process(current.extra.body.toUtf8());
+ text += markdownToHTML(current.extra.body.toUtf8());
ui->packDescription->setHtml(text + current.description);
ui->packDescription->flush();
diff --git a/launcher/ui/setupwizard/SetupWizard.cpp b/launcher/ui/setupwizard/SetupWizard.cpp
index 3c8b5d39..3fd9bb23 100644
--- a/launcher/ui/setupwizard/SetupWizard.cpp
+++ b/launcher/ui/setupwizard/SetupWizard.cpp
@@ -13,7 +13,8 @@
SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent)
{
setObjectName(QStringLiteral("SetupWizard"));
- resize(615, 659);
+ resize(620, 660);
+ setMinimumSize(300, 400);
// make it ugly everywhere to avoid variability in theming
setWizardStyle(QWizard::ClassicStyle);
setOptions(QWizard::NoCancelButton | QWizard::IndependentPages | QWizard::HaveCustomButton1);
diff --git a/launcher/ui/setupwizard/ThemeWizardPage.cpp b/launcher/ui/setupwizard/ThemeWizardPage.cpp
new file mode 100644
index 00000000..42826aba
--- /dev/null
+++ b/launcher/ui/setupwizard/ThemeWizardPage.cpp
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "ThemeWizardPage.h"
+#include "ui_ThemeWizardPage.h"
+
+#include "Application.h"
+#include "ui/themes/ITheme.h"
+#include "ui/themes/ThemeManager.h"
+#include "ui/widgets/ThemeCustomizationWidget.h"
+#include "ui_ThemeCustomizationWidget.h"
+
+ThemeWizardPage::ThemeWizardPage(QWidget* parent) : BaseWizardPage(parent), ui(new Ui::ThemeWizardPage)
+{
+ ui->setupUi(this);
+
+ connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentIconThemeChanged, this, &ThemeWizardPage::updateIcons);
+ connect(ui->themeCustomizationWidget, &ThemeCustomizationWidget::currentCatChanged, this, &ThemeWizardPage::updateCat);
+
+ updateIcons();
+ updateCat();
+}
+
+ThemeWizardPage::~ThemeWizardPage()
+{
+ delete ui;
+}
+
+void ThemeWizardPage::updateIcons()
+{
+ qDebug() << "Setting Icons";
+ ui->previewIconButton0->setIcon(APPLICATION->getThemedIcon("new"));
+ ui->previewIconButton1->setIcon(APPLICATION->getThemedIcon("centralmods"));
+ ui->previewIconButton2->setIcon(APPLICATION->getThemedIcon("viewfolder"));
+ ui->previewIconButton3->setIcon(APPLICATION->getThemedIcon("launch"));
+ ui->previewIconButton4->setIcon(APPLICATION->getThemedIcon("copy"));
+ ui->previewIconButton5->setIcon(APPLICATION->getThemedIcon("export"));
+ ui->previewIconButton6->setIcon(APPLICATION->getThemedIcon("delete"));
+ ui->previewIconButton7->setIcon(APPLICATION->getThemedIcon("about"));
+ ui->previewIconButton8->setIcon(APPLICATION->getThemedIcon("settings"));
+ ui->previewIconButton9->setIcon(APPLICATION->getThemedIcon("cat"));
+ update();
+ repaint();
+ parentWidget()->update();
+}
+
+void ThemeWizardPage::updateCat()
+{
+ qDebug() << "Setting Cat";
+ ui->catImagePreviewButton->setIcon(QIcon(QString(R"(:/backgrounds/%1)").arg(ThemeManager::getCatImage())));
+}
+
+void ThemeWizardPage::retranslate()
+{
+ ui->retranslateUi(this);
+}
diff --git a/launcher/ui/setupwizard/ThemeWizardPage.h b/launcher/ui/setupwizard/ThemeWizardPage.h
new file mode 100644
index 00000000..61a3d0c0
--- /dev/null
+++ b/launcher/ui/setupwizard/ThemeWizardPage.h
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <QWidget>
+#include "BaseWizardPage.h"
+
+namespace Ui {
+class ThemeWizardPage;
+}
+
+class ThemeWizardPage : public BaseWizardPage {
+ Q_OBJECT
+
+ public:
+ explicit ThemeWizardPage(QWidget* parent = nullptr);
+ ~ThemeWizardPage();
+
+ bool validatePage() override { return true; };
+ void retranslate() override;
+
+ private slots:
+ void updateIcons();
+ void updateCat();
+
+ private:
+ Ui::ThemeWizardPage* ui;
+};
diff --git a/launcher/ui/setupwizard/ThemeWizardPage.ui b/launcher/ui/setupwizard/ThemeWizardPage.ui
new file mode 100644
index 00000000..01394ea4
--- /dev/null
+++ b/launcher/ui/setupwizard/ThemeWizardPage.ui
@@ -0,0 +1,371 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ThemeWizardPage</class>
+ <widget class="QWizardPage" name="ThemeWizardPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>510</width>
+ <height>552</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>WizardPage</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Select the Theme you wish to use</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="ThemeCustomizationWidget" name="themeCustomizationWidget" native="true">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>100</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Hint: The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string> Preview:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QGridLayout" name="iconPreview">
+ <item row="0" column="2">
+ <widget class="QPushButton" name="previewIconButton2">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="5">
+ <widget class="QPushButton" name="previewIconButton5">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="7">
+ <widget class="QPushButton" name="previewIconButton7">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="4">
+ <widget class="QPushButton" name="previewIconButton4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="previewIconButton1">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="centralmods">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QPushButton" name="previewIconButton0">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="9">
+ <widget class="QPushButton" name="previewIconButton9">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="viewfolder">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="6">
+ <widget class="QPushButton" name="previewIconButton6">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="new">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <widget class="QPushButton" name="previewIconButton3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="8">
+ <widget class="QPushButton" name="previewIconButton8">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>30</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="icon">
+ <iconset theme="applications-engineering">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QPushButton" name="catImagePreviewButton">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>256</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>The cat appears in the background and does not serve a purpose, it is purely visual.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>256</width>
+ <height>256</height>
+ </size>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>193</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>ThemeCustomizationWidget</class>
+ <extends>QWidget</extends>
+ <header>ui/widgets/ThemeCustomizationWidget.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/launcher/ui/themes/CustomTheme.cpp b/launcher/ui/themes/CustomTheme.cpp
index 3ad61668..198e76ba 100644
--- a/launcher/ui/themes/CustomTheme.cpp
+++ b/launcher/ui/themes/CustomTheme.cpp
@@ -167,8 +167,6 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
if (!FS::ensureFolderPathExists(path) || !FS::ensureFolderPathExists(pathResources)) {
themeWarningLog() << "couldn't create folder for theme!";
- m_palette = baseTheme->colorScheme();
- m_styleSheet = baseTheme->appStyleSheet();
return;
}
@@ -177,18 +175,15 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
bool jsonDataIncomplete = false;
m_palette = baseTheme->colorScheme();
- if (!readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) {
- themeDebugLog() << "Did not read theme json file correctly, writing new one to: " << themeFilePath;
- m_name = "Custom";
- m_palette = baseTheme->colorScheme();
- m_fadeColor = baseTheme->fadeColor();
- m_fadeAmount = baseTheme->fadeAmount();
- m_widgets = baseTheme->qtTheme();
- m_qssFilePath = "themeStyle.css";
- } else {
+ if (readThemeJson(themeFilePath, m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath, jsonDataIncomplete)) {
+ // If theme data was found, fade "Disabled" color of each role according to FadeAmount
m_palette = fadeInactive(m_palette, m_fadeAmount, m_fadeColor);
+ } else {
+ themeDebugLog() << "Did not read theme json file correctly, not changing theme, keeping previous.";
+ return;
}
+ // FIXME: This is kinda jank, it only actually checks if the qss file path is not present. It should actually check for any relevant missing data (e.g. name, colors)
if (jsonDataIncomplete) {
writeThemeJson(fileInfo.absoluteFilePath(), m_palette, m_fadeAmount, m_fadeColor, m_name, m_widgets, m_qssFilePath);
}
@@ -197,20 +192,14 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QFileInfo& fileInfo, bool isManifest
QFileInfo info(qssFilePath);
if (info.isFile()) {
try {
- // TODO: validate css?
+ // TODO: validate qss?
m_styleSheet = QString::fromUtf8(FS::read(qssFilePath));
} catch (const Exception& e) {
- themeWarningLog() << "Couldn't load css:" << e.cause() << "from" << qssFilePath;
- m_styleSheet = baseTheme->appStyleSheet();
+ themeWarningLog() << "Couldn't load qss:" << e.cause() << "from" << qssFilePath;
+ return;
}
} else {
- themeDebugLog() << "No theme css present.";
- m_styleSheet = baseTheme->appStyleSheet();
- try {
- FS::write(qssFilePath, m_styleSheet.toUtf8());
- } catch (const Exception& e) {
- themeWarningLog() << "Couldn't write css:" << e.cause() << "to" << qssFilePath;
- }
+ themeDebugLog() << "No theme qss present.";
}
} else {
m_id = fileInfo.fileName();
diff --git a/launcher/ui/themes/ITheme.cpp b/launcher/ui/themes/ITheme.cpp
index 8bfc466d..22043e44 100644
--- a/launcher/ui/themes/ITheme.cpp
+++ b/launcher/ui/themes/ITheme.cpp
@@ -1,19 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#include "ITheme.h"
#include "rainbow.h"
#include <QStyleFactory>
#include <QDir>
#include "Application.h"
-void ITheme::apply(bool)
+void ITheme::apply()
{
APPLICATION->setStyleSheet(QString());
QApplication::setStyle(QStyleFactory::create(qtTheme()));
if (hasColorScheme()) {
QApplication::setPalette(colorScheme());
}
- if (hasStyleSheet())
- APPLICATION->setStyleSheet(appStyleSheet());
-
+ APPLICATION->setStyleSheet(appStyleSheet());
QDir::setSearchPaths("theme", searchPaths());
}
diff --git a/launcher/ui/themes/ITheme.h b/launcher/ui/themes/ITheme.h
index c2347cf6..2e5b7f25 100644
--- a/launcher/ui/themes/ITheme.h
+++ b/launcher/ui/themes/ITheme.h
@@ -1,14 +1,47 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#pragma once
-#include <QString>
#include <QPalette>
+#include <QString>
class QStyle;
-class ITheme
-{
-public:
+class ITheme {
+ public:
virtual ~ITheme() {}
- virtual void apply(bool initial);
+ virtual void apply();
virtual QString id() = 0;
virtual QString name() = 0;
virtual bool hasStyleSheet() = 0;
@@ -18,10 +51,7 @@ public:
virtual QPalette colorScheme() = 0;
virtual QColor fadeColor() = 0;
virtual double fadeAmount() = 0;
- virtual QStringList searchPaths()
- {
- return {};
- }
+ virtual QStringList searchPaths() { return {}; }
static QPalette fadeInactive(QPalette in, qreal bias, QColor color);
};
diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp
index a63d1741..24875e33 100644
--- a/launcher/ui/themes/SystemTheme.cpp
+++ b/launcher/ui/themes/SystemTheme.cpp
@@ -34,24 +34,22 @@
*/
#include "SystemTheme.h"
#include <QApplication>
+#include <QDebug>
#include <QStyle>
#include <QStyleFactory>
-#include <QDebug>
#include "ThemeManager.h"
SystemTheme::SystemTheme()
{
themeDebugLog() << "Determining System Theme...";
- const auto & style = QApplication::style();
+ const auto& style = QApplication::style();
systemPalette = style->standardPalette();
QString lowerThemeName = style->objectName();
themeDebugLog() << "System theme seems to be:" << lowerThemeName;
QStringList styles = QStyleFactory::keys();
- for(auto &st: styles)
- {
+ for (auto& st : styles) {
themeDebugLog() << "Considering theme from theme factory:" << st.toLower();
- if(st.toLower() == lowerThemeName)
- {
+ if (st.toLower() == lowerThemeName) {
systemTheme = st;
themeDebugLog() << "System theme has been determined to be:" << systemTheme;
return;
@@ -62,14 +60,9 @@ SystemTheme::SystemTheme()
themeDebugLog() << "System theme not found, defaulted to Fusion";
}
-void SystemTheme::apply(bool initial)
+void SystemTheme::apply()
{
- // if we are applying the system theme as the first theme, just don't touch anything. it's for the better...
- if(initial)
- {
- return;
- }
- ITheme::apply(initial);
+ ITheme::apply();
}
QString SystemTheme::id()
@@ -104,7 +97,7 @@ double SystemTheme::fadeAmount()
QColor SystemTheme::fadeColor()
{
- return QColor(128,128,128);
+ return QColor(128, 128, 128);
}
bool SystemTheme::hasStyleSheet()
diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h
index fe450600..b5c03def 100644
--- a/launcher/ui/themes/SystemTheme.h
+++ b/launcher/ui/themes/SystemTheme.h
@@ -1,13 +1,46 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * This file incorporates work covered by the following copyright and
+ * permission notice:
+ *
+ * Copyright 2013-2021 MultiMC Contributors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
#pragma once
#include "ITheme.h"
-class SystemTheme: public ITheme
-{
-public:
+class SystemTheme : public ITheme {
+ public:
SystemTheme();
virtual ~SystemTheme() {}
- void apply(bool initial) override;
+ void apply() override;
QString id() override;
QString name() override;
@@ -18,7 +51,8 @@ public:
QPalette colorScheme() override;
double fadeAmount() override;
QColor fadeColor() override;
-private:
+
+ private:
QPalette systemPalette;
QString systemTheme;
};
diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp
index 01a38a86..13406485 100644
--- a/launcher/ui/themes/ThemeManager.cpp
+++ b/launcher/ui/themes/ThemeManager.cpp
@@ -1,155 +1,155 @@
-// SPDX-License-Identifier: GPL-3.0-only
-/*
- * Prism Launcher - Minecraft Launcher
- * Copyright (C) 2022 Tayou <tayou@gmx.net>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-#include "ThemeManager.h"
-
-#include <QApplication>
-#include <QDir>
-#include <QDirIterator>
-#include <QIcon>
-#include "ui/themes/BrightTheme.h"
-#include "ui/themes/CustomTheme.h"
-#include "ui/themes/DarkTheme.h"
-#include "ui/themes/SystemTheme.h"
-
-#include "Application.h"
-
-#ifdef Q_OS_WIN
-#include <windows.h>
-// this is needed for versionhelpers.h, it is also included in WinDarkmode, but we can't rely on that.
-// Ultimately this should be included in versionhelpers, but that is outside of the project.
-#include "ui/WinDarkmode.h"
-#include <versionhelpers.h>
-#endif
-
-ThemeManager::ThemeManager(MainWindow* mainWindow)
-{
- m_mainWindow = mainWindow;
- InitializeThemes();
-}
-
-/// @brief Adds the Theme to the list of themes
-/// @param theme The Theme to add
-/// @return Theme ID
-QString ThemeManager::AddTheme(std::unique_ptr<ITheme> theme)
-{
- QString id = theme->id();
- m_themes.emplace(id, std::move(theme));
- return id;
-}
-
-/// @brief Gets the Theme from the List via ID
-/// @param themeId Theme ID of theme to fetch
-/// @return Theme at themeId
-ITheme* ThemeManager::GetTheme(QString themeId)
-{
- return m_themes[themeId].get();
-}
-
-void ThemeManager::InitializeThemes()
-{
- // Icon themes
- {
- // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
- // set icon theme search path!
- auto searchPaths = QIcon::themeSearchPaths();
- searchPaths.append("iconthemes");
- QIcon::setThemeSearchPaths(searchPaths);
- themeDebugLog() << "<> Icon themes initialized.";
- }
-
- // Initialize widget themes
- {
- themeDebugLog() << "<> Initializing Widget Themes";
- themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<SystemTheme>());
- auto darkThemeId = AddTheme(std::make_unique<DarkTheme>());
- themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
- themeDebugLog() << "Loading Built-in Theme:" << AddTheme(std::make_unique<BrightTheme>());
-
- // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
- // dropdown?)
- QString themeFolder = QDir("./themes/").absoluteFilePath("");
- themeDebugLog() << "Theme Folder Path: " << themeFolder;
-
- QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
- while (directoryIterator.hasNext()) {
- QDir dir(directoryIterator.next());
- QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
- if (themeJson.exists()) {
- // Load "theme.json" based themes
- themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
- AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), themeJson, true));
- } else {
- // Load pure QSS Themes
- QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
- while (stylesheetFileIterator.hasNext()) {
- QFile customThemeFile(stylesheetFileIterator.next());
- QFileInfo customThemeFileInfo(customThemeFile);
- themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
- AddTheme(std::make_unique<CustomTheme>(GetTheme(darkThemeId), customThemeFileInfo, false));
- }
- }
- }
-
- themeDebugLog() << "<> Widget themes initialized.";
- }
-}
-
-QList<ITheme*> ThemeManager::getValidApplicationThemes()
-{
- QList<ITheme*> ret;
- ret.reserve(m_themes.size());
- for (auto&& [id, theme] : m_themes) {
- ret.append(theme.get());
- }
- return ret;
-}
-
-void ThemeManager::setIconTheme(const QString& name)
-{
- QIcon::setThemeName(name);
-}
-
-void ThemeManager::applyCurrentlySelectedTheme()
-{
- setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
- themeDebugLog() << "<> Icon theme set.";
- setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), true);
- themeDebugLog() << "<> Application theme set.";
-}
-
-void ThemeManager::setApplicationTheme(const QString& name, bool initial)
-{
- auto systemPalette = qApp->palette();
- auto themeIter = m_themes.find(name);
- if (themeIter != m_themes.end()) {
- auto& theme = themeIter->second;
- themeDebugLog() << "applying theme" << theme->name();
- theme->apply(initial);
-#ifdef Q_OS_WIN
- if (m_mainWindow && IsWindows10OrGreater()) {
- if (QString::compare(theme->id(), "dark") == 0) {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), true);
- } else {
- WinDarkmode::setDarkWinTitlebar(m_mainWindow->winId(), false);
- }
- }
-#endif
- } else {
- themeWarningLog() << "Tried to set invalid theme:" << name;
- }
-}
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "ThemeManager.h"
+
+#include <QApplication>
+#include <QDir>
+#include <QDirIterator>
+#include <QIcon>
+#include "ui/themes/BrightTheme.h"
+#include "ui/themes/CustomTheme.h"
+#include "ui/themes/DarkTheme.h"
+#include "ui/themes/SystemTheme.h"
+
+#include "Application.h"
+
+ThemeManager::ThemeManager(MainWindow* mainWindow)
+{
+ m_mainWindow = mainWindow;
+ initializeThemes();
+}
+
+/// @brief Adds the Theme to the list of themes
+/// @param theme The Theme to add
+/// @return Theme ID
+QString ThemeManager::addTheme(std::unique_ptr<ITheme> theme)
+{
+ QString id = theme->id();
+ m_themes.emplace(id, std::move(theme));
+ return id;
+}
+
+/// @brief Gets the Theme from the List via ID
+/// @param themeId Theme ID of theme to fetch
+/// @return Theme at themeId
+ITheme* ThemeManager::getTheme(QString themeId)
+{
+ return m_themes[themeId].get();
+}
+
+void ThemeManager::initializeThemes()
+{
+ // Icon themes
+ {
+ // TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
+ // set icon theme search path!
+ auto searchPaths = QIcon::themeSearchPaths();
+ searchPaths.append("iconthemes");
+ QIcon::setThemeSearchPaths(searchPaths);
+ themeDebugLog() << "<> Icon themes initialized.";
+ }
+
+ // Initialize widget themes
+ {
+ themeDebugLog() << "<> Initializing Widget Themes";
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
+ auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
+ themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
+ themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
+
+ // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
+ // dropdown?)
+ QString themeFolder = QDir("./themes/").absoluteFilePath("");
+ themeDebugLog() << "Theme Folder Path: " << themeFolder;
+
+ QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
+ while (directoryIterator.hasNext()) {
+ QDir dir(directoryIterator.next());
+ QFileInfo themeJson(dir.absoluteFilePath("theme.json"));
+ if (themeJson.exists()) {
+ // Load "theme.json" based themes
+ themeDebugLog() << "Loading JSON Theme from:" << themeJson.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), themeJson, true));
+ } else {
+ // Load pure QSS Themes
+ QDirIterator stylesheetFileIterator(dir.absoluteFilePath(""), { "*.qss", "*.css" }, QDir::Files);
+ while (stylesheetFileIterator.hasNext()) {
+ QFile customThemeFile(stylesheetFileIterator.next());
+ QFileInfo customThemeFileInfo(customThemeFile);
+ themeDebugLog() << "Loading QSS Theme from:" << customThemeFileInfo.absoluteFilePath();
+ addTheme(std::make_unique<CustomTheme>(getTheme(darkThemeId), customThemeFileInfo, false));
+ }
+ }
+ }
+
+ themeDebugLog() << "<> Widget themes initialized.";
+ }
+}
+
+QList<ITheme*> ThemeManager::getValidApplicationThemes()
+{
+ QList<ITheme*> ret;
+ ret.reserve(m_themes.size());
+ for (auto&& [id, theme] : m_themes) {
+ ret.append(theme.get());
+ }
+ return ret;
+}
+
+void ThemeManager::setIconTheme(const QString& name)
+{
+ QIcon::setThemeName(name);
+}
+
+void ThemeManager::applyCurrentlySelectedTheme()
+{
+ setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
+ themeDebugLog() << "<> Icon theme set.";
+ setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString());
+ themeDebugLog() << "<> Application theme set.";
+}
+
+void ThemeManager::setApplicationTheme(const QString& name)
+{
+ auto systemPalette = qApp->palette();
+ auto themeIter = m_themes.find(name);
+ if (themeIter != m_themes.end()) {
+ auto& theme = themeIter->second;
+ themeDebugLog() << "applying theme" << theme->name();
+ theme->apply();
+ } else {
+ themeWarningLog() << "Tried to set invalid theme:" << name;
+ }
+}
+
+QString ThemeManager::getCatImage(QString catName)
+{
+ QDateTime now = QDateTime::currentDateTime();
+ QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
+ QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
+ QDateTime halloween(QDate(now.date().year(), 10, 31), QTime(0, 0));
+ QString cat = !catName.isEmpty() ? catName : APPLICATION->settings()->get("BackgroundCat").toString();
+ if (std::abs(now.daysTo(xmas)) <= 4) {
+ cat += "-xmas";
+ } else if (std::abs(now.daysTo(halloween)) <= 4) {
+ cat += "-spooky";
+ } else if (std::abs(now.daysTo(birthday)) <= 12) {
+ cat += "-bday";
+ }
+ return cat;
+}
diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h
index b85cb742..9af44b5a 100644
--- a/launcher/ui/themes/ThemeManager.h
+++ b/launcher/ui/themes/ThemeManager.h
@@ -1,52 +1,57 @@
-// SPDX-License-Identifier: GPL-3.0-only
-/*
- * Prism Launcher - Minecraft Launcher
- * Copyright (C) 2022 Tayou <tayou@gmx.net>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-#pragma once
-
-#include <QString>
-
-#include "ui/MainWindow.h"
-#include "ui/themes/ITheme.h"
-
-inline auto themeDebugLog()
-{
- return qDebug() << "[Theme]";
-}
-inline auto themeWarningLog()
-{
- return qWarning() << "[Theme]";
-}
-
-class ThemeManager {
- public:
- ThemeManager(MainWindow* mainWindow);
-
- // maybe make private? Or put in ctor?
- void InitializeThemes();
-
- QList<ITheme*> getValidApplicationThemes();
- void setIconTheme(const QString& name);
- void applyCurrentlySelectedTheme();
- void setApplicationTheme(const QString& name, bool initial);
-
- private:
- std::map<QString, std::unique_ptr<ITheme>> m_themes;
- MainWindow* m_mainWindow;
-
- QString AddTheme(std::unique_ptr<ITheme> theme);
- ITheme* GetTheme(QString themeId);
-};
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <QString>
+
+#include "ui/MainWindow.h"
+#include "ui/themes/ITheme.h"
+
+inline auto themeDebugLog()
+{
+ return qDebug() << "[Theme]";
+}
+inline auto themeWarningLog()
+{
+ return qWarning() << "[Theme]";
+}
+
+class ThemeManager {
+ public:
+ ThemeManager(MainWindow* mainWindow);
+
+ QList<ITheme*> getValidApplicationThemes();
+ void setIconTheme(const QString& name);
+ void applyCurrentlySelectedTheme();
+ void setApplicationTheme(const QString& name);
+
+ /// <summary>
+ /// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
+ /// </summary>
+ /// <param name="catName">Optional, if you need a specific cat.</param>
+ /// <returns></returns>
+ static QString getCatImage(QString catName = "");
+
+ private:
+ std::map<QString, std::unique_ptr<ITheme>> m_themes;
+ MainWindow* m_mainWindow;
+
+ void initializeThemes();
+ QString addTheme(std::unique_ptr<ITheme> theme);
+ ITheme* getTheme(QString themeId);
+};
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.cpp b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
new file mode 100644
index 00000000..dcf13303
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.cpp
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "ThemeCustomizationWidget.h"
+#include "ui_ThemeCustomizationWidget.h"
+
+#include "Application.h"
+#include "ui/themes/ITheme.h"
+#include "ui/themes/ThemeManager.h"
+
+ThemeCustomizationWidget::ThemeCustomizationWidget(QWidget *parent) : QWidget(parent), ui(new Ui::ThemeCustomizationWidget)
+{
+ ui->setupUi(this);
+ loadSettings();
+
+ connect(ui->iconsComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyIconTheme);
+ connect(ui->widgetStyleComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyWidgetTheme);
+ connect(ui->backgroundCatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ThemeCustomizationWidget::applyCatTheme);
+}
+
+ThemeCustomizationWidget::~ThemeCustomizationWidget()
+{
+ delete ui;
+}
+
+/// <summary>
+/// The layout was not quite right, so currently this just disables the UI elements, which should be hidden instead
+/// TODO FIXME
+///
+/// Original Method One:
+/// ui->iconsComboBox->setVisible(features& ThemeFields::ICONS);
+/// ui->iconsLabel->setVisible(features& ThemeFields::ICONS);
+/// ui->widgetStyleComboBox->setVisible(features& ThemeFields::WIDGETS);
+/// ui->widgetThemeLabel->setVisible(features& ThemeFields::WIDGETS);
+/// ui->backgroundCatComboBox->setVisible(features& ThemeFields::CAT);
+/// ui->backgroundCatLabel->setVisible(features& ThemeFields::CAT);
+///
+/// original Method Two:
+/// if (!(features & ThemeFields::ICONS)) {
+/// ui->formLayout->setRowVisible(0, false);
+/// }
+/// if (!(features & ThemeFields::WIDGETS)) {
+/// ui->formLayout->setRowVisible(1, false);
+/// }
+/// if (!(features & ThemeFields::CAT)) {
+/// ui->formLayout->setRowVisible(2, false);
+/// }
+/// </summary>
+/// <param name="features"></param>
+void ThemeCustomizationWidget::showFeatures(ThemeFields features) {
+ ui->iconsComboBox->setEnabled(features & ThemeFields::ICONS);
+ ui->iconsLabel->setEnabled(features & ThemeFields::ICONS);
+ ui->widgetStyleComboBox->setEnabled(features & ThemeFields::WIDGETS);
+ ui->widgetThemeLabel->setEnabled(features & ThemeFields::WIDGETS);
+ ui->backgroundCatComboBox->setEnabled(features & ThemeFields::CAT);
+ ui->backgroundCatLabel->setEnabled(features & ThemeFields::CAT);
+}
+
+void ThemeCustomizationWidget::applyIconTheme(int index) {
+ auto settings = APPLICATION->settings();
+ auto originalIconTheme = settings->get("IconTheme").toString();
+ auto& newIconTheme = m_iconThemeOptions[index].first;
+ settings->set("IconTheme", newIconTheme);
+
+ if (originalIconTheme != newIconTheme) {
+ APPLICATION->applyCurrentlySelectedTheme();
+ }
+
+ emit currentIconThemeChanged(index);
+}
+
+void ThemeCustomizationWidget::applyWidgetTheme(int index) {
+ auto settings = APPLICATION->settings();
+ auto originalAppTheme = settings->get("ApplicationTheme").toString();
+ auto newAppTheme = ui->widgetStyleComboBox->currentData().toString();
+ if (originalAppTheme != newAppTheme) {
+ settings->set("ApplicationTheme", newAppTheme);
+ APPLICATION->applyCurrentlySelectedTheme();
+ }
+
+ emit currentWidgetThemeChanged(index);
+}
+
+void ThemeCustomizationWidget::applyCatTheme(int index) {
+ auto settings = APPLICATION->settings();
+ settings->set("BackgroundCat", m_catOptions[index].first);
+
+ emit currentCatChanged(index);
+}
+
+void ThemeCustomizationWidget::applySettings()
+{
+ applyIconTheme(ui->iconsComboBox->currentIndex());
+ applyWidgetTheme(ui->widgetStyleComboBox->currentIndex());
+ applyCatTheme(ui->backgroundCatComboBox->currentIndex());
+}
+void ThemeCustomizationWidget::loadSettings()
+{
+ auto settings = APPLICATION->settings();
+
+ auto iconTheme = settings->get("IconTheme").toString();
+ for (auto& iconThemeFromList : m_iconThemeOptions) {
+ QIcon iconForComboBox = QIcon(QString(":/icons/%1/scalable/settings").arg(iconThemeFromList.first));
+ ui->iconsComboBox->addItem(iconForComboBox, iconThemeFromList.second);
+ if (iconTheme == iconThemeFromList.first) {
+ ui->iconsComboBox->setCurrentIndex(ui->iconsComboBox->count() - 1);
+ }
+ }
+
+ {
+ auto currentTheme = settings->get("ApplicationTheme").toString();
+ auto themes = APPLICATION->getValidApplicationThemes();
+ int idx = 0;
+ for (auto& theme : themes) {
+ ui->widgetStyleComboBox->addItem(theme->name(), theme->id());
+ if (currentTheme == theme->id()) {
+ ui->widgetStyleComboBox->setCurrentIndex(idx);
+ }
+ idx++;
+ }
+ }
+
+ auto cat = settings->get("BackgroundCat").toString();
+ for (auto& catFromList : m_catOptions) {
+ QIcon catIcon = QIcon(QString(":/backgrounds/%1").arg(ThemeManager::getCatImage(catFromList.first)));
+ ui->backgroundCatComboBox->addItem(catIcon, catFromList.second);
+ if (cat == catFromList.first) {
+ ui->backgroundCatComboBox->setCurrentIndex(ui->backgroundCatComboBox->count() - 1);
+ }
+ }
+}
+
+void ThemeCustomizationWidget::retranslate()
+{
+ ui->retranslateUi(this);
+}
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.h b/launcher/ui/widgets/ThemeCustomizationWidget.h
new file mode 100644
index 00000000..d955a266
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.h
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2022 Tayou <tayou@gmx.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+#include <QWidget>
+#include "translations/TranslationsModel.h"
+
+enum ThemeFields { NONE = 0b0000, ICONS = 0b0001, WIDGETS = 0b0010, CAT = 0b0100 };
+
+namespace Ui {
+class ThemeCustomizationWidget;
+}
+
+class ThemeCustomizationWidget : public QWidget {
+ Q_OBJECT
+
+ public:
+ explicit ThemeCustomizationWidget(QWidget* parent = nullptr);
+ ~ThemeCustomizationWidget();
+
+ void showFeatures(ThemeFields features);
+
+ void applySettings();
+
+ void loadSettings();
+ void retranslate();
+
+ private slots:
+ void applyIconTheme(int index);
+ void applyWidgetTheme(int index);
+ void applyCatTheme(int index);
+
+ signals:
+ int currentIconThemeChanged(int index);
+ int currentWidgetThemeChanged(int index);
+ int currentCatChanged(int index);
+
+ private:
+ Ui::ThemeCustomizationWidget* ui;
+
+ //TODO finish implementing
+ QList<std::pair<QString, QString>> m_iconThemeOptions{
+ { "pe_colored", QObject::tr("Simple (Colored Icons)") },
+ { "pe_light", QObject::tr("Simple (Light Icons)") },
+ { "pe_dark", QObject::tr("Simple (Dark Icons)") },
+ { "pe_blue", QObject::tr("Simple (Blue Icons)") },
+ { "breeze_light", QObject::tr("Breeze Light") },
+ { "breeze_dark", QObject::tr("Breeze Dark") },
+ { "OSX", QObject::tr("OSX") },
+ { "iOS", QObject::tr("iOS") },
+ { "flat", QObject::tr("Flat") },
+ { "flat_white", QObject::tr("Flat (White)") },
+ { "multimc", QObject::tr("Legacy") },
+ { "custom", QObject::tr("Custom") }
+ };
+ QList<std::pair<QString, QString>> m_catOptions{
+ { "kitteh", QObject::tr("Background Cat (from MultiMC)") },
+ { "rory", QObject::tr("Rory ID 11 (drawn by Ashtaka)") },
+ { "rory-flat", QObject::tr("Rory ID 11 (flat edition, drawn by Ashtaka)") },
+ { "teawie", QObject::tr("Teawie (drawn by SympathyTea)") }
+ };
+};
diff --git a/launcher/ui/widgets/ThemeCustomizationWidget.ui b/launcher/ui/widgets/ThemeCustomizationWidget.ui
new file mode 100644
index 00000000..f216a610
--- /dev/null
+++ b/launcher/ui/widgets/ThemeCustomizationWidget.ui
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ThemeCustomizationWidget</class>
+ <widget class="QWidget" name="ThemeCustomizationWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>191</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string notr="true">Form</string>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="iconsLabel">
+ <property name="text">
+ <string>&amp;Icons</string>
+ </property>
+ <property name="buddy">
+ <cstring>iconsComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="iconsComboBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="widgetThemeLabel">
+ <property name="text">
+ <string>&amp;Colors</string>
+ </property>
+ <property name="buddy">
+ <cstring>widgetStyleComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="widgetStyleComboBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="backgroundCatLabel">
+ <property name="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ <property name="text">
+ <string>C&amp;at</string>
+ </property>
+ <property name="buddy">
+ <cstring>backgroundCatComboBox</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QComboBox" name="backgroundCatComboBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="focusPolicy">
+ <enum>Qt::StrongFocus</enum>
+ </property>
+ <property name="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="catInfoLabel">
+ <property name="toolTip">
+ <string>The cat appears in the background and is not shown by default. It is only made visible when pressing the Cat button in the Toolbar.</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="about">
+ <normaloff>.</normaloff>.</iconset>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/libraries/README.md b/libraries/README.md
index ac5a3618..95be8740 100644
--- a/libraries/README.md
+++ b/libraries/README.md
@@ -18,11 +18,13 @@ See [github repo](https://github.com/FeralInteractive/gamemode).
BSD-3-Clause licensed
-## hoedown
+## cmark
-Hoedown is a revived fork of Sundown, the Markdown parser based on the original code of the Upskirt library by Natacha Porté.
+The C reference implementation of CommonMark, a standardized Markdown spec.
-See [github repo](https://github.com/hoedown/hoedown).
+See [github_repo](https://github.com/commonmark/cmark).
+
+BSD2 licensed.
## javacheck
diff --git a/libraries/cmark b/libraries/cmark
new file mode 160000
+Subproject a8da5a2f252b96eca60ae8bada1a9ba059a3840
diff --git a/libraries/hoedown/CMakeLists.txt b/libraries/hoedown/CMakeLists.txt
deleted file mode 100644
index 7902e734..00000000
--- a/libraries/hoedown/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-# hoedown 3.0.2 - https://github.com/hoedown/hoedown/archive/3.0.2.tar.gz
-project(hoedown LANGUAGES C VERSION 3.0.2)
-
-set(HOEDOWN_SOURCES
-include/hoedown/autolink.h
-include/hoedown/buffer.h
-include/hoedown/document.h
-include/hoedown/escape.h
-include/hoedown/html.h
-include/hoedown/stack.h
-include/hoedown/version.h
-src/autolink.c
-src/buffer.c
-src/document.c
-src/escape.c
-src/html.c
-src/html_blocks.c
-src/html_smartypants.c
-src/stack.c
-src/version.c
-)
-
-# Include self.
-add_library(hoedown STATIC ${HOEDOWN_SOURCES})
-
-target_include_directories(hoedown PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
diff --git a/libraries/hoedown/LICENSE b/libraries/hoedown/LICENSE
deleted file mode 100644
index 4e75de4d..00000000
--- a/libraries/hoedown/LICENSE
+++ /dev/null
@@ -1,15 +0,0 @@
-Copyright (c) 2008, Natacha Porté
-Copyright (c) 2011, Vicent Martí
-Copyright (c) 2014, Xavier Mendez, Devin Torres and the Hoedown authors
-
-Permission to use, copy, modify, and distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/libraries/hoedown/README.md b/libraries/hoedown/README.md
deleted file mode 100644
index abe2b6ca..00000000
--- a/libraries/hoedown/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
-Hoedown
-=======
-
-This is Hoedown 3.0.2, taken from [the hoedown github repo](https://github.com/hoedown/hoedown).
-
-`Hoedown` is a revived fork of [Sundown](https://github.com/vmg/sundown),
-the Markdown parser based on the original code of the
-[Upskirt library](http://fossil.instinctive.eu/libupskirt/index)
-by Natacha Porté.
diff --git a/libraries/hoedown/include/hoedown/autolink.h b/libraries/hoedown/include/hoedown/autolink.h
deleted file mode 100644
index 953e7807..00000000
--- a/libraries/hoedown/include/hoedown/autolink.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* autolink.h - versatile autolinker */
-
-#ifndef HOEDOWN_AUTOLINK_H
-#define HOEDOWN_AUTOLINK_H
-
-#include "buffer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*************
- * CONSTANTS *
- *************/
-
-typedef enum hoedown_autolink_flags {
- HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0)
-} hoedown_autolink_flags;
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_autolink_is_safe: verify that a URL has a safe protocol */
-int hoedown_autolink_is_safe(const uint8_t *data, size_t size);
-
-/* hoedown_autolink__www: search for the next www link in data */
-size_t hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
- uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
-
-/* hoedown_autolink__email: search for the next email in data */
-size_t hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
- uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
-
-/* hoedown_autolink__url: search for the next URL in data */
-size_t hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
- uint8_t *data, size_t offset, size_t size, hoedown_autolink_flags flags);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_AUTOLINK_H **/
diff --git a/libraries/hoedown/include/hoedown/buffer.h b/libraries/hoedown/include/hoedown/buffer.h
deleted file mode 100644
index 062d86ce..00000000
--- a/libraries/hoedown/include/hoedown/buffer.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/* buffer.h - simple, fast buffers */
-
-#ifndef HOEDOWN_BUFFER_H
-#define HOEDOWN_BUFFER_H
-
-#include <stdio.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if defined(_MSC_VER)
-#define __attribute__(x)
-#define inline __inline
-#define __builtin_expect(x,n) x
-#endif
-
-
-/*********
- * TYPES *
- *********/
-
-typedef void *(*hoedown_realloc_callback)(void *, size_t);
-typedef void (*hoedown_free_callback)(void *);
-
-struct hoedown_buffer {
- uint8_t *data; /* actual character data */
- size_t size; /* size of the string */
- size_t asize; /* allocated size (0 = volatile buffer) */
- size_t unit; /* reallocation unit size (0 = read-only buffer) */
-
- hoedown_realloc_callback data_realloc;
- hoedown_free_callback data_free;
- hoedown_free_callback buffer_free;
-};
-
-typedef struct hoedown_buffer hoedown_buffer;
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* allocation wrappers */
-void *hoedown_malloc(size_t size) __attribute__ ((malloc));
-void *hoedown_calloc(size_t nmemb, size_t size) __attribute__ ((malloc));
-void *hoedown_realloc(void *ptr, size_t size) __attribute__ ((malloc));
-
-/* hoedown_buffer_init: initialize a buffer with custom allocators */
-void hoedown_buffer_init(
- hoedown_buffer *buffer,
- size_t unit,
- hoedown_realloc_callback data_realloc,
- hoedown_free_callback data_free,
- hoedown_free_callback buffer_free
-);
-
-/* hoedown_buffer_uninit: uninitialize an existing buffer */
-void hoedown_buffer_uninit(hoedown_buffer *buf);
-
-/* hoedown_buffer_new: allocate a new buffer */
-hoedown_buffer *hoedown_buffer_new(size_t unit) __attribute__ ((malloc));
-
-/* hoedown_buffer_reset: free internal data of the buffer */
-void hoedown_buffer_reset(hoedown_buffer *buf);
-
-/* hoedown_buffer_grow: increase the allocated size to the given value */
-void hoedown_buffer_grow(hoedown_buffer *buf, size_t neosz);
-
-/* hoedown_buffer_put: append raw data to a buffer */
-void hoedown_buffer_put(hoedown_buffer *buf, const uint8_t *data, size_t size);
-
-/* hoedown_buffer_puts: append a NUL-terminated string to a buffer */
-void hoedown_buffer_puts(hoedown_buffer *buf, const char *str);
-
-/* hoedown_buffer_putc: append a single char to a buffer */
-void hoedown_buffer_putc(hoedown_buffer *buf, uint8_t c);
-
-/* hoedown_buffer_putf: read from a file and append to a buffer, until EOF or error */
-int hoedown_buffer_putf(hoedown_buffer *buf, FILE* file);
-
-/* hoedown_buffer_set: replace the buffer's contents with raw data */
-void hoedown_buffer_set(hoedown_buffer *buf, const uint8_t *data, size_t size);
-
-/* hoedown_buffer_sets: replace the buffer's contents with a NUL-terminated string */
-void hoedown_buffer_sets(hoedown_buffer *buf, const char *str);
-
-/* hoedown_buffer_eq: compare a buffer's data with other data for equality */
-int hoedown_buffer_eq(const hoedown_buffer *buf, const uint8_t *data, size_t size);
-
-/* hoedown_buffer_eq: compare a buffer's data with NUL-terminated string for equality */
-int hoedown_buffer_eqs(const hoedown_buffer *buf, const char *str);
-
-/* hoedown_buffer_prefix: compare the beginning of a buffer with a string */
-int hoedown_buffer_prefix(const hoedown_buffer *buf, const char *prefix);
-
-/* hoedown_buffer_slurp: remove a given number of bytes from the head of the buffer */
-void hoedown_buffer_slurp(hoedown_buffer *buf, size_t size);
-
-/* hoedown_buffer_cstr: NUL-termination of the string array (making a C-string) */
-const char *hoedown_buffer_cstr(hoedown_buffer *buf);
-
-/* hoedown_buffer_printf: formatted printing to a buffer */
-void hoedown_buffer_printf(hoedown_buffer *buf, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
-
-/* hoedown_buffer_put_utf8: put a Unicode character encoded as UTF-8 */
-void hoedown_buffer_put_utf8(hoedown_buffer *buf, unsigned int codepoint);
-
-/* hoedown_buffer_free: free the buffer */
-void hoedown_buffer_free(hoedown_buffer *buf);
-
-
-/* HOEDOWN_BUFPUTSL: optimized hoedown_buffer_puts of a string literal */
-#define HOEDOWN_BUFPUTSL(output, literal) \
- hoedown_buffer_put(output, (const uint8_t *)literal, sizeof(literal) - 1)
-
-/* HOEDOWN_BUFSETSL: optimized hoedown_buffer_sets of a string literal */
-#define HOEDOWN_BUFSETSL(output, literal) \
- hoedown_buffer_set(output, (const uint8_t *)literal, sizeof(literal) - 1)
-
-/* HOEDOWN_BUFEQSL: optimized hoedown_buffer_eqs of a string literal */
-#define HOEDOWN_BUFEQSL(output, literal) \
- hoedown_buffer_eq(output, (const uint8_t *)literal, sizeof(literal) - 1)
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_BUFFER_H **/
diff --git a/libraries/hoedown/include/hoedown/document.h b/libraries/hoedown/include/hoedown/document.h
deleted file mode 100644
index 210c565e..00000000
--- a/libraries/hoedown/include/hoedown/document.h
+++ /dev/null
@@ -1,172 +0,0 @@
-/* document.h - generic markdown parser */
-
-#ifndef HOEDOWN_DOCUMENT_H
-#define HOEDOWN_DOCUMENT_H
-
-#include "buffer.h"
-#include "autolink.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*************
- * CONSTANTS *
- *************/
-
-typedef enum hoedown_extensions {
- /* block-level extensions */
- HOEDOWN_EXT_TABLES = (1 << 0),
- HOEDOWN_EXT_FENCED_CODE = (1 << 1),
- HOEDOWN_EXT_FOOTNOTES = (1 << 2),
-
- /* span-level extensions */
- HOEDOWN_EXT_AUTOLINK = (1 << 3),
- HOEDOWN_EXT_STRIKETHROUGH = (1 << 4),
- HOEDOWN_EXT_UNDERLINE = (1 << 5),
- HOEDOWN_EXT_HIGHLIGHT = (1 << 6),
- HOEDOWN_EXT_QUOTE = (1 << 7),
- HOEDOWN_EXT_SUPERSCRIPT = (1 << 8),
- HOEDOWN_EXT_MATH = (1 << 9),
-
- /* other flags */
- HOEDOWN_EXT_NO_INTRA_EMPHASIS = (1 << 11),
- HOEDOWN_EXT_SPACE_HEADERS = (1 << 12),
- HOEDOWN_EXT_MATH_EXPLICIT = (1 << 13),
-
- /* negative flags */
- HOEDOWN_EXT_DISABLE_INDENTED_CODE = (1 << 14)
-} hoedown_extensions;
-
-#define HOEDOWN_EXT_BLOCK (\
- HOEDOWN_EXT_TABLES |\
- HOEDOWN_EXT_FENCED_CODE |\
- HOEDOWN_EXT_FOOTNOTES )
-
-#define HOEDOWN_EXT_SPAN (\
- HOEDOWN_EXT_AUTOLINK |\
- HOEDOWN_EXT_STRIKETHROUGH |\
- HOEDOWN_EXT_UNDERLINE |\
- HOEDOWN_EXT_HIGHLIGHT |\
- HOEDOWN_EXT_QUOTE |\
- HOEDOWN_EXT_SUPERSCRIPT |\
- HOEDOWN_EXT_MATH )
-
-#define HOEDOWN_EXT_FLAGS (\
- HOEDOWN_EXT_NO_INTRA_EMPHASIS |\
- HOEDOWN_EXT_SPACE_HEADERS |\
- HOEDOWN_EXT_MATH_EXPLICIT )
-
-#define HOEDOWN_EXT_NEGATIVE (\
- HOEDOWN_EXT_DISABLE_INDENTED_CODE )
-
-typedef enum hoedown_list_flags {
- HOEDOWN_LIST_ORDERED = (1 << 0),
- HOEDOWN_LI_BLOCK = (1 << 1) /* <li> containing block data */
-} hoedown_list_flags;
-
-typedef enum hoedown_table_flags {
- HOEDOWN_TABLE_ALIGN_LEFT = 1,
- HOEDOWN_TABLE_ALIGN_RIGHT = 2,
- HOEDOWN_TABLE_ALIGN_CENTER = 3,
- HOEDOWN_TABLE_ALIGNMASK = 3,
- HOEDOWN_TABLE_HEADER = 4
-} hoedown_table_flags;
-
-typedef enum hoedown_autolink_type {
- HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/
- HOEDOWN_AUTOLINK_NORMAL, /* normal http/http/ftp/mailto/etc link */
- HOEDOWN_AUTOLINK_EMAIL /* e-mail link without explit mailto: */
-} hoedown_autolink_type;
-
-
-/*********
- * TYPES *
- *********/
-
-struct hoedown_document;
-typedef struct hoedown_document hoedown_document;
-
-struct hoedown_renderer_data {
- void *opaque;
-};
-typedef struct hoedown_renderer_data hoedown_renderer_data;
-
-/* hoedown_renderer - functions for rendering parsed data */
-struct hoedown_renderer {
- /* state object */
- void *opaque;
-
- /* block level callbacks - NULL skips the block */
- void (*blockcode)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, const hoedown_renderer_data *data);
- void (*blockquote)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*header)(hoedown_buffer *ob, const hoedown_buffer *content, int level, const hoedown_renderer_data *data);
- void (*hrule)(hoedown_buffer *ob, const hoedown_renderer_data *data);
- void (*list)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data);
- void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data);
- void (*paragraph)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*table)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*table_header)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*table_body)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*table_row)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_table_flags flags, const hoedown_renderer_data *data);
- void (*footnotes)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- void (*footnote_def)(hoedown_buffer *ob, const hoedown_buffer *content, unsigned int num, const hoedown_renderer_data *data);
- void (*blockhtml)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data);
-
- /* span level callbacks - NULL or return 0 prints the span verbatim */
- int (*autolink)(hoedown_buffer *ob, const hoedown_buffer *link, hoedown_autolink_type type, const hoedown_renderer_data *data);
- int (*codespan)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data);
- int (*double_emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*underline)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*highlight)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*quote)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*image)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, const hoedown_renderer_data *data);
- int (*linebreak)(hoedown_buffer *ob, const hoedown_renderer_data *data);
- int (*link)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_renderer_data *data);
- int (*triple_emphasis)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*strikethrough)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*superscript)(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data);
- int (*footnote_ref)(hoedown_buffer *ob, unsigned int num, const hoedown_renderer_data *data);
- int (*math)(hoedown_buffer *ob, const hoedown_buffer *text, int displaymode, const hoedown_renderer_data *data);
- int (*raw_html)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data);
-
- /* low level callbacks - NULL copies input directly into the output */
- void (*entity)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data);
- void (*normal_text)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data);
-
- /* miscellaneous callbacks */
- void (*doc_header)(hoedown_buffer *ob, int inline_render, const hoedown_renderer_data *data);
- void (*doc_footer)(hoedown_buffer *ob, int inline_render, const hoedown_renderer_data *data);
-};
-typedef struct hoedown_renderer hoedown_renderer;
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_document_new: allocate a new document processor instance */
-hoedown_document *hoedown_document_new(
- const hoedown_renderer *renderer,
- hoedown_extensions extensions,
- size_t max_nesting
-) __attribute__ ((malloc));
-
-/* hoedown_document_render: render regular Markdown using the document processor */
-void hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size);
-
-/* hoedown_document_render_inline: render inline Markdown using the document processor */
-void hoedown_document_render_inline(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size);
-
-/* hoedown_document_free: deallocate a document processor instance */
-void hoedown_document_free(hoedown_document *doc);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_DOCUMENT_H **/
diff --git a/libraries/hoedown/include/hoedown/escape.h b/libraries/hoedown/include/hoedown/escape.h
deleted file mode 100644
index d7659c27..00000000
--- a/libraries/hoedown/include/hoedown/escape.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* escape.h - escape utilities */
-
-#ifndef HOEDOWN_ESCAPE_H
-#define HOEDOWN_ESCAPE_H
-
-#include "buffer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_escape_href: escape (part of) a URL inside HTML */
-void hoedown_escape_href(hoedown_buffer *ob, const uint8_t *data, size_t size);
-
-/* hoedown_escape_html: escape HTML */
-void hoedown_escape_html(hoedown_buffer *ob, const uint8_t *data, size_t size, int secure);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_ESCAPE_H **/
diff --git a/libraries/hoedown/include/hoedown/html.h b/libraries/hoedown/include/hoedown/html.h
deleted file mode 100644
index 7c68809a..00000000
--- a/libraries/hoedown/include/hoedown/html.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* html.h - HTML renderer and utilities */
-
-#ifndef HOEDOWN_HTML_H
-#define HOEDOWN_HTML_H
-
-#include "document.h"
-#include "buffer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*************
- * CONSTANTS *
- *************/
-
-typedef enum hoedown_html_flags {
- HOEDOWN_HTML_SKIP_HTML = (1 << 0),
- HOEDOWN_HTML_ESCAPE = (1 << 1),
- HOEDOWN_HTML_HARD_WRAP = (1 << 2),
- HOEDOWN_HTML_USE_XHTML = (1 << 3)
-} hoedown_html_flags;
-
-typedef enum hoedown_html_tag {
- HOEDOWN_HTML_TAG_NONE = 0,
- HOEDOWN_HTML_TAG_OPEN,
- HOEDOWN_HTML_TAG_CLOSE
-} hoedown_html_tag;
-
-
-/*********
- * TYPES *
- *********/
-
-struct hoedown_html_renderer_state {
- void *opaque;
-
- struct {
- int header_count;
- int current_level;
- int level_offset;
- int nesting_level;
- } toc_data;
-
- hoedown_html_flags flags;
-
- /* extra callbacks */
- void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, const hoedown_renderer_data *data);
-};
-typedef struct hoedown_html_renderer_state hoedown_html_renderer_state;
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_html_smartypants: process an HTML snippet using SmartyPants for smart punctuation */
-void hoedown_html_smartypants(hoedown_buffer *ob, const uint8_t *data, size_t size);
-
-/* hoedown_html_is_tag: checks if data starts with a specific tag, returns the tag type or NONE */
-hoedown_html_tag hoedown_html_is_tag(const uint8_t *data, size_t size, const char *tagname);
-
-
-/* hoedown_html_renderer_new: allocates a regular HTML renderer */
-hoedown_renderer *hoedown_html_renderer_new(
- hoedown_html_flags render_flags,
- int nesting_level
-) __attribute__ ((malloc));
-
-/* hoedown_html_toc_renderer_new: like hoedown_html_renderer_new, but the returned renderer produces the Table of Contents */
-hoedown_renderer *hoedown_html_toc_renderer_new(
- int nesting_level
-) __attribute__ ((malloc));
-
-/* hoedown_html_renderer_free: deallocate an HTML renderer */
-void hoedown_html_renderer_free(hoedown_renderer *renderer);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_HTML_H **/
diff --git a/libraries/hoedown/include/hoedown/stack.h b/libraries/hoedown/include/hoedown/stack.h
deleted file mode 100644
index d1855f4f..00000000
--- a/libraries/hoedown/include/hoedown/stack.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* stack.h - simple stacking */
-
-#ifndef HOEDOWN_STACK_H
-#define HOEDOWN_STACK_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*********
- * TYPES *
- *********/
-
-struct hoedown_stack {
- void **item;
- size_t size;
- size_t asize;
-};
-typedef struct hoedown_stack hoedown_stack;
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_stack_init: initialize a stack */
-void hoedown_stack_init(hoedown_stack *st, size_t initial_size);
-
-/* hoedown_stack_uninit: free internal data of the stack */
-void hoedown_stack_uninit(hoedown_stack *st);
-
-/* hoedown_stack_grow: increase the allocated size to the given value */
-void hoedown_stack_grow(hoedown_stack *st, size_t neosz);
-
-/* hoedown_stack_push: push an item to the top of the stack */
-void hoedown_stack_push(hoedown_stack *st, void *item);
-
-/* hoedown_stack_pop: retrieve and remove the item at the top of the stack */
-void *hoedown_stack_pop(hoedown_stack *st);
-
-/* hoedown_stack_top: retrieve the item at the top of the stack */
-void *hoedown_stack_top(const hoedown_stack *st);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_STACK_H **/
diff --git a/libraries/hoedown/include/hoedown/version.h b/libraries/hoedown/include/hoedown/version.h
deleted file mode 100644
index 4938cae5..00000000
--- a/libraries/hoedown/include/hoedown/version.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* version.h - holds Hoedown's version */
-
-#ifndef HOEDOWN_VERSION_H
-#define HOEDOWN_VERSION_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/*************
- * CONSTANTS *
- *************/
-
-#define HOEDOWN_VERSION "3.0.2"
-#define HOEDOWN_VERSION_MAJOR 3
-#define HOEDOWN_VERSION_MINOR 0
-#define HOEDOWN_VERSION_REVISION 2
-
-
-/*************
- * FUNCTIONS *
- *************/
-
-/* hoedown_version: retrieve Hoedown's version numbers */
-void hoedown_version(int *major, int *minor, int *revision);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /** HOEDOWN_VERSION_H **/
diff --git a/libraries/hoedown/src/autolink.c b/libraries/hoedown/src/autolink.c
deleted file mode 100644
index 3592b8e3..00000000
--- a/libraries/hoedown/src/autolink.c
+++ /dev/null
@@ -1,281 +0,0 @@
-#include "hoedown/autolink.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#ifndef _MSC_VER
-#include <strings.h>
-#else
-#define strncasecmp _strnicmp
-#endif
-
-int
-hoedown_autolink_is_safe(const uint8_t *data, size_t size)
-{
- static const size_t valid_uris_count = 6;
- static const char *valid_uris[] = {
- "http://", "https://", "/", "#", "ftp://", "mailto:"
- };
- static const size_t valid_uris_size[] = { 7, 8, 1, 1, 6, 7 };
- size_t i;
-
- for (i = 0; i < valid_uris_count; ++i) {
- size_t len = valid_uris_size[i];
-
- if (size > len &&
- strncasecmp((char *)data, valid_uris[i], len) == 0 &&
- isalnum(data[len]))
- return 1;
- }
-
- return 0;
-}
-
-static size_t
-autolink_delim(uint8_t *data, size_t link_end, size_t max_rewind, size_t size)
-{
- uint8_t cclose, copen = 0;
- size_t i;
-
- for (i = 0; i < link_end; ++i)
- if (data[i] == '<') {
- link_end = i;
- break;
- }
-
- while (link_end > 0) {
- if (strchr("?!.,:", data[link_end - 1]) != NULL)
- link_end--;
-
- else if (data[link_end - 1] == ';') {
- size_t new_end = link_end - 2;
-
- while (new_end > 0 && isalpha(data[new_end]))
- new_end--;
-
- if (new_end < link_end - 2 && data[new_end] == '&')
- link_end = new_end;
- else
- link_end--;
- }
- else break;
- }
-
- if (link_end == 0)
- return 0;
-
- cclose = data[link_end - 1];
-
- switch (cclose) {
- case '"': copen = '"'; break;
- case '\'': copen = '\''; break;
- case ')': copen = '('; break;
- case ']': copen = '['; break;
- case '}': copen = '{'; break;
- }
-
- if (copen != 0) {
- size_t closing = 0;
- size_t opening = 0;
- size_t i = 0;
-
- /* Try to close the final punctuation sign in this same line;
- * if we managed to close it outside of the URL, that means that it's
- * not part of the URL. If it closes inside the URL, that means it
- * is part of the URL.
- *
- * Examples:
- *
- * foo http://www.pokemon.com/Pikachu_(Electric) bar
- * => http://www.pokemon.com/Pikachu_(Electric)
- *
- * foo (http://www.pokemon.com/Pikachu_(Electric)) bar
- * => http://www.pokemon.com/Pikachu_(Electric)
- *
- * foo http://www.pokemon.com/Pikachu_(Electric)) bar
- * => http://www.pokemon.com/Pikachu_(Electric))
- *
- * (foo http://www.pokemon.com/Pikachu_(Electric)) bar
- * => foo http://www.pokemon.com/Pikachu_(Electric)
- */
-
- while (i < link_end) {
- if (data[i] == copen)
- opening++;
- else if (data[i] == cclose)
- closing++;
-
- i++;
- }
-
- if (closing != opening)
- link_end--;
- }
-
- return link_end;
-}
-
-static size_t
-check_domain(uint8_t *data, size_t size, int allow_short)
-{
- size_t i, np = 0;
-
- if (!isalnum(data[0]))
- return 0;
-
- for (i = 1; i < size - 1; ++i) {
- if (strchr(".:", data[i]) != NULL) np++;
- else if (!isalnum(data[i]) && data[i] != '-') break;
- }
-
- if (allow_short) {
- /* We don't need a valid domain in the strict sense (with
- * least one dot; so just make sure it's composed of valid
- * domain characters and return the length of the the valid
- * sequence. */
- return i;
- } else {
- /* a valid domain needs to have at least a dot.
- * that's as far as we get */
- return np ? i : 0;
- }
-}
-
-size_t
-hoedown_autolink__www(
- size_t *rewind_p,
- hoedown_buffer *link,
- uint8_t *data,
- size_t max_rewind,
- size_t size,
- hoedown_autolink_flags flags)
-{
- size_t link_end;
-
- if (max_rewind > 0 && !ispunct(data[-1]) && !isspace(data[-1]))
- return 0;
-
- if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
- return 0;
-
- link_end = check_domain(data, size, 0);
-
- if (link_end == 0)
- return 0;
-
- while (link_end < size && !isspace(data[link_end]))
- link_end++;
-
- link_end = autolink_delim(data, link_end, max_rewind, size);
-
- if (link_end == 0)
- return 0;
-
- hoedown_buffer_put(link, data, link_end);
- *rewind_p = 0;
-
- return (int)link_end;
-}
-
-size_t
-hoedown_autolink__email(
- size_t *rewind_p,
- hoedown_buffer *link,
- uint8_t *data,
- size_t max_rewind,
- size_t size,
- hoedown_autolink_flags flags)
-{
- size_t link_end, rewind;
- int nb = 0, np = 0;
-
- for (rewind = 0; rewind < max_rewind; ++rewind) {
- uint8_t c = data[-1 - rewind];
-
- if (isalnum(c))
- continue;
-
- if (strchr(".+-_", c) != NULL)
- continue;
-
- break;
- }
-
- if (rewind == 0)
- return 0;
-
- for (link_end = 0; link_end < size; ++link_end) {
- uint8_t c = data[link_end];
-
- if (isalnum(c))
- continue;
-
- if (c == '@')
- nb++;
- else if (c == '.' && link_end < size - 1)
- np++;
- else if (c != '-' && c != '_')
- break;
- }
-
- if (link_end < 2 || nb != 1 || np == 0 ||
- !isalpha(data[link_end - 1]))
- return 0;
-
- link_end = autolink_delim(data, link_end, max_rewind, size);
-
- if (link_end == 0)
- return 0;
-
- hoedown_buffer_put(link, data - rewind, link_end + rewind);
- *rewind_p = rewind;
-
- return link_end;
-}
-
-size_t
-hoedown_autolink__url(
- size_t *rewind_p,
- hoedown_buffer *link,
- uint8_t *data,
- size_t max_rewind,
- size_t size,
- hoedown_autolink_flags flags)
-{
- size_t link_end, rewind = 0, domain_len;
-
- if (size < 4 || data[1] != '/' || data[2] != '/')
- return 0;
-
- while (rewind < max_rewind && isalpha(data[-1 - rewind]))
- rewind++;
-
- if (!hoedown_autolink_is_safe(data - rewind, size + rewind))
- return 0;
-
- link_end = strlen("://");
-
- domain_len = check_domain(
- data + link_end,
- size - link_end,
- flags & HOEDOWN_AUTOLINK_SHORT_DOMAINS);
-
- if (domain_len == 0)
- return 0;
-
- link_end += domain_len;
- while (link_end < size && !isspace(data[link_end]))
- link_end++;
-
- link_end = autolink_delim(data, link_end, max_rewind, size);
-
- if (link_end == 0)
- return 0;
-
- hoedown_buffer_put(link, data - rewind, link_end + rewind);
- *rewind_p = rewind;
-
- return link_end;
-}
diff --git a/libraries/hoedown/src/buffer.c b/libraries/hoedown/src/buffer.c
deleted file mode 100644
index 024a8bcc..00000000
--- a/libraries/hoedown/src/buffer.c
+++ /dev/null
@@ -1,308 +0,0 @@
-#include "hoedown/buffer.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-void *
-hoedown_malloc(size_t size)
-{
- void *ret = malloc(size);
-
- if (!ret) {
- fprintf(stderr, "Allocation failed.\n");
- abort();
- }
-
- return ret;
-}
-
-void *
-hoedown_calloc(size_t nmemb, size_t size)
-{
- void *ret = calloc(nmemb, size);
-
- if (!ret) {
- fprintf(stderr, "Allocation failed.\n");
- abort();
- }
-
- return ret;
-}
-
-void *
-hoedown_realloc(void *ptr, size_t size)
-{
- void *ret = realloc(ptr, size);
-
- if (!ret) {
- fprintf(stderr, "Allocation failed.\n");
- abort();
- }
-
- return ret;
-}
-
-void
-hoedown_buffer_init(
- hoedown_buffer *buf,
- size_t unit,
- hoedown_realloc_callback data_realloc,
- hoedown_free_callback data_free,
- hoedown_free_callback buffer_free)
-{
- assert(buf);
-
- buf->data = NULL;
- buf->size = buf->asize = 0;
- buf->unit = unit;
- buf->data_realloc = data_realloc;
- buf->data_free = data_free;
- buf->buffer_free = buffer_free;
-}
-
-void
-hoedown_buffer_uninit(hoedown_buffer *buf)
-{
- assert(buf && buf->unit);
- buf->data_free(buf->data);
-}
-
-hoedown_buffer *
-hoedown_buffer_new(size_t unit)
-{
- hoedown_buffer *ret = hoedown_malloc(sizeof (hoedown_buffer));
- hoedown_buffer_init(ret, unit, hoedown_realloc, free, free);
- return ret;
-}
-
-void
-hoedown_buffer_free(hoedown_buffer *buf)
-{
- if (!buf) return;
- assert(buf && buf->unit);
-
- buf->data_free(buf->data);
-
- if (buf->buffer_free)
- buf->buffer_free(buf);
-}
-
-void
-hoedown_buffer_reset(hoedown_buffer *buf)
-{
- assert(buf && buf->unit);
-
- buf->data_free(buf->data);
- buf->data = NULL;
- buf->size = buf->asize = 0;
-}
-
-void
-hoedown_buffer_grow(hoedown_buffer *buf, size_t neosz)
-{
- size_t neoasz;
- assert(buf && buf->unit);
-
- if (buf->asize >= neosz)
- return;
-
- neoasz = buf->asize + buf->unit;
- while (neoasz < neosz)
- neoasz += buf->unit;
-
- buf->data = (uint8_t *) buf->data_realloc(buf->data, neoasz);
- buf->asize = neoasz;
-}
-
-void
-hoedown_buffer_put(hoedown_buffer *buf, const uint8_t *data, size_t size)
-{
- assert(buf && buf->unit);
-
- if (buf->size + size > buf->asize)
- hoedown_buffer_grow(buf, buf->size + size);
-
- memcpy(buf->data + buf->size, data, size);
- buf->size += size;
-}
-
-void
-hoedown_buffer_puts(hoedown_buffer *buf, const char *str)
-{
- hoedown_buffer_put(buf, (const uint8_t *)str, strlen(str));
-}
-
-void
-hoedown_buffer_putc(hoedown_buffer *buf, uint8_t c)
-{
- assert(buf && buf->unit);
-
- if (buf->size >= buf->asize)
- hoedown_buffer_grow(buf, buf->size + 1);
-
- buf->data[buf->size] = c;
- buf->size += 1;
-}
-
-int
-hoedown_buffer_putf(hoedown_buffer *buf, FILE *file)
-{
- assert(buf && buf->unit);
-
- while (!(feof(file) || ferror(file))) {
- hoedown_buffer_grow(buf, buf->size + buf->unit);
- buf->size += fread(buf->data + buf->size, 1, buf->unit, file);
- }
-
- return ferror(file);
-}
-
-void
-hoedown_buffer_set(hoedown_buffer *buf, const uint8_t *data, size_t size)
-{
- assert(buf && buf->unit);
-
- if (size > buf->asize)
- hoedown_buffer_grow(buf, size);
-
- memcpy(buf->data, data, size);
- buf->size = size;
-}
-
-void
-hoedown_buffer_sets(hoedown_buffer *buf, const char *str)
-{
- hoedown_buffer_set(buf, (const uint8_t *)str, strlen(str));
-}
-
-int
-hoedown_buffer_eq(const hoedown_buffer *buf, const uint8_t *data, size_t size)
-{
- if (buf->size != size) return 0;
- return memcmp(buf->data, data, size) == 0;
-}
-
-int
-hoedown_buffer_eqs(const hoedown_buffer *buf, const char *str)
-{
- return hoedown_buffer_eq(buf, (const uint8_t *)str, strlen(str));
-}
-
-int
-hoedown_buffer_prefix(const hoedown_buffer *buf, const char *prefix)
-{
- size_t i;
-
- for (i = 0; i < buf->size; ++i) {
- if (prefix[i] == 0)
- return 0;
-
- if (buf->data[i] != prefix[i])
- return buf->data[i] - prefix[i];
- }
-
- return 0;
-}
-
-void
-hoedown_buffer_slurp(hoedown_buffer *buf, size_t size)
-{
- assert(buf && buf->unit);
-
- if (size >= buf->size) {
- buf->size = 0;
- return;
- }
-
- buf->size -= size;
- memmove(buf->data, buf->data + size, buf->size);
-}
-
-const char *
-hoedown_buffer_cstr(hoedown_buffer *buf)
-{
- assert(buf && buf->unit);
-
- if (buf->size < buf->asize && buf->data[buf->size] == 0)
- return (char *)buf->data;
-
- hoedown_buffer_grow(buf, buf->size + 1);
- buf->data[buf->size] = 0;
-
- return (char *)buf->data;
-}
-
-void
-hoedown_buffer_printf(hoedown_buffer *buf, const char *fmt, ...)
-{
- va_list ap;
- int n;
-
- assert(buf && buf->unit);
-
- if (buf->size >= buf->asize)
- hoedown_buffer_grow(buf, buf->size + 1);
-
- va_start(ap, fmt);
- n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
- va_end(ap);
-
- if (n < 0) {
-#ifndef _MSC_VER
- return;
-#else
- va_start(ap, fmt);
- n = _vscprintf(fmt, ap);
- va_end(ap);
-#endif
- }
-
- if ((size_t)n >= buf->asize - buf->size) {
- hoedown_buffer_grow(buf, buf->size + n + 1);
-
- va_start(ap, fmt);
- n = vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
- va_end(ap);
- }
-
- if (n < 0)
- return;
-
- buf->size += n;
-}
-
-void hoedown_buffer_put_utf8(hoedown_buffer *buf, unsigned int c) {
- unsigned char unichar[4];
-
- assert(buf && buf->unit);
-
- if (c < 0x80) {
- hoedown_buffer_putc(buf, c);
- }
- else if (c < 0x800) {
- unichar[0] = 192 + (c / 64);
- unichar[1] = 128 + (c % 64);
- hoedown_buffer_put(buf, unichar, 2);
- }
- else if (c - 0xd800u < 0x800) {
- HOEDOWN_BUFPUTSL(buf, "\xef\xbf\xbd");
- }
- else if (c < 0x10000) {
- unichar[0] = 224 + (c / 4096);
- unichar[1] = 128 + (c / 64) % 64;
- unichar[2] = 128 + (c % 64);
- hoedown_buffer_put(buf, unichar, 3);
- }
- else if (c < 0x110000) {
- unichar[0] = 240 + (c / 262144);
- unichar[1] = 128 + (c / 4096) % 64;
- unichar[2] = 128 + (c / 64) % 64;
- unichar[3] = 128 + (c % 64);
- hoedown_buffer_put(buf, unichar, 4);
- }
- else {
- HOEDOWN_BUFPUTSL(buf, "\xef\xbf\xbd");
- }
-}
diff --git a/libraries/hoedown/src/document.c b/libraries/hoedown/src/document.c
deleted file mode 100644
index e9e2ab11..00000000
--- a/libraries/hoedown/src/document.c
+++ /dev/null
@@ -1,2958 +0,0 @@
-#include "hoedown/document.h"
-
-#include <assert.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdio.h>
-
-#include "hoedown/stack.h"
-
-#ifndef _MSC_VER
-#include <strings.h>
-#else
-#define strncasecmp _strnicmp
-#endif
-
-#define REF_TABLE_SIZE 8
-
-#define BUFFER_BLOCK 0
-#define BUFFER_SPAN 1
-
-#define HOEDOWN_LI_END 8 /* internal list flag */
-
-const char *hoedown_find_block_tag(const char *str, unsigned int len);
-
-/***************
- * LOCAL TYPES *
- ***************/
-
-/* link_ref: reference to a link */
-struct link_ref {
- unsigned int id;
-
- hoedown_buffer *link;
- hoedown_buffer *title;
-
- struct link_ref *next;
-};
-
-/* footnote_ref: reference to a footnote */
-struct footnote_ref {
- unsigned int id;
-
- int is_used;
- unsigned int num;
-
- hoedown_buffer *contents;
-};
-
-/* footnote_item: an item in a footnote_list */
-struct footnote_item {
- struct footnote_ref *ref;
- struct footnote_item *next;
-};
-
-/* footnote_list: linked list of footnote_item */
-struct footnote_list {
- unsigned int count;
- struct footnote_item *head;
- struct footnote_item *tail;
-};
-
-/* char_trigger: function pointer to render active chars */
-/* returns the number of chars taken care of */
-/* data is the pointer of the beginning of the span */
-/* offset is the number of valid chars before data */
-typedef size_t
-(*char_trigger)(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-
-static size_t char_emphasis(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_quote(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_linebreak(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_codespan(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_escape(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_entity(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_langle_tag(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_autolink_www(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_superscript(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-static size_t char_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size);
-
-enum markdown_char_t {
- MD_CHAR_NONE = 0,
- MD_CHAR_EMPHASIS,
- MD_CHAR_CODESPAN,
- MD_CHAR_LINEBREAK,
- MD_CHAR_LINK,
- MD_CHAR_LANGLE,
- MD_CHAR_ESCAPE,
- MD_CHAR_ENTITY,
- MD_CHAR_AUTOLINK_URL,
- MD_CHAR_AUTOLINK_EMAIL,
- MD_CHAR_AUTOLINK_WWW,
- MD_CHAR_SUPERSCRIPT,
- MD_CHAR_QUOTE,
- MD_CHAR_MATH
-};
-
-static char_trigger markdown_char_ptrs[] = {
- NULL,
- &char_emphasis,
- &char_codespan,
- &char_linebreak,
- &char_link,
- &char_langle_tag,
- &char_escape,
- &char_entity,
- &char_autolink_url,
- &char_autolink_email,
- &char_autolink_www,
- &char_superscript,
- &char_quote,
- &char_math
-};
-
-struct hoedown_document {
- hoedown_renderer md;
- hoedown_renderer_data data;
-
- struct link_ref *refs[REF_TABLE_SIZE];
- struct footnote_list footnotes_found;
- struct footnote_list footnotes_used;
- uint8_t active_char[256];
- hoedown_stack work_bufs[2];
- hoedown_extensions ext_flags;
- size_t max_nesting;
- int in_link_body;
-};
-
-/***************************
- * HELPER FUNCTIONS *
- ***************************/
-
-static hoedown_buffer *
-newbuf(hoedown_document *doc, int type)
-{
- static const size_t buf_size[2] = {256, 64};
- hoedown_buffer *work = NULL;
- hoedown_stack *pool = &doc->work_bufs[type];
-
- if (pool->size < pool->asize &&
- pool->item[pool->size] != NULL) {
- work = pool->item[pool->size++];
- work->size = 0;
- } else {
- work = hoedown_buffer_new(buf_size[type]);
- hoedown_stack_push(pool, work);
- }
-
- return work;
-}
-
-static void
-popbuf(hoedown_document *doc, int type)
-{
- doc->work_bufs[type].size--;
-}
-
-static void
-unscape_text(hoedown_buffer *ob, hoedown_buffer *src)
-{
- size_t i = 0, org;
- while (i < src->size) {
- org = i;
- while (i < src->size && src->data[i] != '\\')
- i++;
-
- if (i > org)
- hoedown_buffer_put(ob, src->data + org, i - org);
-
- if (i + 1 >= src->size)
- break;
-
- hoedown_buffer_putc(ob, src->data[i + 1]);
- i += 2;
- }
-}
-
-static unsigned int
-hash_link_ref(const uint8_t *link_ref, size_t length)
-{
- size_t i;
- unsigned int hash = 0;
-
- for (i = 0; i < length; ++i)
- hash = tolower(link_ref[i]) + (hash << 6) + (hash << 16) - hash;
-
- return hash;
-}
-
-static struct link_ref *
-add_link_ref(
- struct link_ref **references,
- const uint8_t *name, size_t name_size)
-{
- struct link_ref *ref = hoedown_calloc(1, sizeof(struct link_ref));
-
- ref->id = hash_link_ref(name, name_size);
- ref->next = references[ref->id % REF_TABLE_SIZE];
-
- references[ref->id % REF_TABLE_SIZE] = ref;
- return ref;
-}
-
-static struct link_ref *
-find_link_ref(struct link_ref **references, uint8_t *name, size_t length)
-{
- unsigned int hash = hash_link_ref(name, length);
- struct link_ref *ref = NULL;
-
- ref = references[hash % REF_TABLE_SIZE];
-
- while (ref != NULL) {
- if (ref->id == hash)
- return ref;
-
- ref = ref->next;
- }
-
- return NULL;
-}
-
-static void
-free_link_refs(struct link_ref **references)
-{
- size_t i;
-
- for (i = 0; i < REF_TABLE_SIZE; ++i) {
- struct link_ref *r = references[i];
- struct link_ref *next;
-
- while (r) {
- next = r->next;
- hoedown_buffer_free(r->link);
- hoedown_buffer_free(r->title);
- free(r);
- r = next;
- }
- }
-}
-
-static struct footnote_ref *
-create_footnote_ref(struct footnote_list *list, const uint8_t *name, size_t name_size)
-{
- struct footnote_ref *ref = hoedown_calloc(1, sizeof(struct footnote_ref));
-
- ref->id = hash_link_ref(name, name_size);
-
- return ref;
-}
-
-static int
-add_footnote_ref(struct footnote_list *list, struct footnote_ref *ref)
-{
- struct footnote_item *item = hoedown_calloc(1, sizeof(struct footnote_item));
- if (!item)
- return 0;
- item->ref = ref;
-
- if (list->head == NULL) {
- list->head = list->tail = item;
- } else {
- list->tail->next = item;
- list->tail = item;
- }
- list->count++;
-
- return 1;
-}
-
-static struct footnote_ref *
-find_footnote_ref(struct footnote_list *list, uint8_t *name, size_t length)
-{
- unsigned int hash = hash_link_ref(name, length);
- struct footnote_item *item = NULL;
-
- item = list->head;
-
- while (item != NULL) {
- if (item->ref->id == hash)
- return item->ref;
- item = item->next;
- }
-
- return NULL;
-}
-
-static void
-free_footnote_ref(struct footnote_ref *ref)
-{
- hoedown_buffer_free(ref->contents);
- free(ref);
-}
-
-static void
-free_footnote_list(struct footnote_list *list, int free_refs)
-{
- struct footnote_item *item = list->head;
- struct footnote_item *next;
-
- while (item) {
- next = item->next;
- if (free_refs)
- free_footnote_ref(item->ref);
- free(item);
- item = next;
- }
-}
-
-
-/*
- * Check whether a char is a Markdown spacing char.
-
- * Right now we only consider spaces the actual
- * space and a newline: tabs and carriage returns
- * are filtered out during the preprocessing phase.
- *
- * If we wanted to actually be UTF-8 compliant, we
- * should instead extract an Unicode codepoint from
- * this character and check for space properties.
- */
-static int
-_isspace(int c)
-{
- return c == ' ' || c == '\n';
-}
-
-/* is_empty_all: verify that all the data is spacing */
-static int
-is_empty_all(const uint8_t *data, size_t size)
-{
- size_t i = 0;
- while (i < size && _isspace(data[i])) i++;
- return i == size;
-}
-
-/*
- * Replace all spacing characters in data with spaces. As a special
- * case, this collapses a newline with the previous space, if possible.
- */
-static void
-replace_spacing(hoedown_buffer *ob, const uint8_t *data, size_t size)
-{
- size_t i = 0, mark;
- hoedown_buffer_grow(ob, size);
- while (1) {
- mark = i;
- while (i < size && data[i] != '\n') i++;
- hoedown_buffer_put(ob, data + mark, i - mark);
-
- if (i >= size) break;
-
- if (!(i > 0 && data[i-1] == ' '))
- hoedown_buffer_putc(ob, ' ');
- i++;
- }
-}
-
-/****************************
- * INLINE PARSING FUNCTIONS *
- ****************************/
-
-/* is_mail_autolink • looks for the address part of a mail autolink and '>' */
-/* this is less strict than the original markdown e-mail address matching */
-static size_t
-is_mail_autolink(uint8_t *data, size_t size)
-{
- size_t i = 0, nb = 0;
-
- /* address is assumed to be: [-@._a-zA-Z0-9]+ with exactly one '@' */
- for (i = 0; i < size; ++i) {
- if (isalnum(data[i]))
- continue;
-
- switch (data[i]) {
- case '@':
- nb++;
-
- case '-':
- case '.':
- case '_':
- break;
-
- case '>':
- return (nb == 1) ? i + 1 : 0;
-
- default:
- return 0;
- }
- }
-
- return 0;
-}
-
-/* tag_length • returns the length of the given tag, or 0 is it's not valid */
-static size_t
-tag_length(uint8_t *data, size_t size, hoedown_autolink_type *autolink)
-{
- size_t i, j;
-
- /* a valid tag can't be shorter than 3 chars */
- if (size < 3) return 0;
-
- /* begins with a '<' optionally followed by '/', followed by letter or number */
- if (data[0] != '<') return 0;
- i = (data[1] == '/') ? 2 : 1;
-
- if (!isalnum(data[i]))
- return 0;
-
- /* scheme test */
- *autolink = HOEDOWN_AUTOLINK_NONE;
-
- /* try to find the beginning of an URI */
- while (i < size && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-'))
- i++;
-
- if (i > 1 && data[i] == '@') {
- if ((j = is_mail_autolink(data + i, size - i)) != 0) {
- *autolink = HOEDOWN_AUTOLINK_EMAIL;
- return i + j;
- }
- }
-
- if (i > 2 && data[i] == ':') {
- *autolink = HOEDOWN_AUTOLINK_NORMAL;
- i++;
- }
-
- /* completing autolink test: no spacing or ' or " */
- if (i >= size)
- *autolink = HOEDOWN_AUTOLINK_NONE;
-
- else if (*autolink) {
- j = i;
-
- while (i < size) {
- if (data[i] == '\\') i += 2;
- else if (data[i] == '>' || data[i] == '\'' ||
- data[i] == '"' || data[i] == ' ' || data[i] == '\n')
- break;
- else i++;
- }
-
- if (i >= size) return 0;
- if (i > j && data[i] == '>') return i + 1;
- /* one of the forbidden chars has been found */
- *autolink = HOEDOWN_AUTOLINK_NONE;
- }
-
- /* looking for something looking like a tag end */
- while (i < size && data[i] != '>') i++;
- if (i >= size) return 0;
- return i + 1;
-}
-
-/* parse_inline • parses inline markdown elements */
-static void
-parse_inline(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- size_t i = 0, end = 0, consumed = 0;
- hoedown_buffer work = { 0, 0, 0, 0, NULL, NULL, NULL };
- uint8_t *active_char = doc->active_char;
-
- if (doc->work_bufs[BUFFER_SPAN].size +
- doc->work_bufs[BUFFER_BLOCK].size > doc->max_nesting)
- return;
-
- while (i < size) {
- /* copying inactive chars into the output */
- while (end < size && active_char[data[end]] == 0)
- end++;
-
- if (doc->md.normal_text) {
- work.data = data + i;
- work.size = end - i;
- doc->md.normal_text(ob, &work, &doc->data);
- }
- else
- hoedown_buffer_put(ob, data + i, end - i);
-
- if (end >= size) break;
- i = end;
-
- end = markdown_char_ptrs[ (int)active_char[data[end]] ](ob, doc, data + i, i - consumed, size - i);
- if (!end) /* no action from the callback */
- end = i + 1;
- else {
- i += end;
- end = i;
- consumed = i;
- }
- }
-}
-
-/* is_escaped • returns whether special char at data[loc] is escaped by '\\' */
-static int
-is_escaped(uint8_t *data, size_t loc)
-{
- size_t i = loc;
- while (i >= 1 && data[i - 1] == '\\')
- i--;
-
- /* odd numbers of backslashes escapes data[loc] */
- return (loc - i) % 2;
-}
-
-/* find_emph_char • looks for the next emph uint8_t, skipping other constructs */
-static size_t
-find_emph_char(uint8_t *data, size_t size, uint8_t c)
-{
- size_t i = 0;
-
- while (i < size) {
- while (i < size && data[i] != c && data[i] != '[' && data[i] != '`')
- i++;
-
- if (i == size)
- return 0;
-
- /* not counting escaped chars */
- if (is_escaped(data, i)) {
- i++; continue;
- }
-
- if (data[i] == c)
- return i;
-
- /* skipping a codespan */
- if (data[i] == '`') {
- size_t span_nb = 0, bt;
- size_t tmp_i = 0;
-
- /* counting the number of opening backticks */
- while (i < size && data[i] == '`') {
- i++; span_nb++;
- }
-
- if (i >= size) return 0;
-
- /* finding the matching closing sequence */
- bt = 0;
- while (i < size && bt < span_nb) {
- if (!tmp_i && data[i] == c) tmp_i = i;
- if (data[i] == '`') bt++;
- else bt = 0;
- i++;
- }
-
- /* not a well-formed codespan; use found matching emph char */
- if (i >= size) return tmp_i;
- }
- /* skipping a link */
- else if (data[i] == '[') {
- size_t tmp_i = 0;
- uint8_t cc;
-
- i++;
- while (i < size && data[i] != ']') {
- if (!tmp_i && data[i] == c) tmp_i = i;
- i++;
- }
-
- i++;
- while (i < size && _isspace(data[i]))
- i++;
-
- if (i >= size)
- return tmp_i;
-
- switch (data[i]) {
- case '[':
- cc = ']'; break;
-
- case '(':
- cc = ')'; break;
-
- default:
- if (tmp_i)
- return tmp_i;
- else
- continue;
- }
-
- i++;
- while (i < size && data[i] != cc) {
- if (!tmp_i && data[i] == c) tmp_i = i;
- i++;
- }
-
- if (i >= size)
- return tmp_i;
-
- i++;
- }
- }
-
- return 0;
-}
-
-/* parse_emph1 • parsing single emphase */
-/* closed by a symbol not preceded by spacing and not followed by symbol */
-static size_t
-parse_emph1(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, uint8_t c)
-{
- size_t i = 0, len;
- hoedown_buffer *work = 0;
- int r;
-
- /* skipping one symbol if coming from emph3 */
- if (size > 1 && data[0] == c && data[1] == c) i = 1;
-
- while (i < size) {
- len = find_emph_char(data + i, size - i, c);
- if (!len) return 0;
- i += len;
- if (i >= size) return 0;
-
- if (data[i] == c && !_isspace(data[i - 1])) {
-
- if (doc->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
- if (i + 1 < size && isalnum(data[i + 1]))
- continue;
- }
-
- work = newbuf(doc, BUFFER_SPAN);
- parse_inline(work, doc, data, i);
-
- if (doc->ext_flags & HOEDOWN_EXT_UNDERLINE && c == '_')
- r = doc->md.underline(ob, work, &doc->data);
- else
- r = doc->md.emphasis(ob, work, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- return r ? i + 1 : 0;
- }
- }
-
- return 0;
-}
-
-/* parse_emph2 • parsing single emphase */
-static size_t
-parse_emph2(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, uint8_t c)
-{
- size_t i = 0, len;
- hoedown_buffer *work = 0;
- int r;
-
- while (i < size) {
- len = find_emph_char(data + i, size - i, c);
- if (!len) return 0;
- i += len;
-
- if (i + 1 < size && data[i] == c && data[i + 1] == c && i && !_isspace(data[i - 1])) {
- work = newbuf(doc, BUFFER_SPAN);
- parse_inline(work, doc, data, i);
-
- if (c == '~')
- r = doc->md.strikethrough(ob, work, &doc->data);
- else if (c == '=')
- r = doc->md.highlight(ob, work, &doc->data);
- else
- r = doc->md.double_emphasis(ob, work, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- return r ? i + 2 : 0;
- }
- i++;
- }
- return 0;
-}
-
-/* parse_emph3 • parsing single emphase */
-/* finds the first closing tag, and delegates to the other emph */
-static size_t
-parse_emph3(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, uint8_t c)
-{
- size_t i = 0, len;
- int r;
-
- while (i < size) {
- len = find_emph_char(data + i, size - i, c);
- if (!len) return 0;
- i += len;
-
- /* skip spacing preceded symbols */
- if (data[i] != c || _isspace(data[i - 1]))
- continue;
-
- if (i + 2 < size && data[i + 1] == c && data[i + 2] == c && doc->md.triple_emphasis) {
- /* triple symbol found */
- hoedown_buffer *work = newbuf(doc, BUFFER_SPAN);
-
- parse_inline(work, doc, data, i);
- r = doc->md.triple_emphasis(ob, work, &doc->data);
- popbuf(doc, BUFFER_SPAN);
- return r ? i + 3 : 0;
-
- } else if (i + 1 < size && data[i + 1] == c) {
- /* double symbol found, handing over to emph1 */
- len = parse_emph1(ob, doc, data - 2, size + 2, c);
- if (!len) return 0;
- else return len - 2;
-
- } else {
- /* single symbol found, handing over to emph2 */
- len = parse_emph2(ob, doc, data - 1, size + 1, c);
- if (!len) return 0;
- else return len - 1;
- }
- }
- return 0;
-}
-
-/* parse_math • parses a math span until the given ending delimiter */
-static size_t
-parse_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size, const char *end, size_t delimsz, int displaymode)
-{
- hoedown_buffer text = { NULL, 0, 0, 0, NULL, NULL, NULL };
- size_t i = delimsz;
-
- if (!doc->md.math)
- return 0;
-
- /* find ending delimiter */
- while (1) {
- while (i < size && data[i] != (uint8_t)end[0])
- i++;
-
- if (i >= size)
- return 0;
-
- if (!is_escaped(data, i) && !(i + delimsz > size)
- && memcmp(data + i, end, delimsz) == 0)
- break;
-
- i++;
- }
-
- /* prepare buffers */
- text.data = data + delimsz;
- text.size = i - delimsz;
-
- /* if this is a $$ and MATH_EXPLICIT is not active,
- * guess whether displaymode should be enabled from the context */
- i += delimsz;
- if (delimsz == 2 && !(doc->ext_flags & HOEDOWN_EXT_MATH_EXPLICIT))
- displaymode = is_empty_all(data - offset, offset) && is_empty_all(data + i, size - i);
-
- /* call callback */
- if (doc->md.math(ob, &text, displaymode, &doc->data))
- return i;
-
- return 0;
-}
-
-/* char_emphasis • single and double emphasis parsing */
-static size_t
-char_emphasis(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- uint8_t c = data[0];
- size_t ret;
-
- if (doc->ext_flags & HOEDOWN_EXT_NO_INTRA_EMPHASIS) {
- if (offset > 0 && !_isspace(data[-1]) && data[-1] != '>' && data[-1] != '(')
- return 0;
- }
-
- if (size > 2 && data[1] != c) {
- /* spacing cannot follow an opening emphasis;
- * strikethrough and highlight only takes two characters '~~' */
- if (c == '~' || c == '=' || _isspace(data[1]) || (ret = parse_emph1(ob, doc, data + 1, size - 1, c)) == 0)
- return 0;
-
- return ret + 1;
- }
-
- if (size > 3 && data[1] == c && data[2] != c) {
- if (_isspace(data[2]) || (ret = parse_emph2(ob, doc, data + 2, size - 2, c)) == 0)
- return 0;
-
- return ret + 2;
- }
-
- if (size > 4 && data[1] == c && data[2] == c && data[3] != c) {
- if (c == '~' || c == '=' || _isspace(data[3]) || (ret = parse_emph3(ob, doc, data + 3, size - 3, c)) == 0)
- return 0;
-
- return ret + 3;
- }
-
- return 0;
-}
-
-
-/* char_linebreak • '\n' preceded by two spaces (assuming linebreak != 0) */
-static size_t
-char_linebreak(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- if (offset < 2 || data[-1] != ' ' || data[-2] != ' ')
- return 0;
-
- /* removing the last space from ob and rendering */
- while (ob->size && ob->data[ob->size - 1] == ' ')
- ob->size--;
-
- return doc->md.linebreak(ob, &doc->data) ? 1 : 0;
-}
-
-
-/* char_codespan • '`' parsing a code span (assuming codespan != 0) */
-static size_t
-char_codespan(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- hoedown_buffer work = { NULL, 0, 0, 0, NULL, NULL, NULL };
- size_t end, nb = 0, i, f_begin, f_end;
-
- /* counting the number of backticks in the delimiter */
- while (nb < size && data[nb] == '`')
- nb++;
-
- /* finding the next delimiter */
- i = 0;
- for (end = nb; end < size && i < nb; end++) {
- if (data[end] == '`') i++;
- else i = 0;
- }
-
- if (i < nb && end >= size)
- return 0; /* no matching delimiter */
-
- /* trimming outside spaces */
- f_begin = nb;
- while (f_begin < end && data[f_begin] == ' ')
- f_begin++;
-
- f_end = end - nb;
- while (f_end > nb && data[f_end-1] == ' ')
- f_end--;
-
- /* real code span */
- if (f_begin < f_end) {
- work.data = data + f_begin;
- work.size = f_end - f_begin;
-
- if (!doc->md.codespan(ob, &work, &doc->data))
- end = 0;
- } else {
- if (!doc->md.codespan(ob, 0, &doc->data))
- end = 0;
- }
-
- return end;
-}
-
-/* char_quote • '"' parsing a quote */
-static size_t
-char_quote(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- size_t end, nq = 0, i, f_begin, f_end;
-
- /* counting the number of quotes in the delimiter */
- while (nq < size && data[nq] == '"')
- nq++;
-
- /* finding the next delimiter */
- end = nq;
- while (1) {
- i = end;
- end += find_emph_char(data + end, size - end, '"');
- if (end == i) return 0; /* no matching delimiter */
- i = end;
- while (end < size && data[end] == '"' && end - i < nq) end++;
- if (end - i >= nq) break;
- }
-
- /* trimming outside spaces */
- f_begin = nq;
- while (f_begin < end && data[f_begin] == ' ')
- f_begin++;
-
- f_end = end - nq;
- while (f_end > nq && data[f_end-1] == ' ')
- f_end--;
-
- /* real quote */
- if (f_begin < f_end) {
- hoedown_buffer *work = newbuf(doc, BUFFER_SPAN);
- parse_inline(work, doc, data + f_begin, f_end - f_begin);
-
- if (!doc->md.quote(ob, work, &doc->data))
- end = 0;
- popbuf(doc, BUFFER_SPAN);
- } else {
- if (!doc->md.quote(ob, 0, &doc->data))
- end = 0;
- }
-
- return end;
-}
-
-
-/* char_escape • '\\' backslash escape */
-static size_t
-char_escape(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- static const char *escape_chars = "\\`*_{}[]()#+-.!:|&<>^~=\"$";
- hoedown_buffer work = { 0, 0, 0, 0, NULL, NULL, NULL };
- size_t w;
-
- if (size > 1) {
- if (data[1] == '\\' && (doc->ext_flags & HOEDOWN_EXT_MATH) &&
- size > 2 && (data[2] == '(' || data[2] == '[')) {
- const char *end = (data[2] == '[') ? "\\\\]" : "\\\\)";
- w = parse_math(ob, doc, data, offset, size, end, 3, data[2] == '[');
- if (w) return w;
- }
-
- if (strchr(escape_chars, data[1]) == NULL)
- return 0;
-
- if (doc->md.normal_text) {
- work.data = data + 1;
- work.size = 1;
- doc->md.normal_text(ob, &work, &doc->data);
- }
- else hoedown_buffer_putc(ob, data[1]);
- } else if (size == 1) {
- hoedown_buffer_putc(ob, data[0]);
- }
-
- return 2;
-}
-
-/* char_entity • '&' escaped when it doesn't belong to an entity */
-/* valid entities are assumed to be anything matching &#?[A-Za-z0-9]+; */
-static size_t
-char_entity(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- size_t end = 1;
- hoedown_buffer work = { 0, 0, 0, 0, NULL, NULL, NULL };
-
- if (end < size && data[end] == '#')
- end++;
-
- while (end < size && isalnum(data[end]))
- end++;
-
- if (end < size && data[end] == ';')
- end++; /* real entity */
- else
- return 0; /* lone '&' */
-
- if (doc->md.entity) {
- work.data = data;
- work.size = end;
- doc->md.entity(ob, &work, &doc->data);
- }
- else hoedown_buffer_put(ob, data, end);
-
- return end;
-}
-
-/* char_langle_tag • '<' when tags or autolinks are allowed */
-static size_t
-char_langle_tag(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- hoedown_buffer work = { NULL, 0, 0, 0, NULL, NULL, NULL };
- hoedown_autolink_type altype = HOEDOWN_AUTOLINK_NONE;
- size_t end = tag_length(data, size, &altype);
- int ret = 0;
-
- work.data = data;
- work.size = end;
-
- if (end > 2) {
- if (doc->md.autolink && altype != HOEDOWN_AUTOLINK_NONE) {
- hoedown_buffer *u_link = newbuf(doc, BUFFER_SPAN);
- work.data = data + 1;
- work.size = end - 2;
- unscape_text(u_link, &work);
- ret = doc->md.autolink(ob, u_link, altype, &doc->data);
- popbuf(doc, BUFFER_SPAN);
- }
- else if (doc->md.raw_html)
- ret = doc->md.raw_html(ob, &work, &doc->data);
- }
-
- if (!ret) return 0;
- else return end;
-}
-
-static size_t
-char_autolink_www(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- hoedown_buffer *link, *link_url, *link_text;
- size_t link_len, rewind;
-
- if (!doc->md.link || doc->in_link_body)
- return 0;
-
- link = newbuf(doc, BUFFER_SPAN);
-
- if ((link_len = hoedown_autolink__www(&rewind, link, data, offset, size, HOEDOWN_AUTOLINK_SHORT_DOMAINS)) > 0) {
- link_url = newbuf(doc, BUFFER_SPAN);
- HOEDOWN_BUFPUTSL(link_url, "http://");
- hoedown_buffer_put(link_url, link->data, link->size);
-
- ob->size -= rewind;
- if (doc->md.normal_text) {
- link_text = newbuf(doc, BUFFER_SPAN);
- doc->md.normal_text(link_text, link, &doc->data);
- doc->md.link(ob, link_text, link_url, NULL, &doc->data);
- popbuf(doc, BUFFER_SPAN);
- } else {
- doc->md.link(ob, link, link_url, NULL, &doc->data);
- }
- popbuf(doc, BUFFER_SPAN);
- }
-
- popbuf(doc, BUFFER_SPAN);
- return link_len;
-}
-
-static size_t
-char_autolink_email(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- hoedown_buffer *link;
- size_t link_len, rewind;
-
- if (!doc->md.autolink || doc->in_link_body)
- return 0;
-
- link = newbuf(doc, BUFFER_SPAN);
-
- if ((link_len = hoedown_autolink__email(&rewind, link, data, offset, size, 0)) > 0) {
- ob->size -= rewind;
- doc->md.autolink(ob, link, HOEDOWN_AUTOLINK_EMAIL, &doc->data);
- }
-
- popbuf(doc, BUFFER_SPAN);
- return link_len;
-}
-
-static size_t
-char_autolink_url(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- hoedown_buffer *link;
- size_t link_len, rewind;
-
- if (!doc->md.autolink || doc->in_link_body)
- return 0;
-
- link = newbuf(doc, BUFFER_SPAN);
-
- if ((link_len = hoedown_autolink__url(&rewind, link, data, offset, size, 0)) > 0) {
- ob->size -= rewind;
- doc->md.autolink(ob, link, HOEDOWN_AUTOLINK_NORMAL, &doc->data);
- }
-
- popbuf(doc, BUFFER_SPAN);
- return link_len;
-}
-
-/* char_link • '[': parsing a link, a footnote or an image */
-static size_t
-char_link(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- int is_img = (offset && data[-1] == '!' && !is_escaped(data - offset, offset - 1));
- int is_footnote = (doc->ext_flags & HOEDOWN_EXT_FOOTNOTES && data[1] == '^');
- size_t i = 1, txt_e, link_b = 0, link_e = 0, title_b = 0, title_e = 0;
- hoedown_buffer *content = NULL;
- hoedown_buffer *link = NULL;
- hoedown_buffer *title = NULL;
- hoedown_buffer *u_link = NULL;
- size_t org_work_size = doc->work_bufs[BUFFER_SPAN].size;
- int ret = 0, in_title = 0, qtype = 0;
-
- /* checking whether the correct renderer exists */
- if ((is_footnote && !doc->md.footnote_ref) || (is_img && !doc->md.image)
- || (!is_img && !is_footnote && !doc->md.link))
- goto cleanup;
-
- /* looking for the matching closing bracket */
- i += find_emph_char(data + i, size - i, ']');
- txt_e = i;
-
- if (i < size && data[i] == ']') i++;
- else goto cleanup;
-
- /* footnote link */
- if (is_footnote) {
- hoedown_buffer id = { NULL, 0, 0, 0, NULL, NULL, NULL };
- struct footnote_ref *fr;
-
- if (txt_e < 3)
- goto cleanup;
-
- id.data = data + 2;
- id.size = txt_e - 2;
-
- fr = find_footnote_ref(&doc->footnotes_found, id.data, id.size);
-
- /* mark footnote used */
- if (fr && !fr->is_used) {
- if(!add_footnote_ref(&doc->footnotes_used, fr))
- goto cleanup;
- fr->is_used = 1;
- fr->num = doc->footnotes_used.count;
-
- /* render */
- if (doc->md.footnote_ref)
- ret = doc->md.footnote_ref(ob, fr->num, &doc->data);
- }
-
- goto cleanup;
- }
-
- /* skip any amount of spacing */
- /* (this is much more laxist than original markdown syntax) */
- while (i < size && _isspace(data[i]))
- i++;
-
- /* inline style link */
- if (i < size && data[i] == '(') {
- size_t nb_p;
-
- /* skipping initial spacing */
- i++;
-
- while (i < size && _isspace(data[i]))
- i++;
-
- link_b = i;
-
- /* looking for link end: ' " ) */
- /* Count the number of open parenthesis */
- nb_p = 0;
-
- while (i < size) {
- if (data[i] == '\\') i += 2;
- else if (data[i] == '(' && i != 0) {
- nb_p++; i++;
- }
- else if (data[i] == ')') {
- if (nb_p == 0) break;
- else nb_p--; i++;
- } else if (i >= 1 && _isspace(data[i-1]) && (data[i] == '\'' || data[i] == '"')) break;
- else i++;
- }
-
- if (i >= size) goto cleanup;
- link_e = i;
-
- /* looking for title end if present */
- if (data[i] == '\'' || data[i] == '"') {
- qtype = data[i];
- in_title = 1;
- i++;
- title_b = i;
-
- while (i < size) {
- if (data[i] == '\\') i += 2;
- else if (data[i] == qtype) {in_title = 0; i++;}
- else if ((data[i] == ')') && !in_title) break;
- else i++;
- }
-
- if (i >= size) goto cleanup;
-
- /* skipping spacing after title */
- title_e = i - 1;
- while (title_e > title_b && _isspace(data[title_e]))
- title_e--;
-
- /* checking for closing quote presence */
- if (data[title_e] != '\'' && data[title_e] != '"') {
- title_b = title_e = 0;
- link_e = i;
- }
- }
-
- /* remove spacing at the end of the link */
- while (link_e > link_b && _isspace(data[link_e - 1]))
- link_e--;
-
- /* remove optional angle brackets around the link */
- if (data[link_b] == '<') link_b++;
- if (data[link_e - 1] == '>') link_e--;
-
- /* building escaped link and title */
- if (link_e > link_b) {
- link = newbuf(doc, BUFFER_SPAN);
- hoedown_buffer_put(link, data + link_b, link_e - link_b);
- }
-
- if (title_e > title_b) {
- title = newbuf(doc, BUFFER_SPAN);
- hoedown_buffer_put(title, data + title_b, title_e - title_b);
- }
-
- i++;
- }
-
- /* reference style link */
- else if (i < size && data[i] == '[') {
- hoedown_buffer *id = newbuf(doc, BUFFER_SPAN);
- struct link_ref *lr;
-
- /* looking for the id */
- i++;
- link_b = i;
- while (i < size && data[i] != ']') i++;
- if (i >= size) goto cleanup;
- link_e = i;
-
- /* finding the link_ref */
- if (link_b == link_e)
- replace_spacing(id, data + 1, txt_e - 1);
- else
- hoedown_buffer_put(id, data + link_b, link_e - link_b);
-
- lr = find_link_ref(doc->refs, id->data, id->size);
- if (!lr)
- goto cleanup;
-
- /* keeping link and title from link_ref */
- link = lr->link;
- title = lr->title;
- i++;
- }
-
- /* shortcut reference style link */
- else {
- hoedown_buffer *id = newbuf(doc, BUFFER_SPAN);
- struct link_ref *lr;
-
- /* crafting the id */
- replace_spacing(id, data + 1, txt_e - 1);
-
- /* finding the link_ref */
- lr = find_link_ref(doc->refs, id->data, id->size);
- if (!lr)
- goto cleanup;
-
- /* keeping link and title from link_ref */
- link = lr->link;
- title = lr->title;
-
- /* rewinding the spacing */
- i = txt_e + 1;
- }
-
- /* building content: img alt is kept, only link content is parsed */
- if (txt_e > 1) {
- content = newbuf(doc, BUFFER_SPAN);
- if (is_img) {
- hoedown_buffer_put(content, data + 1, txt_e - 1);
- } else {
- /* disable autolinking when parsing inline the
- * content of a link */
- doc->in_link_body = 1;
- parse_inline(content, doc, data + 1, txt_e - 1);
- doc->in_link_body = 0;
- }
- }
-
- if (link) {
- u_link = newbuf(doc, BUFFER_SPAN);
- unscape_text(u_link, link);
- }
-
- /* calling the relevant rendering function */
- if (is_img) {
- if (ob->size && ob->data[ob->size - 1] == '!')
- ob->size -= 1;
-
- ret = doc->md.image(ob, u_link, title, content, &doc->data);
- } else {
- ret = doc->md.link(ob, content, u_link, title, &doc->data);
- }
-
- /* cleanup */
-cleanup:
- doc->work_bufs[BUFFER_SPAN].size = (int)org_work_size;
- return ret ? i : 0;
-}
-
-static size_t
-char_superscript(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- size_t sup_start, sup_len;
- hoedown_buffer *sup;
-
- if (!doc->md.superscript)
- return 0;
-
- if (size < 2)
- return 0;
-
- if (data[1] == '(') {
- sup_start = 2;
- sup_len = find_emph_char(data + 2, size - 2, ')') + 2;
-
- if (sup_len == size)
- return 0;
- } else {
- sup_start = sup_len = 1;
-
- while (sup_len < size && !_isspace(data[sup_len]))
- sup_len++;
- }
-
- if (sup_len - sup_start == 0)
- return (sup_start == 2) ? 3 : 0;
-
- sup = newbuf(doc, BUFFER_SPAN);
- parse_inline(sup, doc, data + sup_start, sup_len - sup_start);
- doc->md.superscript(ob, sup, &doc->data);
- popbuf(doc, BUFFER_SPAN);
-
- return (sup_start == 2) ? sup_len + 1 : sup_len;
-}
-
-static size_t
-char_math(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t offset, size_t size)
-{
- /* double dollar */
- if (size > 1 && data[1] == '$')
- return parse_math(ob, doc, data, offset, size, "$$", 2, 1);
-
- /* single dollar allowed only with MATH_EXPLICIT flag */
- if (doc->ext_flags & HOEDOWN_EXT_MATH_EXPLICIT)
- return parse_math(ob, doc, data, offset, size, "$", 1, 0);
-
- return 0;
-}
-
-/*********************************
- * BLOCK-LEVEL PARSING FUNCTIONS *
- *********************************/
-
-/* is_empty • returns the line length when it is empty, 0 otherwise */
-static size_t
-is_empty(const uint8_t *data, size_t size)
-{
- size_t i;
-
- for (i = 0; i < size && data[i] != '\n'; i++)
- if (data[i] != ' ')
- return 0;
-
- return i + 1;
-}
-
-/* is_hrule • returns whether a line is a horizontal rule */
-static int
-is_hrule(uint8_t *data, size_t size)
-{
- size_t i = 0, n = 0;
- uint8_t c;
-
- /* skipping initial spaces */
- if (size < 3) return 0;
- if (data[0] == ' ') { i++;
- if (data[1] == ' ') { i++;
- if (data[2] == ' ') { i++; } } }
-
- /* looking at the hrule uint8_t */
- if (i + 2 >= size
- || (data[i] != '*' && data[i] != '-' && data[i] != '_'))
- return 0;
- c = data[i];
-
- /* the whole line must be the char or space */
- while (i < size && data[i] != '\n') {
- if (data[i] == c) n++;
- else if (data[i] != ' ')
- return 0;
-
- i++;
- }
-
- return n >= 3;
-}
-
-/* check if a line is a code fence; return the
- * end of the code fence. if passed, width of
- * the fence rule and character will be returned */
-static size_t
-is_codefence(uint8_t *data, size_t size, size_t *width, uint8_t *chr)
-{
- size_t i = 0, n = 1;
- uint8_t c;
-
- /* skipping initial spaces */
- if (size < 3)
- return 0;
-
- if (data[0] == ' ') { i++;
- if (data[1] == ' ') { i++;
- if (data[2] == ' ') { i++; } } }
-
- /* looking at the hrule uint8_t */
- c = data[i];
- if (i + 2 >= size || !(c=='~' || c=='`'))
- return 0;
-
- /* the fence must be that same character */
- while (++i < size && data[i] == c)
- ++n;
-
- if (n < 3)
- return 0;
-
- if (width) *width = n;
- if (chr) *chr = c;
- return i;
-}
-
-/* expects single line, checks if it's a codefence and extracts language */
-static size_t
-parse_codefence(uint8_t *data, size_t size, hoedown_buffer *lang, size_t *width, uint8_t *chr)
-{
- size_t i, w, lang_start;
-
- i = w = is_codefence(data, size, width, chr);
- if (i == 0)
- return 0;
-
- while (i < size && _isspace(data[i]))
- i++;
-
- lang_start = i;
-
- while (i < size && !_isspace(data[i]))
- i++;
-
- lang->data = data + lang_start;
- lang->size = i - lang_start;
-
- /* Avoid parsing a codespan as a fence */
- i = lang_start + 2;
- while (i < size && !(data[i] == *chr && data[i-1] == *chr && data[i-2] == *chr)) i++;
- if (i < size) return 0;
-
- return w;
-}
-
-/* is_atxheader • returns whether the line is a hash-prefixed header */
-static int
-is_atxheader(hoedown_document *doc, uint8_t *data, size_t size)
-{
- if (data[0] != '#')
- return 0;
-
- if (doc->ext_flags & HOEDOWN_EXT_SPACE_HEADERS) {
- size_t level = 0;
-
- while (level < size && level < 6 && data[level] == '#')
- level++;
-
- if (level < size && data[level] != ' ')
- return 0;
- }
-
- return 1;
-}
-
-/* is_headerline • returns whether the line is a setext-style hdr underline */
-static int
-is_headerline(uint8_t *data, size_t size)
-{
- size_t i = 0;
-
- /* test of level 1 header */
- if (data[i] == '=') {
- for (i = 1; i < size && data[i] == '='; i++);
- while (i < size && data[i] == ' ') i++;
- return (i >= size || data[i] == '\n') ? 1 : 0; }
-
- /* test of level 2 header */
- if (data[i] == '-') {
- for (i = 1; i < size && data[i] == '-'; i++);
- while (i < size && data[i] == ' ') i++;
- return (i >= size || data[i] == '\n') ? 2 : 0; }
-
- return 0;
-}
-
-static int
-is_next_headerline(uint8_t *data, size_t size)
-{
- size_t i = 0;
-
- while (i < size && data[i] != '\n')
- i++;
-
- if (++i >= size)
- return 0;
-
- return is_headerline(data + i, size - i);
-}
-
-/* prefix_quote • returns blockquote prefix length */
-static size_t
-prefix_quote(uint8_t *data, size_t size)
-{
- size_t i = 0;
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
-
- if (i < size && data[i] == '>') {
- if (i + 1 < size && data[i + 1] == ' ')
- return i + 2;
-
- return i + 1;
- }
-
- return 0;
-}
-
-/* prefix_code • returns prefix length for block code*/
-static size_t
-prefix_code(uint8_t *data, size_t size)
-{
- if (size > 3 && data[0] == ' ' && data[1] == ' '
- && data[2] == ' ' && data[3] == ' ') return 4;
-
- return 0;
-}
-
-/* prefix_oli • returns ordered list item prefix */
-static size_t
-prefix_oli(uint8_t *data, size_t size)
-{
- size_t i = 0;
-
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
-
- if (i >= size || data[i] < '0' || data[i] > '9')
- return 0;
-
- while (i < size && data[i] >= '0' && data[i] <= '9')
- i++;
-
- if (i + 1 >= size || data[i] != '.' || data[i + 1] != ' ')
- return 0;
-
- if (is_next_headerline(data + i, size - i))
- return 0;
-
- return i + 2;
-}
-
-/* prefix_uli • returns ordered list item prefix */
-static size_t
-prefix_uli(uint8_t *data, size_t size)
-{
- size_t i = 0;
-
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
- if (i < size && data[i] == ' ') i++;
-
- if (i + 1 >= size ||
- (data[i] != '*' && data[i] != '+' && data[i] != '-') ||
- data[i + 1] != ' ')
- return 0;
-
- if (is_next_headerline(data + i, size - i))
- return 0;
-
- return i + 2;
-}
-
-
-/* parse_block • parsing of one block, returning next uint8_t to parse */
-static void parse_block(hoedown_buffer *ob, hoedown_document *doc,
- uint8_t *data, size_t size);
-
-
-/* parse_blockquote • handles parsing of a blockquote fragment */
-static size_t
-parse_blockquote(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- size_t beg, end = 0, pre, work_size = 0;
- uint8_t *work_data = 0;
- hoedown_buffer *out = 0;
-
- out = newbuf(doc, BUFFER_BLOCK);
- beg = 0;
- while (beg < size) {
- for (end = beg + 1; end < size && data[end - 1] != '\n'; end++);
-
- pre = prefix_quote(data + beg, end - beg);
-
- if (pre)
- beg += pre; /* skipping prefix */
-
- /* empty line followed by non-quote line */
- else if (is_empty(data + beg, end - beg) &&
- (end >= size || (prefix_quote(data + end, size - end) == 0 &&
- !is_empty(data + end, size - end))))
- break;
-
- if (beg < end) { /* copy into the in-place working buffer */
- /* hoedown_buffer_put(work, data + beg, end - beg); */
- if (!work_data)
- work_data = data + beg;
- else if (data + beg != work_data + work_size)
- memmove(work_data + work_size, data + beg, end - beg);
- work_size += end - beg;
- }
- beg = end;
- }
-
- parse_block(out, doc, work_data, work_size);
- if (doc->md.blockquote)
- doc->md.blockquote(ob, out, &doc->data);
- popbuf(doc, BUFFER_BLOCK);
- return end;
-}
-
-static size_t
-parse_htmlblock(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, int do_render);
-
-/* parse_blockquote • handles parsing of a regular paragraph */
-static size_t
-parse_paragraph(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- hoedown_buffer work = { NULL, 0, 0, 0, NULL, NULL, NULL };
- size_t i = 0, end = 0;
- int level = 0;
-
- work.data = data;
-
- while (i < size) {
- for (end = i + 1; end < size && data[end - 1] != '\n'; end++) /* empty */;
-
- if (is_empty(data + i, size - i))
- break;
-
- if ((level = is_headerline(data + i, size - i)) != 0)
- break;
-
- if (is_atxheader(doc, data + i, size - i) ||
- is_hrule(data + i, size - i) ||
- prefix_quote(data + i, size - i)) {
- end = i;
- break;
- }
-
- i = end;
- }
-
- work.size = i;
- while (work.size && data[work.size - 1] == '\n')
- work.size--;
-
- if (!level) {
- hoedown_buffer *tmp = newbuf(doc, BUFFER_BLOCK);
- parse_inline(tmp, doc, work.data, work.size);
- if (doc->md.paragraph)
- doc->md.paragraph(ob, tmp, &doc->data);
- popbuf(doc, BUFFER_BLOCK);
- } else {
- hoedown_buffer *header_work;
-
- if (work.size) {
- size_t beg;
- i = work.size;
- work.size -= 1;
-
- while (work.size && data[work.size] != '\n')
- work.size -= 1;
-
- beg = work.size + 1;
- while (work.size && data[work.size - 1] == '\n')
- work.size -= 1;
-
- if (work.size > 0) {
- hoedown_buffer *tmp = newbuf(doc, BUFFER_BLOCK);
- parse_inline(tmp, doc, work.data, work.size);
-
- if (doc->md.paragraph)
- doc->md.paragraph(ob, tmp, &doc->data);
-
- popbuf(doc, BUFFER_BLOCK);
- work.data += beg;
- work.size = i - beg;
- }
- else work.size = i;
- }
-
- header_work = newbuf(doc, BUFFER_SPAN);
- parse_inline(header_work, doc, work.data, work.size);
-
- if (doc->md.header)
- doc->md.header(ob, header_work, (int)level, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- }
-
- return end;
-}
-
-/* parse_fencedcode • handles parsing of a block-level code fragment */
-static size_t
-parse_fencedcode(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- hoedown_buffer text = { 0, 0, 0, 0, NULL, NULL, NULL };
- hoedown_buffer lang = { 0, 0, 0, 0, NULL, NULL, NULL };
- size_t i = 0, text_start, line_start;
- size_t w, w2;
- size_t width, width2;
- uint8_t chr, chr2;
-
- /* parse codefence line */
- while (i < size && data[i] != '\n')
- i++;
-
- w = parse_codefence(data, i, &lang, &width, &chr);
- if (!w)
- return 0;
-
- /* search for end */
- i++;
- text_start = i;
- while ((line_start = i) < size) {
- while (i < size && data[i] != '\n')
- i++;
-
- w2 = is_codefence(data + line_start, i - line_start, &width2, &chr2);
- if (w == w2 && width == width2 && chr == chr2 &&
- is_empty(data + (line_start+w), i - (line_start+w)))
- break;
-
- i++;
- }
-
- text.data = data + text_start;
- text.size = line_start - text_start;
-
- if (doc->md.blockcode)
- doc->md.blockcode(ob, text.size ? &text : NULL, lang.size ? &lang : NULL, &doc->data);
-
- return i;
-}
-
-static size_t
-parse_blockcode(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- size_t beg, end, pre;
- hoedown_buffer *work = 0;
-
- work = newbuf(doc, BUFFER_BLOCK);
-
- beg = 0;
- while (beg < size) {
- for (end = beg + 1; end < size && data[end - 1] != '\n'; end++) {};
- pre = prefix_code(data + beg, end - beg);
-
- if (pre)
- beg += pre; /* skipping prefix */
- else if (!is_empty(data + beg, end - beg))
- /* non-empty non-prefixed line breaks the pre */
- break;
-
- if (beg < end) {
- /* verbatim copy to the working buffer,
- escaping entities */
- if (is_empty(data + beg, end - beg))
- hoedown_buffer_putc(work, '\n');
- else hoedown_buffer_put(work, data + beg, end - beg);
- }
- beg = end;
- }
-
- while (work->size && work->data[work->size - 1] == '\n')
- work->size -= 1;
-
- hoedown_buffer_putc(work, '\n');
-
- if (doc->md.blockcode)
- doc->md.blockcode(ob, work, NULL, &doc->data);
-
- popbuf(doc, BUFFER_BLOCK);
- return beg;
-}
-
-/* parse_listitem • parsing of a single list item */
-/* assuming initial prefix is already removed */
-static size_t
-parse_listitem(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_list_flags *flags)
-{
- hoedown_buffer *work = 0, *inter = 0;
- size_t beg = 0, end, pre, sublist = 0, orgpre = 0, i;
- int in_empty = 0, has_inside_empty = 0, in_fence = 0;
-
- /* keeping track of the first indentation prefix */
- while (orgpre < 3 && orgpre < size && data[orgpre] == ' ')
- orgpre++;
-
- beg = prefix_uli(data, size);
- if (!beg)
- beg = prefix_oli(data, size);
-
- if (!beg)
- return 0;
-
- /* skipping to the beginning of the following line */
- end = beg;
- while (end < size && data[end - 1] != '\n')
- end++;
-
- /* getting working buffers */
- work = newbuf(doc, BUFFER_SPAN);
- inter = newbuf(doc, BUFFER_SPAN);
-
- /* putting the first line into the working buffer */
- hoedown_buffer_put(work, data + beg, end - beg);
- beg = end;
-
- /* process the following lines */
- while (beg < size) {
- size_t has_next_uli = 0, has_next_oli = 0;
-
- end++;
-
- while (end < size && data[end - 1] != '\n')
- end++;
-
- /* process an empty line */
- if (is_empty(data + beg, end - beg)) {
- in_empty = 1;
- beg = end;
- continue;
- }
-
- /* calculating the indentation */
- i = 0;
- while (i < 4 && beg + i < end && data[beg + i] == ' ')
- i++;
-
- pre = i;
-
- if (doc->ext_flags & HOEDOWN_EXT_FENCED_CODE) {
- if (is_codefence(data + beg + i, end - beg - i, NULL, NULL))
- in_fence = !in_fence;
- }
-
- /* Only check for new list items if we are **not** inside
- * a fenced code block */
- if (!in_fence) {
- has_next_uli = prefix_uli(data + beg + i, end - beg - i);
- has_next_oli = prefix_oli(data + beg + i, end - beg - i);
- }
-
- /* checking for a new item */
- if ((has_next_uli && !is_hrule(data + beg + i, end - beg - i)) || has_next_oli) {
- if (in_empty)
- has_inside_empty = 1;
-
- /* the following item must have the same (or less) indentation */
- if (pre <= orgpre) {
- /* if the following item has different list type, we end this list */
- if (in_empty && (
- ((*flags & HOEDOWN_LIST_ORDERED) && has_next_uli) ||
- (!(*flags & HOEDOWN_LIST_ORDERED) && has_next_oli)))
- *flags |= HOEDOWN_LI_END;
-
- break;
- }
-
- if (!sublist)
- sublist = work->size;
- }
- /* joining only indented stuff after empty lines;
- * note that now we only require 1 space of indentation
- * to continue a list */
- else if (in_empty && pre == 0) {
- *flags |= HOEDOWN_LI_END;
- break;
- }
-
- if (in_empty) {
- hoedown_buffer_putc(work, '\n');
- has_inside_empty = 1;
- in_empty = 0;
- }
-
- /* adding the line without prefix into the working buffer */
- hoedown_buffer_put(work, data + beg + i, end - beg - i);
- beg = end;
- }
-
- /* render of li contents */
- if (has_inside_empty)
- *flags |= HOEDOWN_LI_BLOCK;
-
- if (*flags & HOEDOWN_LI_BLOCK) {
- /* intermediate render of block li */
- if (sublist && sublist < work->size) {
- parse_block(inter, doc, work->data, sublist);
- parse_block(inter, doc, work->data + sublist, work->size - sublist);
- }
- else
- parse_block(inter, doc, work->data, work->size);
- } else {
- /* intermediate render of inline li */
- if (sublist && sublist < work->size) {
- parse_inline(inter, doc, work->data, sublist);
- parse_block(inter, doc, work->data + sublist, work->size - sublist);
- }
- else
- parse_inline(inter, doc, work->data, work->size);
- }
-
- /* render of li itself */
- if (doc->md.listitem)
- doc->md.listitem(ob, inter, *flags, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- popbuf(doc, BUFFER_SPAN);
- return beg;
-}
-
-
-/* parse_list • parsing ordered or unordered list block */
-static size_t
-parse_list(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, hoedown_list_flags flags)
-{
- hoedown_buffer *work = 0;
- size_t i = 0, j;
-
- work = newbuf(doc, BUFFER_BLOCK);
-
- while (i < size) {
- j = parse_listitem(work, doc, data + i, size - i, &flags);
- i += j;
-
- if (!j || (flags & HOEDOWN_LI_END))
- break;
- }
-
- if (doc->md.list)
- doc->md.list(ob, work, flags, &doc->data);
- popbuf(doc, BUFFER_BLOCK);
- return i;
-}
-
-/* parse_atxheader • parsing of atx-style headers */
-static size_t
-parse_atxheader(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- size_t level = 0;
- size_t i, end, skip;
-
- while (level < size && level < 6 && data[level] == '#')
- level++;
-
- for (i = level; i < size && data[i] == ' '; i++);
-
- for (end = i; end < size && data[end] != '\n'; end++);
- skip = end;
-
- while (end && data[end - 1] == '#')
- end--;
-
- while (end && data[end - 1] == ' ')
- end--;
-
- if (end > i) {
- hoedown_buffer *work = newbuf(doc, BUFFER_SPAN);
-
- parse_inline(work, doc, data + i, end - i);
-
- if (doc->md.header)
- doc->md.header(ob, work, (int)level, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- }
-
- return skip;
-}
-
-/* parse_footnote_def • parse a single footnote definition */
-static void
-parse_footnote_def(hoedown_buffer *ob, hoedown_document *doc, unsigned int num, uint8_t *data, size_t size)
-{
- hoedown_buffer *work = 0;
- work = newbuf(doc, BUFFER_SPAN);
-
- parse_block(work, doc, data, size);
-
- if (doc->md.footnote_def)
- doc->md.footnote_def(ob, work, num, &doc->data);
- popbuf(doc, BUFFER_SPAN);
-}
-
-/* parse_footnote_list • render the contents of the footnotes */
-static void
-parse_footnote_list(hoedown_buffer *ob, hoedown_document *doc, struct footnote_list *footnotes)
-{
- hoedown_buffer *work = 0;
- struct footnote_item *item;
- struct footnote_ref *ref;
-
- if (footnotes->count == 0)
- return;
-
- work = newbuf(doc, BUFFER_BLOCK);
-
- item = footnotes->head;
- while (item) {
- ref = item->ref;
- parse_footnote_def(work, doc, ref->num, ref->contents->data, ref->contents->size);
- item = item->next;
- }
-
- if (doc->md.footnotes)
- doc->md.footnotes(ob, work, &doc->data);
- popbuf(doc, BUFFER_BLOCK);
-}
-
-/* htmlblock_is_end • check for end of HTML block : </tag>( *)\n */
-/* returns tag length on match, 0 otherwise */
-/* assumes data starts with "<" */
-static size_t
-htmlblock_is_end(
- const char *tag,
- size_t tag_len,
- hoedown_document *doc,
- uint8_t *data,
- size_t size)
-{
- size_t i = tag_len + 3, w;
-
- /* try to match the end tag */
- /* note: we're not considering tags like "</tag >" which are still valid */
- if (i > size ||
- data[1] != '/' ||
- strncasecmp((char *)data + 2, tag, tag_len) != 0 ||
- data[tag_len + 2] != '>')
- return 0;
-
- /* rest of the line must be empty */
- if ((w = is_empty(data + i, size - i)) == 0 && i < size)
- return 0;
-
- return i + w;
-}
-
-/* htmlblock_find_end • try to find HTML block ending tag */
-/* returns the length on match, 0 otherwise */
-static size_t
-htmlblock_find_end(
- const char *tag,
- size_t tag_len,
- hoedown_document *doc,
- uint8_t *data,
- size_t size)
-{
- size_t i = 0, w;
-
- while (1) {
- while (i < size && data[i] != '<') i++;
- if (i >= size) return 0;
-
- w = htmlblock_is_end(tag, tag_len, doc, data + i, size - i);
- if (w) return i + w;
- i++;
- }
-}
-
-/* htmlblock_find_end_strict • try to find end of HTML block in strict mode */
-/* (it must be an unindented line, and have a blank line afterwads) */
-/* returns the length on match, 0 otherwise */
-static size_t
-htmlblock_find_end_strict(
- const char *tag,
- size_t tag_len,
- hoedown_document *doc,
- uint8_t *data,
- size_t size)
-{
- size_t i = 0, mark;
-
- while (1) {
- mark = i;
- while (i < size && data[i] != '\n') i++;
- if (i < size) i++;
- if (i == mark) return 0;
-
- if (data[mark] == ' ' && mark > 0) continue;
- mark += htmlblock_find_end(tag, tag_len, doc, data + mark, i - mark);
- if (mark == i && (is_empty(data + i, size - i) || i >= size)) break;
- }
-
- return i;
-}
-
-/* parse_htmlblock • parsing of inline HTML block */
-static size_t
-parse_htmlblock(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size, int do_render)
-{
- hoedown_buffer work = { NULL, 0, 0, 0, NULL, NULL, NULL };
- size_t i, j = 0, tag_len, tag_end;
- const char *curtag = NULL;
-
- work.data = data;
-
- /* identification of the opening tag */
- if (size < 2 || data[0] != '<')
- return 0;
-
- i = 1;
- while (i < size && data[i] != '>' && data[i] != ' ')
- i++;
-
- if (i < size)
- curtag = hoedown_find_block_tag((char *)data + 1, (int)i - 1);
-
- /* handling of special cases */
- if (!curtag) {
-
- /* HTML comment, laxist form */
- if (size > 5 && data[1] == '!' && data[2] == '-' && data[3] == '-') {
- i = 5;
-
- while (i < size && !(data[i - 2] == '-' && data[i - 1] == '-' && data[i] == '>'))
- i++;
-
- i++;
-
- if (i < size)
- j = is_empty(data + i, size - i);
-
- if (j) {
- work.size = i + j;
- if (do_render && doc->md.blockhtml)
- doc->md.blockhtml(ob, &work, &doc->data);
- return work.size;
- }
- }
-
- /* HR, which is the only self-closing block tag considered */
- if (size > 4 && (data[1] == 'h' || data[1] == 'H') && (data[2] == 'r' || data[2] == 'R')) {
- i = 3;
- while (i < size && data[i] != '>')
- i++;
-
- if (i + 1 < size) {
- i++;
- j = is_empty(data + i, size - i);
- if (j) {
- work.size = i + j;
- if (do_render && doc->md.blockhtml)
- doc->md.blockhtml(ob, &work, &doc->data);
- return work.size;
- }
- }
- }
-
- /* no special case recognised */
- return 0;
- }
-
- /* looking for a matching closing tag in strict mode */
- tag_len = strlen(curtag);
- tag_end = htmlblock_find_end_strict(curtag, tag_len, doc, data, size);
-
- /* if not found, trying a second pass looking for indented match */
- /* but not if tag is "ins" or "del" (following original Markdown.pl) */
- if (!tag_end && strcmp(curtag, "ins") != 0 && strcmp(curtag, "del") != 0)
- tag_end = htmlblock_find_end(curtag, tag_len, doc, data, size);
-
- if (!tag_end)
- return 0;
-
- /* the end of the block has been found */
- work.size = tag_end;
- if (do_render && doc->md.blockhtml)
- doc->md.blockhtml(ob, &work, &doc->data);
-
- return tag_end;
-}
-
-static void
-parse_table_row(
- hoedown_buffer *ob,
- hoedown_document *doc,
- uint8_t *data,
- size_t size,
- size_t columns,
- hoedown_table_flags *col_data,
- hoedown_table_flags header_flag)
-{
- size_t i = 0, col, len;
- hoedown_buffer *row_work = 0;
-
- if (!doc->md.table_cell || !doc->md.table_row)
- return;
-
- row_work = newbuf(doc, BUFFER_SPAN);
-
- if (i < size && data[i] == '|')
- i++;
-
- for (col = 0; col < columns && i < size; ++col) {
- size_t cell_start, cell_end;
- hoedown_buffer *cell_work;
-
- cell_work = newbuf(doc, BUFFER_SPAN);
-
- while (i < size && _isspace(data[i]))
- i++;
-
- cell_start = i;
-
- len = find_emph_char(data + i, size - i, '|');
- i += len ? len : size - i;
-
- cell_end = i - 1;
-
- while (cell_end > cell_start && _isspace(data[cell_end]))
- cell_end--;
-
- parse_inline(cell_work, doc, data + cell_start, 1 + cell_end - cell_start);
- doc->md.table_cell(row_work, cell_work, col_data[col] | header_flag, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
- i++;
- }
-
- for (; col < columns; ++col) {
- hoedown_buffer empty_cell = { 0, 0, 0, 0, NULL, NULL, NULL };
- doc->md.table_cell(row_work, &empty_cell, col_data[col] | header_flag, &doc->data);
- }
-
- doc->md.table_row(ob, row_work, &doc->data);
-
- popbuf(doc, BUFFER_SPAN);
-}
-
-static size_t
-parse_table_header(
- hoedown_buffer *ob,
- hoedown_document *doc,
- uint8_t *data,
- size_t size,
- size_t *columns,
- hoedown_table_flags **column_data)
-{
- int pipes;
- size_t i = 0, col, header_end, under_end;
-
- pipes = 0;
- while (i < size && data[i] != '\n')
- if (data[i++] == '|')
- pipes++;
-
- if (i == size || pipes == 0)
- return 0;
-
- header_end = i;
-
- while (header_end > 0 && _isspace(data[header_end - 1]))
- header_end--;
-
- if (data[0] == '|')
- pipes--;
-
- if (header_end && data[header_end - 1] == '|')
- pipes--;
-
- if (pipes < 0)
- return 0;
-
- *columns = pipes + 1;
- *column_data = hoedown_calloc(*columns, sizeof(hoedown_table_flags));
-
- /* Parse the header underline */
- i++;
- if (i < size && data[i] == '|')
- i++;
-
- under_end = i;
- while (under_end < size && data[under_end] != '\n')
- under_end++;
-
- for (col = 0; col < *columns && i < under_end; ++col) {
- size_t dashes = 0;
-
- while (i < under_end && data[i] == ' ')
- i++;
-
- if (data[i] == ':') {
- i++; (*column_data)[col] |= HOEDOWN_TABLE_ALIGN_LEFT;
- dashes++;
- }
-
- while (i < under_end && data[i] == '-') {
- i++; dashes++;
- }
-
- if (i < under_end && data[i] == ':') {
- i++; (*column_data)[col] |= HOEDOWN_TABLE_ALIGN_RIGHT;
- dashes++;
- }
-
- while (i < under_end && data[i] == ' ')
- i++;
-
- if (i < under_end && data[i] != '|' && data[i] != '+')
- break;
-
- if (dashes < 3)
- break;
-
- i++;
- }
-
- if (col < *columns)
- return 0;
-
- parse_table_row(
- ob, doc, data,
- header_end,
- *columns,
- *column_data,
- HOEDOWN_TABLE_HEADER
- );
-
- return under_end + 1;
-}
-
-static size_t
-parse_table(
- hoedown_buffer *ob,
- hoedown_document *doc,
- uint8_t *data,
- size_t size)
-{
- size_t i;
-
- hoedown_buffer *work = 0;
- hoedown_buffer *header_work = 0;
- hoedown_buffer *body_work = 0;
-
- size_t columns;
- hoedown_table_flags *col_data = NULL;
-
- work = newbuf(doc, BUFFER_BLOCK);
- header_work = newbuf(doc, BUFFER_SPAN);
- body_work = newbuf(doc, BUFFER_BLOCK);
-
- i = parse_table_header(header_work, doc, data, size, &columns, &col_data);
- if (i > 0) {
-
- while (i < size) {
- size_t row_start;
- int pipes = 0;
-
- row_start = i;
-
- while (i < size && data[i] != '\n')
- if (data[i++] == '|')
- pipes++;
-
- if (pipes == 0 || i == size) {
- i = row_start;
- break;
- }
-
- parse_table_row(
- body_work,
- doc,
- data + row_start,
- i - row_start,
- columns,
- col_data, 0
- );
-
- i++;
- }
-
- if (doc->md.table_header)
- doc->md.table_header(work, header_work, &doc->data);
-
- if (doc->md.table_body)
- doc->md.table_body(work, body_work, &doc->data);
-
- if (doc->md.table)
- doc->md.table(ob, work, &doc->data);
- }
-
- free(col_data);
- popbuf(doc, BUFFER_SPAN);
- popbuf(doc, BUFFER_BLOCK);
- popbuf(doc, BUFFER_BLOCK);
- return i;
-}
-
-/* parse_block • parsing of one block, returning next uint8_t to parse */
-static void
-parse_block(hoedown_buffer *ob, hoedown_document *doc, uint8_t *data, size_t size)
-{
- size_t beg, end, i;
- uint8_t *txt_data;
- beg = 0;
-
- if (doc->work_bufs[BUFFER_SPAN].size +
- doc->work_bufs[BUFFER_BLOCK].size > doc->max_nesting)
- return;
-
- while (beg < size) {
- txt_data = data + beg;
- end = size - beg;
-
- if (is_atxheader(doc, txt_data, end))
- beg += parse_atxheader(ob, doc, txt_data, end);
-
- else if (data[beg] == '<' && doc->md.blockhtml &&
- (i = parse_htmlblock(ob, doc, txt_data, end, 1)) != 0)
- beg += i;
-
- else if ((i = is_empty(txt_data, end)) != 0)
- beg += i;
-
- else if (is_hrule(txt_data, end)) {
- if (doc->md.hrule)
- doc->md.hrule(ob, &doc->data);
-
- while (beg < size && data[beg] != '\n')
- beg++;
-
- beg++;
- }
-
- else if ((doc->ext_flags & HOEDOWN_EXT_FENCED_CODE) != 0 &&
- (i = parse_fencedcode(ob, doc, txt_data, end)) != 0)
- beg += i;
-
- else if ((doc->ext_flags & HOEDOWN_EXT_TABLES) != 0 &&
- (i = parse_table(ob, doc, txt_data, end)) != 0)
- beg += i;
-
- else if (prefix_quote(txt_data, end))
- beg += parse_blockquote(ob, doc, txt_data, end);
-
- else if (!(doc->ext_flags & HOEDOWN_EXT_DISABLE_INDENTED_CODE) && prefix_code(txt_data, end))
- beg += parse_blockcode(ob, doc, txt_data, end);
-
- else if (prefix_uli(txt_data, end))
- beg += parse_list(ob, doc, txt_data, end, 0);
-
- else if (prefix_oli(txt_data, end))
- beg += parse_list(ob, doc, txt_data, end, HOEDOWN_LIST_ORDERED);
-
- else
- beg += parse_paragraph(ob, doc, txt_data, end);
- }
-}
-
-
-
-/*********************
- * REFERENCE PARSING *
- *********************/
-
-/* is_footnote • returns whether a line is a footnote definition or not */
-static int
-is_footnote(const uint8_t *data, size_t beg, size_t end, size_t *last, struct footnote_list *list)
-{
- size_t i = 0;
- hoedown_buffer *contents = 0;
- size_t ind = 0;
- int in_empty = 0;
- size_t start = 0;
-
- size_t id_offset, id_end;
-
- /* up to 3 optional leading spaces */
- if (beg + 3 >= end) return 0;
- if (data[beg] == ' ') { i = 1;
- if (data[beg + 1] == ' ') { i = 2;
- if (data[beg + 2] == ' ') { i = 3;
- if (data[beg + 3] == ' ') return 0; } } }
- i += beg;
-
- /* id part: caret followed by anything between brackets */
- if (data[i] != '[') return 0;
- i++;
- if (i >= end || data[i] != '^') return 0;
- i++;
- id_offset = i;
- while (i < end && data[i] != '\n' && data[i] != '\r' && data[i] != ']')
- i++;
- if (i >= end || data[i] != ']') return 0;
- id_end = i;
-
- /* spacer: colon (space | tab)* newline? (space | tab)* */
- i++;
- if (i >= end || data[i] != ':') return 0;
- i++;
-
- /* getting content buffer */
- contents = hoedown_buffer_new(64);
-
- start = i;
-
- /* process lines similar to a list item */
- while (i < end) {
- while (i < end && data[i] != '\n' && data[i] != '\r') i++;
-
- /* process an empty line */
- if (is_empty(data + start, i - start)) {
- in_empty = 1;
- if (i < end && (data[i] == '\n' || data[i] == '\r')) {
- i++;
- if (i < end && data[i] == '\n' && data[i - 1] == '\r') i++;
- }
- start = i;
- continue;
- }
-
- /* calculating the indentation */
- ind = 0;
- while (ind < 4 && start + ind < end && data[start + ind] == ' ')
- ind++;
-
- /* joining only indented stuff after empty lines;
- * note that now we only require 1 space of indentation
- * to continue, just like lists */
- if (ind == 0) {
- if (start == id_end + 2 && data[start] == '\t') {}
- else break;
- }
- else if (in_empty) {
- hoedown_buffer_putc(contents, '\n');
- }
-
- in_empty = 0;
-
- /* adding the line into the content buffer */
- hoedown_buffer_put(contents, data + start + ind, i - start - ind);
- /* add carriage return */
- if (i < end) {
- hoedown_buffer_putc(contents, '\n');
- if (i < end && (data[i] == '\n' || data[i] == '\r')) {
- i++;
- if (i < end && data[i] == '\n' && data[i - 1] == '\r') i++;
- }
- }
- start = i;
- }
-
- if (last)
- *last = start;
-
- if (list) {
- struct footnote_ref *ref;
- ref = create_footnote_ref(list, data + id_offset, id_end - id_offset);
- if (!ref)
- return 0;
- if (!add_footnote_ref(list, ref)) {
- free_footnote_ref(ref);
- return 0;
- }
- ref->contents = contents;
- }
-
- return 1;
-}
-
-/* is_ref • returns whether a line is a reference or not */
-static int
-is_ref(const uint8_t *data, size_t beg, size_t end, size_t *last, struct link_ref **refs)
-{
-/* int n; */
- size_t i = 0;
- size_t id_offset, id_end;
- size_t link_offset, link_end;
- size_t title_offset, title_end;
- size_t line_end;
-
- /* up to 3 optional leading spaces */
- if (beg + 3 >= end) return 0;
- if (data[beg] == ' ') { i = 1;
- if (data[beg + 1] == ' ') { i = 2;
- if (data[beg + 2] == ' ') { i = 3;
- if (data[beg + 3] == ' ') return 0; } } }
- i += beg;
-
- /* id part: anything but a newline between brackets */
- if (data[i] != '[') return 0;
- i++;
- id_offset = i;
- while (i < end && data[i] != '\n' && data[i] != '\r' && data[i] != ']')
- i++;
- if (i >= end || data[i] != ']') return 0;
- id_end = i;
-
- /* spacer: colon (space | tab)* newline? (space | tab)* */
- i++;
- if (i >= end || data[i] != ':') return 0;
- i++;
- while (i < end && data[i] == ' ') i++;
- if (i < end && (data[i] == '\n' || data[i] == '\r')) {
- i++;
- if (i < end && data[i] == '\r' && data[i - 1] == '\n') i++; }
- while (i < end && data[i] == ' ') i++;
- if (i >= end) return 0;
-
- /* link: spacing-free sequence, optionally between angle brackets */
- if (data[i] == '<')
- i++;
-
- link_offset = i;
-
- while (i < end && data[i] != ' ' && data[i] != '\n' && data[i] != '\r')
- i++;
-
- if (data[i - 1] == '>') link_end = i - 1;
- else link_end = i;
-
- /* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */
- while (i < end && data[i] == ' ') i++;
- if (i < end && data[i] != '\n' && data[i] != '\r'
- && data[i] != '\'' && data[i] != '"' && data[i] != '(')
- return 0;
- line_end = 0;
- /* computing end-of-line */
- if (i >= end || data[i] == '\r' || data[i] == '\n') line_end = i;
- if (i + 1 < end && data[i] == '\n' && data[i + 1] == '\r')
- line_end = i + 1;
-
- /* optional (space|tab)* spacer after a newline */
- if (line_end) {
- i = line_end + 1;
- while (i < end && data[i] == ' ') i++; }
-
- /* optional title: any non-newline sequence enclosed in '"()
- alone on its line */
- title_offset = title_end = 0;
- if (i + 1 < end
- && (data[i] == '\'' || data[i] == '"' || data[i] == '(')) {
- i++;
- title_offset = i;
- /* looking for EOL */
- while (i < end && data[i] != '\n' && data[i] != '\r') i++;
- if (i + 1 < end && data[i] == '\n' && data[i + 1] == '\r')
- title_end = i + 1;
- else title_end = i;
- /* stepping back */
- i -= 1;
- while (i > title_offset && data[i] == ' ')
- i -= 1;
- if (i > title_offset
- && (data[i] == '\'' || data[i] == '"' || data[i] == ')')) {
- line_end = title_end;
- title_end = i; } }
-
- if (!line_end || link_end == link_offset)
- return 0; /* garbage after the link empty link */
-
- /* a valid ref has been found, filling-in return structures */
- if (last)
- *last = line_end;
-
- if (refs) {
- struct link_ref *ref;
-
- ref = add_link_ref(refs, data + id_offset, id_end - id_offset);
- if (!ref)
- return 0;
-
- ref->link = hoedown_buffer_new(link_end - link_offset);
- hoedown_buffer_put(ref->link, data + link_offset, link_end - link_offset);
-
- if (title_end > title_offset) {
- ref->title = hoedown_buffer_new(title_end - title_offset);
- hoedown_buffer_put(ref->title, data + title_offset, title_end - title_offset);
- }
- }
-
- return 1;
-}
-
-static void expand_tabs(hoedown_buffer *ob, const uint8_t *line, size_t size)
-{
- /* This code makes two assumptions:
- * - Input is valid UTF-8. (Any byte with top two bits 10 is skipped,
- * whether or not it is a valid UTF-8 continuation byte.)
- * - Input contains no combining characters. (Combining characters
- * should be skipped but are not.)
- */
- size_t i = 0, tab = 0;
-
- while (i < size) {
- size_t org = i;
-
- while (i < size && line[i] != '\t') {
- /* ignore UTF-8 continuation bytes */
- if ((line[i] & 0xc0) != 0x80)
- tab++;
- i++;
- }
-
- if (i > org)
- hoedown_buffer_put(ob, line + org, i - org);
-
- if (i >= size)
- break;
-
- do {
- hoedown_buffer_putc(ob, ' '); tab++;
- } while (tab % 4);
-
- i++;
- }
-}
-
-/**********************
- * EXPORTED FUNCTIONS *
- **********************/
-
-hoedown_document *
-hoedown_document_new(
- const hoedown_renderer *renderer,
- hoedown_extensions extensions,
- size_t max_nesting)
-{
- hoedown_document *doc = NULL;
-
- assert(max_nesting > 0 && renderer);
-
- doc = hoedown_malloc(sizeof(hoedown_document));
- memcpy(&doc->md, renderer, sizeof(hoedown_renderer));
-
- doc->data.opaque = renderer->opaque;
-
- hoedown_stack_init(&doc->work_bufs[BUFFER_BLOCK], 4);
- hoedown_stack_init(&doc->work_bufs[BUFFER_SPAN], 8);
-
- memset(doc->active_char, 0x0, 256);
-
- if (extensions & HOEDOWN_EXT_UNDERLINE && doc->md.underline) {
- doc->active_char['_'] = MD_CHAR_EMPHASIS;
- }
-
- if (doc->md.emphasis || doc->md.double_emphasis || doc->md.triple_emphasis) {
- doc->active_char['*'] = MD_CHAR_EMPHASIS;
- doc->active_char['_'] = MD_CHAR_EMPHASIS;
- if (extensions & HOEDOWN_EXT_STRIKETHROUGH)
- doc->active_char['~'] = MD_CHAR_EMPHASIS;
- if (extensions & HOEDOWN_EXT_HIGHLIGHT)
- doc->active_char['='] = MD_CHAR_EMPHASIS;
- }
-
- if (doc->md.codespan)
- doc->active_char['`'] = MD_CHAR_CODESPAN;
-
- if (doc->md.linebreak)
- doc->active_char['\n'] = MD_CHAR_LINEBREAK;
-
- if (doc->md.image || doc->md.link || doc->md.footnotes || doc->md.footnote_ref)
- doc->active_char['['] = MD_CHAR_LINK;
-
- doc->active_char['<'] = MD_CHAR_LANGLE;
- doc->active_char['\\'] = MD_CHAR_ESCAPE;
- doc->active_char['&'] = MD_CHAR_ENTITY;
-
- if (extensions & HOEDOWN_EXT_AUTOLINK) {
- doc->active_char[':'] = MD_CHAR_AUTOLINK_URL;
- doc->active_char['@'] = MD_CHAR_AUTOLINK_EMAIL;
- doc->active_char['w'] = MD_CHAR_AUTOLINK_WWW;
- }
-
- if (extensions & HOEDOWN_EXT_SUPERSCRIPT)
- doc->active_char['^'] = MD_CHAR_SUPERSCRIPT;
-
- if (extensions & HOEDOWN_EXT_QUOTE)
- doc->active_char['"'] = MD_CHAR_QUOTE;
-
- if (extensions & HOEDOWN_EXT_MATH)
- doc->active_char['$'] = MD_CHAR_MATH;
-
- /* Extension data */
- doc->ext_flags = extensions;
- doc->max_nesting = max_nesting;
- doc->in_link_body = 0;
-
- return doc;
-}
-
-void
-hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size)
-{
- static const uint8_t UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
-
- hoedown_buffer *text;
- size_t beg, end;
-
- int footnotes_enabled;
-
- text = hoedown_buffer_new(64);
-
- /* Preallocate enough space for our buffer to avoid expanding while copying */
- hoedown_buffer_grow(text, size);
-
- /* reset the references table */
- memset(&doc->refs, 0x0, REF_TABLE_SIZE * sizeof(void *));
-
- footnotes_enabled = doc->ext_flags & HOEDOWN_EXT_FOOTNOTES;
-
- /* reset the footnotes lists */
- if (footnotes_enabled) {
- memset(&doc->footnotes_found, 0x0, sizeof(doc->footnotes_found));
- memset(&doc->footnotes_used, 0x0, sizeof(doc->footnotes_used));
- }
-
- /* first pass: looking for references, copying everything else */
- beg = 0;
-
- /* Skip a possible UTF-8 BOM, even though the Unicode standard
- * discourages having these in UTF-8 documents */
- if (size >= 3 && memcmp(data, UTF8_BOM, 3) == 0)
- beg += 3;
-
- while (beg < size) /* iterating over lines */
- if (footnotes_enabled && is_footnote(data, beg, size, &end, &doc->footnotes_found))
- beg = end;
- else if (is_ref(data, beg, size, &end, doc->refs))
- beg = end;
- else { /* skipping to the next line */
- end = beg;
- while (end < size && data[end] != '\n' && data[end] != '\r')
- end++;
-
- /* adding the line body if present */
- if (end > beg)
- expand_tabs(text, data + beg, end - beg);
-
- while (end < size && (data[end] == '\n' || data[end] == '\r')) {
- /* add one \n per newline */
- if (data[end] == '\n' || (end + 1 < size && data[end + 1] != '\n'))
- hoedown_buffer_putc(text, '\n');
- end++;
- }
-
- beg = end;
- }
-
- /* pre-grow the output buffer to minimize allocations */
- hoedown_buffer_grow(ob, text->size + (text->size >> 1));
-
- /* second pass: actual rendering */
- if (doc->md.doc_header)
- doc->md.doc_header(ob, 0, &doc->data);
-
- if (text->size) {
- /* adding a final newline if not already present */
- if (text->data[text->size - 1] != '\n' && text->data[text->size - 1] != '\r')
- hoedown_buffer_putc(text, '\n');
-
- parse_block(ob, doc, text->data, text->size);
- }
-
- /* footnotes */
- if (footnotes_enabled)
- parse_footnote_list(ob, doc, &doc->footnotes_used);
-
- if (doc->md.doc_footer)
- doc->md.doc_footer(ob, 0, &doc->data);
-
- /* clean-up */
- hoedown_buffer_free(text);
- free_link_refs(doc->refs);
- if (footnotes_enabled) {
- free_footnote_list(&doc->footnotes_found, 1);
- free_footnote_list(&doc->footnotes_used, 0);
- }
-
- assert(doc->work_bufs[BUFFER_SPAN].size == 0);
- assert(doc->work_bufs[BUFFER_BLOCK].size == 0);
-}
-
-void
-hoedown_document_render_inline(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *data, size_t size)
-{
- size_t i = 0, mark;
- hoedown_buffer *text = hoedown_buffer_new(64);
-
- /* reset the references table */
- memset(&doc->refs, 0x0, REF_TABLE_SIZE * sizeof(void *));
-
- /* first pass: expand tabs and process newlines */
- hoedown_buffer_grow(text, size);
- while (1) {
- mark = i;
- while (i < size && data[i] != '\n' && data[i] != '\r')
- i++;
-
- expand_tabs(text, data + mark, i - mark);
-
- if (i >= size)
- break;
-
- while (i < size && (data[i] == '\n' || data[i] == '\r')) {
- /* add one \n per newline */
- if (data[i] == '\n' || (i + 1 < size && data[i + 1] != '\n'))
- hoedown_buffer_putc(text, '\n');
- i++;
- }
- }
-
- /* second pass: actual rendering */
- hoedown_buffer_grow(ob, text->size + (text->size >> 1));
-
- if (doc->md.doc_header)
- doc->md.doc_header(ob, 1, &doc->data);
-
- parse_inline(ob, doc, text->data, text->size);
-
- if (doc->md.doc_footer)
- doc->md.doc_footer(ob, 1, &doc->data);
-
- /* clean-up */
- hoedown_buffer_free(text);
-
- assert(doc->work_bufs[BUFFER_SPAN].size == 0);
- assert(doc->work_bufs[BUFFER_BLOCK].size == 0);
-}
-
-void
-hoedown_document_free(hoedown_document *doc)
-{
- size_t i;
-
- for (i = 0; i < (size_t)doc->work_bufs[BUFFER_SPAN].asize; ++i)
- hoedown_buffer_free(doc->work_bufs[BUFFER_SPAN].item[i]);
-
- for (i = 0; i < (size_t)doc->work_bufs[BUFFER_BLOCK].asize; ++i)
- hoedown_buffer_free(doc->work_bufs[BUFFER_BLOCK].item[i]);
-
- hoedown_stack_uninit(&doc->work_bufs[BUFFER_SPAN]);
- hoedown_stack_uninit(&doc->work_bufs[BUFFER_BLOCK]);
-
- free(doc);
-}
diff --git a/libraries/hoedown/src/escape.c b/libraries/hoedown/src/escape.c
deleted file mode 100644
index ce25dd54..00000000
--- a/libraries/hoedown/src/escape.c
+++ /dev/null
@@ -1,188 +0,0 @@
-#include "hoedown/escape.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-
-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
-
-
-/*
- * The following characters will not be escaped:
- *
- * -_.+!*'(),%#@?=;:/,+&$ alphanum
- *
- * Note that this character set is the addition of:
- *
- * - The characters which are safe to be in an URL
- * - The characters which are *not* safe to be in
- * an URL because they are RESERVED characters.
- *
- * We assume (lazily) that any RESERVED char that
- * appears inside an URL is actually meant to
- * have its native function (i.e. as an URL
- * component/separator) and hence needs no escaping.
- *
- * There are two exceptions: the chacters & (amp)
- * and ' (single quote) do not appear in the table.
- * They are meant to appear in the URL as components,
- * yet they require special HTML-entity escaping
- * to generate valid HTML markup.
- *
- * All other characters will be escaped to %XX.
- *
- */
-static const uint8_t HREF_SAFE[UINT8_MAX+1] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-void
-hoedown_escape_href(hoedown_buffer *ob, const uint8_t *data, size_t size)
-{
- static const char hex_chars[] = "0123456789ABCDEF";
- size_t i = 0, mark;
- char hex_str[3];
-
- hex_str[0] = '%';
-
- while (i < size) {
- mark = i;
- while (i < size && HREF_SAFE[data[i]]) i++;
-
- /* Optimization for cases where there's nothing to escape */
- if (mark == 0 && i >= size) {
- hoedown_buffer_put(ob, data, size);
- return;
- }
-
- if (likely(i > mark)) {
- hoedown_buffer_put(ob, data + mark, i - mark);
- }
-
- /* escaping */
- if (i >= size)
- break;
-
- switch (data[i]) {
- /* amp appears all the time in URLs, but needs
- * HTML-entity escaping to be inside an href */
- case '&':
- HOEDOWN_BUFPUTSL(ob, "&amp;");
- break;
-
- /* the single quote is a valid URL character
- * according to the standard; it needs HTML
- * entity escaping too */
- case '\'':
- HOEDOWN_BUFPUTSL(ob, "&#x27;");
- break;
-
- /* the space can be escaped to %20 or a plus
- * sign. we're going with the generic escape
- * for now. the plus thing is more commonly seen
- * when building GET strings */
-#if 0
- case ' ':
- hoedown_buffer_putc(ob, '+');
- break;
-#endif
-
- /* every other character goes with a %XX escaping */
- default:
- hex_str[1] = hex_chars[(data[i] >> 4) & 0xF];
- hex_str[2] = hex_chars[data[i] & 0xF];
- hoedown_buffer_put(ob, (uint8_t *)hex_str, 3);
- }
-
- i++;
- }
-}
-
-
-/**
- * According to the OWASP rules:
- *
- * & --> &amp;
- * < --> &lt;
- * > --> &gt;
- * " --> &quot;
- * ' --> &#x27; &apos; is not recommended
- * / --> &#x2F; forward slash is included as it helps end an HTML entity
- *
- */
-static const uint8_t HTML_ESCAPE_TABLE[UINT8_MAX+1] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-static const char *HTML_ESCAPES[] = {
- "",
- "&quot;",
- "&amp;",
- "&#39;",
- "&#47;",
- "&lt;",
- "&gt;"
-};
-
-void
-hoedown_escape_html(hoedown_buffer *ob, const uint8_t *data, size_t size, int secure)
-{
- size_t i = 0, mark;
-
- while (1) {
- mark = i;
- while (i < size && HTML_ESCAPE_TABLE[data[i]] == 0) i++;
-
- /* Optimization for cases where there's nothing to escape */
- if (mark == 0 && i >= size) {
- hoedown_buffer_put(ob, data, size);
- return;
- }
-
- if (likely(i > mark))
- hoedown_buffer_put(ob, data + mark, i - mark);
-
- if (i >= size) break;
-
- /* The forward slash is only escaped in secure mode */
- if (!secure && data[i] == '/') {
- hoedown_buffer_putc(ob, '/');
- } else {
- hoedown_buffer_puts(ob, HTML_ESCAPES[HTML_ESCAPE_TABLE[data[i]]]);
- }
-
- i++;
- }
-}
diff --git a/libraries/hoedown/src/html.c b/libraries/hoedown/src/html.c
deleted file mode 100644
index 8bf3358e..00000000
--- a/libraries/hoedown/src/html.c
+++ /dev/null
@@ -1,754 +0,0 @@
-#include "hoedown/html.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#include "hoedown/escape.h"
-
-#define USE_XHTML(opt) (opt->flags & HOEDOWN_HTML_USE_XHTML)
-
-hoedown_html_tag
-hoedown_html_is_tag(const uint8_t *data, size_t size, const char *tagname)
-{
- size_t i;
- int closed = 0;
-
- if (size < 3 || data[0] != '<')
- return HOEDOWN_HTML_TAG_NONE;
-
- i = 1;
-
- if (data[i] == '/') {
- closed = 1;
- i++;
- }
-
- for (; i < size; ++i, ++tagname) {
- if (*tagname == 0)
- break;
-
- if (data[i] != *tagname)
- return HOEDOWN_HTML_TAG_NONE;
- }
-
- if (i == size)
- return HOEDOWN_HTML_TAG_NONE;
-
- if (isspace(data[i]) || data[i] == '>')
- return closed ? HOEDOWN_HTML_TAG_CLOSE : HOEDOWN_HTML_TAG_OPEN;
-
- return HOEDOWN_HTML_TAG_NONE;
-}
-
-static void escape_html(hoedown_buffer *ob, const uint8_t *source, size_t length)
-{
- hoedown_escape_html(ob, source, length, 0);
-}
-
-static void escape_href(hoedown_buffer *ob, const uint8_t *source, size_t length)
-{
- hoedown_escape_href(ob, source, length);
-}
-
-/********************
- * GENERIC RENDERER *
- ********************/
-static int
-rndr_autolink(hoedown_buffer *ob, const hoedown_buffer *link, hoedown_autolink_type type, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- if (!link || !link->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<a href=\"");
- if (type == HOEDOWN_AUTOLINK_EMAIL)
- HOEDOWN_BUFPUTSL(ob, "mailto:");
- escape_href(ob, link->data, link->size);
-
- if (state->link_attributes) {
- hoedown_buffer_putc(ob, '\"');
- state->link_attributes(ob, link, data);
- hoedown_buffer_putc(ob, '>');
- } else {
- HOEDOWN_BUFPUTSL(ob, "\">");
- }
-
- /*
- * Pretty printing: if we get an email address as
- * an actual URI, e.g. `mailto:foo@bar.com`, we don't
- * want to print the `mailto:` prefix
- */
- if (hoedown_buffer_prefix(link, "mailto:") == 0) {
- escape_html(ob, link->data + 7, link->size - 7);
- } else {
- escape_html(ob, link->data, link->size);
- }
-
- HOEDOWN_BUFPUTSL(ob, "</a>");
-
- return 1;
-}
-
-static void
-rndr_blockcode(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
-
- if (lang) {
- HOEDOWN_BUFPUTSL(ob, "<pre><code class=\"language-");
- escape_html(ob, lang->data, lang->size);
- HOEDOWN_BUFPUTSL(ob, "\">");
- } else {
- HOEDOWN_BUFPUTSL(ob, "<pre><code>");
- }
-
- if (text)
- escape_html(ob, text->data, text->size);
-
- HOEDOWN_BUFPUTSL(ob, "</code></pre>\n");
-}
-
-static void
-rndr_blockquote(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- HOEDOWN_BUFPUTSL(ob, "<blockquote>\n");
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</blockquote>\n");
-}
-
-static int
-rndr_codespan(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data)
-{
- HOEDOWN_BUFPUTSL(ob, "<code>");
- if (text) escape_html(ob, text->data, text->size);
- HOEDOWN_BUFPUTSL(ob, "</code>");
- return 1;
-}
-
-static int
-rndr_strikethrough(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<del>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</del>");
- return 1;
-}
-
-static int
-rndr_double_emphasis(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<strong>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</strong>");
-
- return 1;
-}
-
-static int
-rndr_emphasis(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size) return 0;
- HOEDOWN_BUFPUTSL(ob, "<em>");
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</em>");
- return 1;
-}
-
-static int
-rndr_underline(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<u>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</u>");
-
- return 1;
-}
-
-static int
-rndr_highlight(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<mark>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</mark>");
-
- return 1;
-}
-
-static int
-rndr_quote(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size)
- return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<q>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</q>");
-
- return 1;
-}
-
-static int
-rndr_linebreak(hoedown_buffer *ob, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
- hoedown_buffer_puts(ob, USE_XHTML(state) ? "<br/>\n" : "<br>\n");
- return 1;
-}
-
-static void
-rndr_header(hoedown_buffer *ob, const hoedown_buffer *content, int level, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- if (ob->size)
- hoedown_buffer_putc(ob, '\n');
-
- if (level <= state->toc_data.nesting_level)
- hoedown_buffer_printf(ob, "<h%d id=\"toc_%d\">", level, state->toc_data.header_count++);
- else
- hoedown_buffer_printf(ob, "<h%d>", level);
-
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- hoedown_buffer_printf(ob, "</h%d>\n", level);
-}
-
-static int
-rndr_link(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- HOEDOWN_BUFPUTSL(ob, "<a href=\"");
-
- if (link && link->size)
- escape_href(ob, link->data, link->size);
-
- if (title && title->size) {
- HOEDOWN_BUFPUTSL(ob, "\" title=\"");
- escape_html(ob, title->data, title->size);
- }
-
- if (state->link_attributes) {
- hoedown_buffer_putc(ob, '\"');
- state->link_attributes(ob, link, data);
- hoedown_buffer_putc(ob, '>');
- } else {
- HOEDOWN_BUFPUTSL(ob, "\">");
- }
-
- if (content && content->size) hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</a>");
- return 1;
-}
-
-static void
-rndr_list(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- hoedown_buffer_put(ob, (const uint8_t *)(flags & HOEDOWN_LIST_ORDERED ? "<ol>\n" : "<ul>\n"), 5);
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- hoedown_buffer_put(ob, (const uint8_t *)(flags & HOEDOWN_LIST_ORDERED ? "</ol>\n" : "</ul>\n"), 6);
-}
-
-static void
-rndr_listitem(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_list_flags flags, const hoedown_renderer_data *data)
-{
- HOEDOWN_BUFPUTSL(ob, "<li>");
- if (content) {
- size_t size = content->size;
- while (size && content->data[size - 1] == '\n')
- size--;
-
- hoedown_buffer_put(ob, content->data, size);
- }
- HOEDOWN_BUFPUTSL(ob, "</li>\n");
-}
-
-static void
-rndr_paragraph(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
- size_t i = 0;
-
- if (ob->size) hoedown_buffer_putc(ob, '\n');
-
- if (!content || !content->size)
- return;
-
- while (i < content->size && isspace(content->data[i])) i++;
-
- if (i == content->size)
- return;
-
- HOEDOWN_BUFPUTSL(ob, "<p>");
- if (state->flags & HOEDOWN_HTML_HARD_WRAP) {
- size_t org;
- while (i < content->size) {
- org = i;
- while (i < content->size && content->data[i] != '\n')
- i++;
-
- if (i > org)
- hoedown_buffer_put(ob, content->data + org, i - org);
-
- /*
- * do not insert a line break if this newline
- * is the last character on the paragraph
- */
- if (i >= content->size - 1)
- break;
-
- rndr_linebreak(ob, data);
- i++;
- }
- } else {
- hoedown_buffer_put(ob, content->data + i, content->size - i);
- }
- HOEDOWN_BUFPUTSL(ob, "</p>\n");
-}
-
-static void
-rndr_raw_block(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data)
-{
- size_t org, sz;
-
- if (!text)
- return;
-
- /* FIXME: Do we *really* need to trim the HTML? How does that make a difference? */
- sz = text->size;
- while (sz > 0 && text->data[sz - 1] == '\n')
- sz--;
-
- org = 0;
- while (org < sz && text->data[org] == '\n')
- org++;
-
- if (org >= sz)
- return;
-
- if (ob->size)
- hoedown_buffer_putc(ob, '\n');
-
- hoedown_buffer_put(ob, text->data + org, sz - org);
- hoedown_buffer_putc(ob, '\n');
-}
-
-static int
-rndr_triple_emphasis(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size) return 0;
- HOEDOWN_BUFPUTSL(ob, "<strong><em>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</em></strong>");
- return 1;
-}
-
-static void
-rndr_hrule(hoedown_buffer *ob, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- hoedown_buffer_puts(ob, USE_XHTML(state) ? "<hr/>\n" : "<hr>\n");
-}
-
-static int
-rndr_image(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
- if (!link || !link->size) return 0;
-
- HOEDOWN_BUFPUTSL(ob, "<img src=\"");
- escape_href(ob, link->data, link->size);
- HOEDOWN_BUFPUTSL(ob, "\" alt=\"");
-
- if (alt && alt->size)
- escape_html(ob, alt->data, alt->size);
-
- if (title && title->size) {
- HOEDOWN_BUFPUTSL(ob, "\" title=\"");
- escape_html(ob, title->data, title->size); }
-
- hoedown_buffer_puts(ob, USE_XHTML(state) ? "\"/>" : "\">");
- return 1;
-}
-
-static int
-rndr_raw_html(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- /* ESCAPE overrides SKIP_HTML. It doesn't look to see if
- * there are any valid tags, just escapes all of them. */
- if((state->flags & HOEDOWN_HTML_ESCAPE) != 0) {
- escape_html(ob, text->data, text->size);
- return 1;
- }
-
- if ((state->flags & HOEDOWN_HTML_SKIP_HTML) != 0)
- return 1;
-
- hoedown_buffer_put(ob, text->data, text->size);
- return 1;
-}
-
-static void
-rndr_table(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- HOEDOWN_BUFPUTSL(ob, "<table>\n");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</table>\n");
-}
-
-static void
-rndr_table_header(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- HOEDOWN_BUFPUTSL(ob, "<thead>\n");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</thead>\n");
-}
-
-static void
-rndr_table_body(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- HOEDOWN_BUFPUTSL(ob, "<tbody>\n");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</tbody>\n");
-}
-
-static void
-rndr_tablerow(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- HOEDOWN_BUFPUTSL(ob, "<tr>\n");
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</tr>\n");
-}
-
-static void
-rndr_tablecell(hoedown_buffer *ob, const hoedown_buffer *content, hoedown_table_flags flags, const hoedown_renderer_data *data)
-{
- if (flags & HOEDOWN_TABLE_HEADER) {
- HOEDOWN_BUFPUTSL(ob, "<th");
- } else {
- HOEDOWN_BUFPUTSL(ob, "<td");
- }
-
- switch (flags & HOEDOWN_TABLE_ALIGNMASK) {
- case HOEDOWN_TABLE_ALIGN_CENTER:
- HOEDOWN_BUFPUTSL(ob, " style=\"text-align: center\">");
- break;
-
- case HOEDOWN_TABLE_ALIGN_LEFT:
- HOEDOWN_BUFPUTSL(ob, " style=\"text-align: left\">");
- break;
-
- case HOEDOWN_TABLE_ALIGN_RIGHT:
- HOEDOWN_BUFPUTSL(ob, " style=\"text-align: right\">");
- break;
-
- default:
- HOEDOWN_BUFPUTSL(ob, ">");
- }
-
- if (content)
- hoedown_buffer_put(ob, content->data, content->size);
-
- if (flags & HOEDOWN_TABLE_HEADER) {
- HOEDOWN_BUFPUTSL(ob, "</th>\n");
- } else {
- HOEDOWN_BUFPUTSL(ob, "</td>\n");
- }
-}
-
-static int
-rndr_superscript(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (!content || !content->size) return 0;
- HOEDOWN_BUFPUTSL(ob, "<sup>");
- hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</sup>");
- return 1;
-}
-
-static void
-rndr_normal_text(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- if (content)
- escape_html(ob, content->data, content->size);
-}
-
-static void
-rndr_footnotes(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- if (ob->size) hoedown_buffer_putc(ob, '\n');
- HOEDOWN_BUFPUTSL(ob, "<div class=\"footnotes\">\n");
- hoedown_buffer_puts(ob, USE_XHTML(state) ? "<hr/>\n" : "<hr>\n");
- HOEDOWN_BUFPUTSL(ob, "<ol>\n");
-
- if (content) hoedown_buffer_put(ob, content->data, content->size);
-
- HOEDOWN_BUFPUTSL(ob, "\n</ol>\n</div>\n");
-}
-
-static void
-rndr_footnote_def(hoedown_buffer *ob, const hoedown_buffer *content, unsigned int num, const hoedown_renderer_data *data)
-{
- size_t i = 0;
- int pfound = 0;
-
- /* insert anchor at the end of first paragraph block */
- if (content) {
- while ((i+3) < content->size) {
- if (content->data[i++] != '<') continue;
- if (content->data[i++] != '/') continue;
- if (content->data[i++] != 'p' && content->data[i] != 'P') continue;
- if (content->data[i] != '>') continue;
- i -= 3;
- pfound = 1;
- break;
- }
- }
-
- hoedown_buffer_printf(ob, "\n<li id=\"fn%d\">\n", num);
- if (pfound) {
- hoedown_buffer_put(ob, content->data, i);
- hoedown_buffer_printf(ob, "&nbsp;<a href=\"#fnref%d\" rev=\"footnote\">&#8617;</a>", num);
- hoedown_buffer_put(ob, content->data + i, content->size - i);
- } else if (content) {
- hoedown_buffer_put(ob, content->data, content->size);
- }
- HOEDOWN_BUFPUTSL(ob, "</li>\n");
-}
-
-static int
-rndr_footnote_ref(hoedown_buffer *ob, unsigned int num, const hoedown_renderer_data *data)
-{
- hoedown_buffer_printf(ob, "<sup id=\"fnref%d\"><a href=\"#fn%d\" rel=\"footnote\">%d</a></sup>", num, num, num);
- return 1;
-}
-
-static int
-rndr_math(hoedown_buffer *ob, const hoedown_buffer *text, int displaymode, const hoedown_renderer_data *data)
-{
- hoedown_buffer_put(ob, (const uint8_t *)(displaymode ? "\\[" : "\\("), 2);
- escape_html(ob, text->data, text->size);
- hoedown_buffer_put(ob, (const uint8_t *)(displaymode ? "\\]" : "\\)"), 2);
- return 1;
-}
-
-static void
-toc_header(hoedown_buffer *ob, const hoedown_buffer *content, int level, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state = data->opaque;
-
- if (level <= state->toc_data.nesting_level) {
- /* set the level offset if this is the first header
- * we're parsing for the document */
- if (state->toc_data.current_level == 0)
- state->toc_data.level_offset = level - 1;
-
- level -= state->toc_data.level_offset;
-
- if (level > state->toc_data.current_level) {
- while (level > state->toc_data.current_level) {
- HOEDOWN_BUFPUTSL(ob, "<ul>\n<li>\n");
- state->toc_data.current_level++;
- }
- } else if (level < state->toc_data.current_level) {
- HOEDOWN_BUFPUTSL(ob, "</li>\n");
- while (level < state->toc_data.current_level) {
- HOEDOWN_BUFPUTSL(ob, "</ul>\n</li>\n");
- state->toc_data.current_level--;
- }
- HOEDOWN_BUFPUTSL(ob,"<li>\n");
- } else {
- HOEDOWN_BUFPUTSL(ob,"</li>\n<li>\n");
- }
-
- hoedown_buffer_printf(ob, "<a href=\"#toc_%d\">", state->toc_data.header_count++);
- if (content) hoedown_buffer_put(ob, content->data, content->size);
- HOEDOWN_BUFPUTSL(ob, "</a>\n");
- }
-}
-
-static int
-toc_link(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_renderer_data *data)
-{
- if (content && content->size) hoedown_buffer_put(ob, content->data, content->size);
- return 1;
-}
-
-static void
-toc_finalize(hoedown_buffer *ob, int inline_render, const hoedown_renderer_data *data)
-{
- hoedown_html_renderer_state *state;
-
- if (inline_render)
- return;
-
- state = data->opaque;
-
- while (state->toc_data.current_level > 0) {
- HOEDOWN_BUFPUTSL(ob, "</li>\n</ul>\n");
- state->toc_data.current_level--;
- }
-
- state->toc_data.header_count = 0;
-}
-
-hoedown_renderer *
-hoedown_html_toc_renderer_new(int nesting_level)
-{
- static const hoedown_renderer cb_default = {
- NULL,
-
- NULL,
- NULL,
- toc_header,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-
- NULL,
- rndr_codespan,
- rndr_double_emphasis,
- rndr_emphasis,
- rndr_underline,
- rndr_highlight,
- rndr_quote,
- NULL,
- NULL,
- toc_link,
- rndr_triple_emphasis,
- rndr_strikethrough,
- rndr_superscript,
- NULL,
- NULL,
- NULL,
-
- NULL,
- rndr_normal_text,
-
- NULL,
- toc_finalize
- };
-
- hoedown_html_renderer_state *state;
- hoedown_renderer *renderer;
-
- /* Prepare the state pointer */
- state = hoedown_malloc(sizeof(hoedown_html_renderer_state));
- memset(state, 0x0, sizeof(hoedown_html_renderer_state));
-
- state->toc_data.nesting_level = nesting_level;
-
- /* Prepare the renderer */
- renderer = hoedown_malloc(sizeof(hoedown_renderer));
- memcpy(renderer, &cb_default, sizeof(hoedown_renderer));
-
- renderer->opaque = state;
- return renderer;
-}
-
-hoedown_renderer *
-hoedown_html_renderer_new(hoedown_html_flags render_flags, int nesting_level)
-{
- static const hoedown_renderer cb_default = {
- NULL,
-
- rndr_blockcode,
- rndr_blockquote,
- rndr_header,
- rndr_hrule,
- rndr_list,
- rndr_listitem,
- rndr_paragraph,
- rndr_table,
- rndr_table_header,
- rndr_table_body,
- rndr_tablerow,
- rndr_tablecell,
- rndr_footnotes,
- rndr_footnote_def,
- rndr_raw_block,
-
- rndr_autolink,
- rndr_codespan,
- rndr_double_emphasis,
- rndr_emphasis,
- rndr_underline,
- rndr_highlight,
- rndr_quote,
- rndr_image,
- rndr_linebreak,
- rndr_link,
- rndr_triple_emphasis,
- rndr_strikethrough,
- rndr_superscript,
- rndr_footnote_ref,
- rndr_math,
- rndr_raw_html,
-
- NULL,
- rndr_normal_text,
-
- NULL,
- NULL
- };
-
- hoedown_html_renderer_state *state;
- hoedown_renderer *renderer;
-
- /* Prepare the state pointer */
- state = hoedown_malloc(sizeof(hoedown_html_renderer_state));
- memset(state, 0x0, sizeof(hoedown_html_renderer_state));
-
- state->flags = render_flags;
- state->toc_data.nesting_level = nesting_level;
-
- /* Prepare the renderer */
- renderer = hoedown_malloc(sizeof(hoedown_renderer));
- memcpy(renderer, &cb_default, sizeof(hoedown_renderer));
-
- if (render_flags & HOEDOWN_HTML_SKIP_HTML || render_flags & HOEDOWN_HTML_ESCAPE)
- renderer->blockhtml = NULL;
-
- renderer->opaque = state;
- return renderer;
-}
-
-void
-hoedown_html_renderer_free(hoedown_renderer *renderer)
-{
- free(renderer->opaque);
- free(renderer);
-}
diff --git a/libraries/hoedown/src/html_blocks.c b/libraries/hoedown/src/html_blocks.c
deleted file mode 100644
index f5e9dce9..00000000
--- a/libraries/hoedown/src/html_blocks.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/* ANSI-C code produced by gperf version 3.0.3 */
-/* Command-line: gperf -L ANSI-C -N hoedown_find_block_tag -c -C -E -S 1 --ignore-case -m100 html_block_names.gperf */
-/* Computed positions: -k'1-2' */
-
-#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
- && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
- && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
- && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
- && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
- && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
- && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
- && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
- && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
- && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
- && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
- && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
- && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
- && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
- && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
- && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
- && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
- && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
- && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
- && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
- && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
- && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
- && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
-/* The character set is not based on ISO-646. */
-#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
-#endif
-
-/* maximum key range = 24, duplicates = 0 */
-
-#ifndef GPERF_DOWNCASE
-#define GPERF_DOWNCASE 1
-static unsigned char gperf_downcase[256] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
- 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 60, 61, 62, 63, 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
- 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
- 122, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
- 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
- 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
- 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
- 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
- 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
- 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
- 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
- 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
- 255
- };
-#endif
-
-#ifndef GPERF_CASE_STRNCMP
-#define GPERF_CASE_STRNCMP 1
-static int
-gperf_case_strncmp (register const char *s1, register const char *s2, register unsigned int n)
-{
- for (; n > 0;)
- {
- unsigned char c1 = gperf_downcase[(unsigned char)*s1++];
- unsigned char c2 = gperf_downcase[(unsigned char)*s2++];
- if (c1 != 0 && c1 == c2)
- {
- n--;
- continue;
- }
- return (int)c1 - (int)c2;
- }
- return 0;
-}
-#endif
-
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
-hash (register const char *str, register unsigned int len)
-{
- static const unsigned char asso_values[] =
- {
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 22, 21, 19, 18, 16, 0, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 1, 25, 0, 25,
- 1, 0, 0, 13, 0, 25, 25, 11, 2, 1,
- 0, 25, 25, 5, 0, 2, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 1, 25,
- 0, 25, 1, 0, 0, 13, 0, 25, 25, 11,
- 2, 1, 0, 25, 25, 5, 0, 2, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25
- };
- register int hval = (int)len;
-
- switch (hval)
- {
- default:
- hval += asso_values[(unsigned char)str[1]+1];
- /*FALLTHROUGH*/
- case 1:
- hval += asso_values[(unsigned char)str[0]];
- break;
- }
- return hval;
-}
-
-#ifdef __GNUC__
-__inline
-#ifdef __GNUC_STDC_INLINE__
-__attribute__ ((__gnu_inline__))
-#endif
-#endif
-const char *
-hoedown_find_block_tag (register const char *str, register unsigned int len)
-{
- enum
- {
- TOTAL_KEYWORDS = 24,
- MIN_WORD_LENGTH = 1,
- MAX_WORD_LENGTH = 10,
- MIN_HASH_VALUE = 1,
- MAX_HASH_VALUE = 24
- };
-
- if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
- {
- register int key = hash (str, len);
-
- if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
- {
- register const char *resword;
-
- switch (key - 1)
- {
- case 0:
- resword = "p";
- goto compare;
- case 1:
- resword = "h6";
- goto compare;
- case 2:
- resword = "div";
- goto compare;
- case 3:
- resword = "del";
- goto compare;
- case 4:
- resword = "form";
- goto compare;
- case 5:
- resword = "table";
- goto compare;
- case 6:
- resword = "figure";
- goto compare;
- case 7:
- resword = "pre";
- goto compare;
- case 8:
- resword = "fieldset";
- goto compare;
- case 9:
- resword = "noscript";
- goto compare;
- case 10:
- resword = "script";
- goto compare;
- case 11:
- resword = "style";
- goto compare;
- case 12:
- resword = "dl";
- goto compare;
- case 13:
- resword = "ol";
- goto compare;
- case 14:
- resword = "ul";
- goto compare;
- case 15:
- resword = "math";
- goto compare;
- case 16:
- resword = "ins";
- goto compare;
- case 17:
- resword = "h5";
- goto compare;
- case 18:
- resword = "iframe";
- goto compare;
- case 19:
- resword = "h4";
- goto compare;
- case 20:
- resword = "h3";
- goto compare;
- case 21:
- resword = "blockquote";
- goto compare;
- case 22:
- resword = "h2";
- goto compare;
- case 23:
- resword = "h1";
- goto compare;
- }
- return 0;
- compare:
- if ((((unsigned char)*str ^ (unsigned char)*resword) & ~32) == 0 && !gperf_case_strncmp (str, resword, len) && resword[len] == '\0')
- return resword;
- }
- }
- return 0;
-}
diff --git a/libraries/hoedown/src/html_smartypants.c b/libraries/hoedown/src/html_smartypants.c
deleted file mode 100644
index d89624f3..00000000
--- a/libraries/hoedown/src/html_smartypants.c
+++ /dev/null
@@ -1,435 +0,0 @@
-#include "hoedown/html.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <ctype.h>
-
-#ifdef _MSC_VER
-#define snprintf _snprintf
-#endif
-
-struct smartypants_data {
- int in_squote;
- int in_dquote;
-};
-
-static size_t smartypants_cb__ltag(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__dquote(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__amp(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__period(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__number(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__dash(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__parens(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__squote(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__backtick(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-static size_t smartypants_cb__escape(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size);
-
-static size_t (*smartypants_cb_ptrs[])
- (hoedown_buffer *, struct smartypants_data *, uint8_t, const uint8_t *, size_t) =
-{
- NULL, /* 0 */
- smartypants_cb__dash, /* 1 */
- smartypants_cb__parens, /* 2 */
- smartypants_cb__squote, /* 3 */
- smartypants_cb__dquote, /* 4 */
- smartypants_cb__amp, /* 5 */
- smartypants_cb__period, /* 6 */
- smartypants_cb__number, /* 7 */
- smartypants_cb__ltag, /* 8 */
- smartypants_cb__backtick, /* 9 */
- smartypants_cb__escape, /* 10 */
-};
-
-static const uint8_t smartypants_cb_chars[UINT8_MAX+1] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 4, 0, 0, 0, 5, 3, 2, 0, 0, 0, 0, 1, 6, 0,
- 0, 7, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0,
- 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-static int
-word_boundary(uint8_t c)
-{
- return c == 0 || isspace(c) || ispunct(c);
-}
-
-/*
- If 'text' begins with any kind of single quote (e.g. "'" or "&apos;" etc.),
- returns the length of the sequence of characters that makes up the single-
- quote. Otherwise, returns zero.
-*/
-static size_t
-squote_len(const uint8_t *text, size_t size)
-{
- static char* single_quote_list[] = { "'", "&#39;", "&#x27;", "&apos;", NULL };
- char** p;
-
- for (p = single_quote_list; *p; ++p) {
- size_t len = strlen(*p);
- if (size >= len && memcmp(text, *p, len) == 0) {
- return len;
- }
- }
-
- return 0;
-}
-
-/* Converts " or ' at very beginning or end of a word to left or right quote */
-static int
-smartypants_quotes(hoedown_buffer *ob, uint8_t previous_char, uint8_t next_char, uint8_t quote, int *is_open)
-{
- char ent[8];
-
- if (*is_open && !word_boundary(next_char))
- return 0;
-
- if (!(*is_open) && !word_boundary(previous_char))
- return 0;
-
- snprintf(ent, sizeof(ent), "&%c%cquo;", (*is_open) ? 'r' : 'l', quote);
- *is_open = !(*is_open);
- hoedown_buffer_puts(ob, ent);
- return 1;
-}
-
-/*
- Converts ' to left or right single quote; but the initial ' might be in
- different forms, e.g. &apos; or &#39; or &#x27;.
- 'squote_text' points to the original single quote, and 'squote_size' is its length.
- 'text' points at the last character of the single-quote, e.g. ' or ;
-*/
-static size_t
-smartypants_squote(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size,
- const uint8_t *squote_text, size_t squote_size)
-{
- if (size >= 2) {
- uint8_t t1 = tolower(text[1]);
- size_t next_squote_len = squote_len(text+1, size-1);
-
- /* convert '' to &ldquo; or &rdquo; */
- if (next_squote_len > 0) {
- uint8_t next_char = (size > 1+next_squote_len) ? text[1+next_squote_len] : 0;
- if (smartypants_quotes(ob, previous_char, next_char, 'd', &smrt->in_dquote))
- return next_squote_len;
- }
-
- /* Tom's, isn't, I'm, I'd */
- if ((t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd') &&
- (size == 3 || word_boundary(text[2]))) {
- HOEDOWN_BUFPUTSL(ob, "&rsquo;");
- return 0;
- }
-
- /* you're, you'll, you've */
- if (size >= 3) {
- uint8_t t2 = tolower(text[2]);
-
- if (((t1 == 'r' && t2 == 'e') ||
- (t1 == 'l' && t2 == 'l') ||
- (t1 == 'v' && t2 == 'e')) &&
- (size == 4 || word_boundary(text[3]))) {
- HOEDOWN_BUFPUTSL(ob, "&rsquo;");
- return 0;
- }
- }
- }
-
- if (smartypants_quotes(ob, previous_char, size > 0 ? text[1] : 0, 's', &smrt->in_squote))
- return 0;
-
- hoedown_buffer_put(ob, squote_text, squote_size);
- return 0;
-}
-
-/* Converts ' to left or right single quote. */
-static size_t
-smartypants_cb__squote(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- return smartypants_squote(ob, smrt, previous_char, text, size, text, 1);
-}
-
-/* Converts (c), (r), (tm) */
-static size_t
-smartypants_cb__parens(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (size >= 3) {
- uint8_t t1 = tolower(text[1]);
- uint8_t t2 = tolower(text[2]);
-
- if (t1 == 'c' && t2 == ')') {
- HOEDOWN_BUFPUTSL(ob, "&copy;");
- return 2;
- }
-
- if (t1 == 'r' && t2 == ')') {
- HOEDOWN_BUFPUTSL(ob, "&reg;");
- return 2;
- }
-
- if (size >= 4 && t1 == 't' && t2 == 'm' && text[3] == ')') {
- HOEDOWN_BUFPUTSL(ob, "&trade;");
- return 3;
- }
- }
-
- hoedown_buffer_putc(ob, text[0]);
- return 0;
-}
-
-/* Converts "--" to em-dash, etc. */
-static size_t
-smartypants_cb__dash(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (size >= 3 && text[1] == '-' && text[2] == '-') {
- HOEDOWN_BUFPUTSL(ob, "&mdash;");
- return 2;
- }
-
- if (size >= 2 && text[1] == '-') {
- HOEDOWN_BUFPUTSL(ob, "&ndash;");
- return 1;
- }
-
- hoedown_buffer_putc(ob, text[0]);
- return 0;
-}
-
-/* Converts &quot; etc. */
-static size_t
-smartypants_cb__amp(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- size_t len;
- if (size >= 6 && memcmp(text, "&quot;", 6) == 0) {
- if (smartypants_quotes(ob, previous_char, size >= 7 ? text[6] : 0, 'd', &smrt->in_dquote))
- return 5;
- }
-
- len = squote_len(text, size);
- if (len > 0) {
- return (len-1) + smartypants_squote(ob, smrt, previous_char, text+(len-1), size-(len-1), text, len);
- }
-
- if (size >= 4 && memcmp(text, "&#0;", 4) == 0)
- return 3;
-
- hoedown_buffer_putc(ob, '&');
- return 0;
-}
-
-/* Converts "..." to ellipsis */
-static size_t
-smartypants_cb__period(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (size >= 3 && text[1] == '.' && text[2] == '.') {
- HOEDOWN_BUFPUTSL(ob, "&hellip;");
- return 2;
- }
-
- if (size >= 5 && text[1] == ' ' && text[2] == '.' && text[3] == ' ' && text[4] == '.') {
- HOEDOWN_BUFPUTSL(ob, "&hellip;");
- return 4;
- }
-
- hoedown_buffer_putc(ob, text[0]);
- return 0;
-}
-
-/* Converts `` to opening double quote */
-static size_t
-smartypants_cb__backtick(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (size >= 2 && text[1] == '`') {
- if (smartypants_quotes(ob, previous_char, size >= 3 ? text[2] : 0, 'd', &smrt->in_dquote))
- return 1;
- }
-
- hoedown_buffer_putc(ob, text[0]);
- return 0;
-}
-
-/* Converts 1/2, 1/4, 3/4 */
-static size_t
-smartypants_cb__number(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (word_boundary(previous_char) && size >= 3) {
- if (text[0] == '1' && text[1] == '/' && text[2] == '2') {
- if (size == 3 || word_boundary(text[3])) {
- HOEDOWN_BUFPUTSL(ob, "&frac12;");
- return 2;
- }
- }
-
- if (text[0] == '1' && text[1] == '/' && text[2] == '4') {
- if (size == 3 || word_boundary(text[3]) ||
- (size >= 5 && tolower(text[3]) == 't' && tolower(text[4]) == 'h')) {
- HOEDOWN_BUFPUTSL(ob, "&frac14;");
- return 2;
- }
- }
-
- if (text[0] == '3' && text[1] == '/' && text[2] == '4') {
- if (size == 3 || word_boundary(text[3]) ||
- (size >= 6 && tolower(text[3]) == 't' && tolower(text[4]) == 'h' && tolower(text[5]) == 's')) {
- HOEDOWN_BUFPUTSL(ob, "&frac34;");
- return 2;
- }
- }
- }
-
- hoedown_buffer_putc(ob, text[0]);
- return 0;
-}
-
-/* Converts " to left or right double quote */
-static size_t
-smartypants_cb__dquote(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (!smartypants_quotes(ob, previous_char, size > 0 ? text[1] : 0, 'd', &smrt->in_dquote))
- HOEDOWN_BUFPUTSL(ob, "&quot;");
-
- return 0;
-}
-
-static size_t
-smartypants_cb__ltag(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- static const char *skip_tags[] = {
- "pre", "code", "var", "samp", "kbd", "math", "script", "style"
- };
- static const size_t skip_tags_count = 8;
-
- size_t tag, i = 0;
-
- /* This is a comment. Copy everything verbatim until --> or EOF is seen. */
- if (i + 4 < size && memcmp(text, "<!--", 4) == 0) {
- i += 4;
- while (i + 3 < size && memcmp(text + i, "-->", 3) != 0)
- i++;
- i += 3;
- hoedown_buffer_put(ob, text, i + 1);
- return i;
- }
-
- while (i < size && text[i] != '>')
- i++;
-
- for (tag = 0; tag < skip_tags_count; ++tag) {
- if (hoedown_html_is_tag(text, size, skip_tags[tag]) == HOEDOWN_HTML_TAG_OPEN)
- break;
- }
-
- if (tag < skip_tags_count) {
- for (;;) {
- while (i < size && text[i] != '<')
- i++;
-
- if (i == size)
- break;
-
- if (hoedown_html_is_tag(text + i, size - i, skip_tags[tag]) == HOEDOWN_HTML_TAG_CLOSE)
- break;
-
- i++;
- }
-
- while (i < size && text[i] != '>')
- i++;
- }
-
- hoedown_buffer_put(ob, text, i + 1);
- return i;
-}
-
-static size_t
-smartypants_cb__escape(hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
-{
- if (size < 2)
- return 0;
-
- switch (text[1]) {
- case '\\':
- case '"':
- case '\'':
- case '.':
- case '-':
- case '`':
- hoedown_buffer_putc(ob, text[1]);
- return 1;
-
- default:
- hoedown_buffer_putc(ob, '\\');
- return 0;
- }
-}
-
-#if 0
-static struct {
- uint8_t c0;
- const uint8_t *pattern;
- const uint8_t *entity;
- int skip;
-} smartypants_subs[] = {
- { '\'', "'s>", "&rsquo;", 0 },
- { '\'', "'t>", "&rsquo;", 0 },
- { '\'', "'re>", "&rsquo;", 0 },
- { '\'', "'ll>", "&rsquo;", 0 },
- { '\'', "'ve>", "&rsquo;", 0 },
- { '\'', "'m>", "&rsquo;", 0 },
- { '\'', "'d>", "&rsquo;", 0 },
- { '-', "--", "&mdash;", 1 },
- { '-', "<->", "&ndash;", 0 },
- { '.', "...", "&hellip;", 2 },
- { '.', ". . .", "&hellip;", 4 },
- { '(', "(c)", "&copy;", 2 },
- { '(', "(r)", "&reg;", 2 },
- { '(', "(tm)", "&trade;", 3 },
- { '3', "<3/4>", "&frac34;", 2 },
- { '3', "<3/4ths>", "&frac34;", 2 },
- { '1', "<1/2>", "&frac12;", 2 },
- { '1', "<1/4>", "&frac14;", 2 },
- { '1', "<1/4th>", "&frac14;", 2 },
- { '&', "&#0;", 0, 3 },
-};
-#endif
-
-void
-hoedown_html_smartypants(hoedown_buffer *ob, const uint8_t *text, size_t size)
-{
- size_t i;
- struct smartypants_data smrt = {0, 0};
-
- if (!text)
- return;
-
- hoedown_buffer_grow(ob, size);
-
- for (i = 0; i < size; ++i) {
- size_t org;
- uint8_t action = 0;
-
- org = i;
- while (i < size && (action = smartypants_cb_chars[text[i]]) == 0)
- i++;
-
- if (i > org)
- hoedown_buffer_put(ob, text + org, i - org);
-
- if (i < size) {
- i += smartypants_cb_ptrs[(int)action]
- (ob, &smrt, i ? text[i - 1] : 0, text + i, size - i);
- }
- }
-}
diff --git a/libraries/hoedown/src/stack.c b/libraries/hoedown/src/stack.c
deleted file mode 100644
index 0523c11b..00000000
--- a/libraries/hoedown/src/stack.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "hoedown/stack.h"
-
-#include "hoedown/buffer.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-void
-hoedown_stack_init(hoedown_stack *st, size_t initial_size)
-{
- assert(st);
-
- st->item = NULL;
- st->size = st->asize = 0;
-
- if (!initial_size)
- initial_size = 8;
-
- hoedown_stack_grow(st, initial_size);
-}
-
-void
-hoedown_stack_uninit(hoedown_stack *st)
-{
- assert(st);
-
- free(st->item);
-}
-
-void
-hoedown_stack_grow(hoedown_stack *st, size_t neosz)
-{
- assert(st);
-
- if (st->asize >= neosz)
- return;
-
- st->item = hoedown_realloc(st->item, neosz * sizeof(void *));
- memset(st->item + st->asize, 0x0, (neosz - st->asize) * sizeof(void *));
-
- st->asize = neosz;
-
- if (st->size > neosz)
- st->size = neosz;
-}
-
-void
-hoedown_stack_push(hoedown_stack *st, void *item)
-{
- assert(st);
-
- if (st->size >= st->asize)
- hoedown_stack_grow(st, st->size * 2);
-
- st->item[st->size++] = item;
-}
-
-void *
-hoedown_stack_pop(hoedown_stack *st)
-{
- assert(st);
-
- if (!st->size)
- return NULL;
-
- return st->item[--st->size];
-}
-
-void *
-hoedown_stack_top(const hoedown_stack *st)
-{
- assert(st);
-
- if (!st->size)
- return NULL;
-
- return st->item[st->size - 1];
-}
diff --git a/libraries/hoedown/src/version.c b/libraries/hoedown/src/version.c
deleted file mode 100644
index 10d36cb9..00000000
--- a/libraries/hoedown/src/version.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "hoedown/version.h"
-
-void
-hoedown_version(int *major, int *minor, int *revision)
-{
- *major = HOEDOWN_VERSION_MAJOR;
- *minor = HOEDOWN_VERSION_MINOR;
- *revision = HOEDOWN_VERSION_REVISION;
-}
diff --git a/nix/default.nix b/nix/default.nix
index 82ba9c7d..f6ab1332 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -18,6 +18,7 @@
, extra-cmake-modules
, tomlplusplus
, ghc_filesystem
+, cmark
, msaClientID ? ""
, jdks ? [ jdk17 jdk8 ]
@@ -41,6 +42,7 @@ stdenv.mkDerivation rec {
quazip
ghc_filesystem
tomlplusplus
+ cmark
] ++ lib.optional (lib.versionAtLeast qtbase.version "6") qtwayland;
cmakeFlags = lib.optionals (msaClientID != "") [ "-DLauncher_MSA_CLIENT_ID=${msaClientID}" ]