diff --git a/dll/Markdig.LICENSE.txt b/dll/Markdig.LICENSE.txt new file mode 100644 index 0000000..0b2323f --- /dev/null +++ b/dll/Markdig.LICENSE.txt @@ -0,0 +1,23 @@ +Copyright (c) 2018-2019, Alexandre Mutel +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification +, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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 HOLDER 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. \ No newline at end of file diff --git a/dll/Markdig.dll b/dll/Markdig.dll new file mode 100644 index 0000000..797f3cb Binary files /dev/null and b/dll/Markdig.dll differ diff --git a/fonts/DejaVuSansMono.LICENSE.txt b/fonts/DejaVuSansMono.LICENSE.txt new file mode 100644 index 0000000..b3d93a1 --- /dev/null +++ b/fonts/DejaVuSansMono.LICENSE.txt @@ -0,0 +1,78 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: DejaVu fonts +Upstream-Author: Stepan Roh (original author), + see /usr/share/doc/fonts-dejavu-core/AUTHORS for full list +Source: https://dejavu-fonts.github.io/ + +Files: * +Copyright: Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. + Bitstream Vera is a trademark of Bitstream, Inc. + DejaVu changes are in public domain. +License: bitstream-vera + Permission is hereby granted, free of charge, to any person obtaining a copy + of the fonts accompanying this license ("Fonts") and associated + documentation files (the "Font Software"), to reproduce and distribute the + Font Software, including without limitation the rights to use, copy, merge, + publish, distribute, and/or sell copies of the Font Software, and to permit + persons to whom the Font Software is furnished to do so, subject to the + following conditions: + . + The above copyright and trademark notices and this permission notice shall + be included in all copies of one or more of the Font Software typefaces. + . + The Font Software may be modified, altered, or added to, and in particular + the designs of glyphs or characters in the Fonts may be modified and + additional glyphs or characters may be added to the Fonts, only if the fonts + are renamed to names not containing either the words "Bitstream" or the word + "Vera". + . + This License becomes null and void to the extent applicable to Fonts or Font + Software that has been modified and is distributed under the "Bitstream + Vera" names. + . + The Font Software may be sold as part of a larger software package but no + copy of one or more of the Font Software typefaces may be sold by itself. + . + THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, + TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME + FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING + ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE + FONT SOFTWARE. + . + Except as contained in this notice, the names of Gnome, the Gnome + Foundation, and Bitstream Inc., shall not be used in advertising or + otherwise to promote the sale, use or other dealings in this Font Software + without prior written authorization from the Gnome Foundation or Bitstream + Inc., respectively. For further information, contact: fonts at gnome dot + org. + +Files: debian/* +Copyright: (C) 2005-2006 Peter Cernak + (C) 2006-2011 Davide Viti + (C) 2011-2013 Christian Perrier + (C) 2013 Fabian Greffrath +License: GPL-2+ + 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; either + version 2 of the License, or (at your option) any later + version. + . + 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 package; if not, write to the Free + Software Foundation, Inc., 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301 USA + . + On Debian systems, the full text of the GNU General Public + License version 2 can be found in the file + /usr/share/common-licenses/GPL-2'. diff --git a/fonts/DejaVuSansMono.ttf b/fonts/DejaVuSansMono.ttf new file mode 100644 index 0000000..37b0269 Binary files /dev/null and b/fonts/DejaVuSansMono.ttf differ diff --git a/locale/en.properties b/locale/en.properties index 63e6c5f..79cd32d 100644 --- a/locale/en.properties +++ b/locale/en.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = Required by: {0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = Dependencies and group purpose mod_manager/hint_collection_dependencies_body = Dependency → the mod that needs it. Card positions and group boundaries do not define load order. A group describes the mod’s purpose in this game; another game may assign it a different role. + +# Bundled mod documentation +mod_manager/documentation = Documentation +mod_manager/docs_auto = Auto · interface language +mod_manager/docs_default = Default +mod_manager/docs_source = Installed version documentation {0} · {1} +mod_manager/docs_installed_notice = A different download version is selected. The guide below belongs to the installed mod. +mod_manager/docs_image_unavailable = Image unavailable +mod_manager/hint_docs_language_title = Documentation language +mod_manager/hint_docs_language_body = Auto follows the interface language. Missing translations fall back to default.md, English, then the first available document. You can select a language manually. diff --git a/locale/es.properties b/locale/es.properties index 9934cce..38ed080 100644 --- a/locale/es.properties +++ b/locale/es.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = Requerido por: {0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = Dependencias y función de los grupos mod_manager/hint_collection_dependencies_body = Dependencia → mod que la necesita. La posición y los grupos no definen el orden de carga. El grupo describe la función del mod en este juego; otro juego puede asignarle otra función. + +# Bundled mod documentation +mod_manager/documentation = Documentación +mod_manager/docs_auto = Auto · idioma de la interfaz +mod_manager/docs_default = Predeterminado +mod_manager/docs_source = Documentación de la versión instalada {0} · {1} +mod_manager/docs_installed_notice = Se ha seleccionado otra versión para descargar. Esta guía corresponde al mod instalado. +mod_manager/docs_image_unavailable = Imagen no disponible +mod_manager/hint_docs_language_title = Idioma de la documentación +mod_manager/hint_docs_language_body = Auto usa el idioma de la interfaz. Si falta una traducción: default.md, inglés y luego el primer documento disponible. También puedes elegir el idioma. diff --git a/locale/ja.properties b/locale/ja.properties index 86b3eaa..ed7c773 100644 --- a/locale/ja.properties +++ b/locale/ja.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = 必要とするMOD:{0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = 依存関係とグループの用途 mod_manager/hint_collection_dependencies_body = 依存先 → それを必要とするMOD。カードの位置やグループの境界は読み込み順を決めません。 グループはこのゲームでのMODの用途です。他のゲームでは異なる役割になり得ます。 + +# Bundled mod documentation +mod_manager/documentation = ドキュメント +mod_manager/docs_auto = 自動 · UIの言語 +mod_manager/docs_default = 既定 +mod_manager/docs_source = インストール済みバージョンの説明 {0} · {1} +mod_manager/docs_installed_notice = 別のダウンロードバージョンが選択されています。以下はインストール済みModのガイドです。 +mod_manager/docs_image_unavailable = 画像を表示できません +mod_manager/hint_docs_language_title = ドキュメントの言語 +mod_manager/hint_docs_language_body = 自動はUIの言語に従います。翻訳がない場合は default.md、英語、最初の文書の順に表示します。手動でも選択できます。 diff --git a/locale/ko.properties b/locale/ko.properties index 92c7fd8..2ba076d 100644 --- a/locale/ko.properties +++ b/locale/ko.properties @@ -318,3 +318,13 @@ mod_manager/collection_used_by = 필요로 하는 모드: {0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = 의존성과 그룹 용도 mod_manager/hint_collection_dependencies_body = 의존 모드 → 이를 필요로 하는 모드. 카드 위치와 그룹 경계는 로드 순서를 정하지 않습니다. 그룹은 이 게임에서 모드의 용도를 설명합니다. 다른 게임에서는 역할이 다를 수 있습니다. + +# Bundled mod documentation +mod_manager/documentation = 문서 +mod_manager/docs_auto = 자동 · 인터페이스 언어 +mod_manager/docs_default = 기본값 +mod_manager/docs_source = 설치된 버전의 문서 {0} · {1} +mod_manager/docs_installed_notice = 다른 다운로드 버전이 선택되었습니다. 아래 안내는 설치된 모드에 해당합니다. +mod_manager/docs_image_unavailable = 이미지를 표시할 수 없음 +mod_manager/hint_docs_language_title = 문서 언어 +mod_manager/hint_docs_language_body = 자동은 인터페이스 언어를 따릅니다. 번역이 없으면 default.md, 영어, 첫 문서 순으로 표시합니다. 직접 언어를 선택할 수도 있습니다. diff --git a/locale/ru.properties b/locale/ru.properties index 5d1a874..b9f9449 100644 --- a/locale/ru.properties +++ b/locale/ru.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = Нужен для: {0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = Зависимости и назначение групп mod_manager/hint_collection_dependencies_body = Зависимость → мод, которому она нужна. Положение карточки и границы групп не задают порядок загрузки. Группа задаёт назначение мода в этой игре; в другой игре его роль может отличаться. + +# Bundled mod documentation +mod_manager/documentation = Документация +mod_manager/docs_auto = Авто · язык интерфейса +mod_manager/docs_default = По умолчанию +mod_manager/docs_source = Документация установленной версии {0} · {1} +mod_manager/docs_installed_notice = Выбрана другая версия для загрузки. Ниже показано руководство установленного мода. +mod_manager/docs_image_unavailable = Изображение недоступно +mod_manager/hint_docs_language_title = Язык документации +mod_manager/hint_docs_language_body = Авто использует язык интерфейса. Если перевода нет: default.md → английский → первый доступный документ. Можно выбрать язык вручную. diff --git a/locale/vi.properties b/locale/vi.properties index 452240b..dce6ef0 100644 --- a/locale/vi.properties +++ b/locale/vi.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = Cần cho: {0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = Phụ thuộc và vai trò nhóm mod_manager/hint_collection_dependencies_body = Phụ thuộc → mod cần nó. Vị trí thẻ và ranh giới nhóm không quyết định thứ tự tải. Nhóm mô tả vai trò của mod trong game này; game khác có thể gán vai trò khác. + +# Bundled mod documentation +mod_manager/documentation = Tài liệu +mod_manager/docs_auto = Tự động · ngôn ngữ giao diện +mod_manager/docs_default = Mặc định +mod_manager/docs_source = Tài liệu phiên bản đã cài {0} · {1} +mod_manager/docs_installed_notice = Đang chọn phiên bản tải xuống khác. Hướng dẫn bên dưới dành cho mod đã cài. +mod_manager/docs_image_unavailable = Không có hình ảnh +mod_manager/hint_docs_language_title = Ngôn ngữ tài liệu +mod_manager/hint_docs_language_body = Tự động dùng ngôn ngữ giao diện. Nếu thiếu bản dịch: default.md, tiếng Anh, rồi tài liệu đầu tiên. Bạn cũng có thể chọn ngôn ngữ thủ công. diff --git a/locale/zh.properties b/locale/zh.properties index 92dd2d7..afe16c0 100644 --- a/locale/zh.properties +++ b/locale/zh.properties @@ -309,3 +309,13 @@ mod_manager/collection_used_by = 被以下模组依赖:{0} mod_manager/collection_other_role = {0} → {1} mod_manager/hint_collection_dependencies_title = 依赖关系与分组用途 mod_manager/hint_collection_dependencies_body = 依赖项 → 使用它的模组。卡片位置和分组边界不决定加载顺序。 分组说明模组在本游戏中的用途;在其他游戏中,它可以有不同的作用。 + +# Bundled mod documentation +mod_manager/documentation = 文档 +mod_manager/docs_auto = 自动 · 界面语言 +mod_manager/docs_default = 默认 +mod_manager/docs_source = 已安装版本的文档 {0} · {1} +mod_manager/docs_installed_notice = 当前选择了其他下载版本。下方指南适用于已安装的模组。 +mod_manager/docs_image_unavailable = 图片不可用 +mod_manager/hint_docs_language_title = 文档语言 +mod_manager/hint_docs_language_body = 自动使用界面语言。缺少翻译时依次使用 default.md、英语、首个可用文档。也可手动选择语言。 diff --git a/manifest.json b/manifest.json index 73b9f29..37482f8 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,7 @@ "sources": [ "src/**/*.cs" ], + "test_sources": ["tests/*.cs"], "depends": ["ui_base>=1"], "main_menu": [ { @@ -17,6 +18,7 @@ } ], "test_suites": [ - { "id": "help", "activate": ["--itest=mod_help"] } + { "id": "help", "activate": ["--itest=mod_help"] }, + { "id": "documentation", "activate": ["--itest=mod_documentation"] } ] } diff --git a/scenes/components/mod_detail_view.tscn b/scenes/components/mod_detail_view.tscn index e9269db..ea7ed43 100644 --- a/scenes/components/mod_detail_view.tscn +++ b/scenes/components/mod_detail_view.tscn @@ -1,6 +1,7 @@ [gd_scene format=3] [ext_resource type="Script" path="src/UI/ModDetailView.cs" id="1_detail"] +[ext_resource type="Script" path="src/UI/ModMarkdownView.cs" id="2_markdown"] [node name="ModDetailView" type="VBoxContainer"] theme_override_constants/separation = 8 @@ -124,6 +125,35 @@ theme_override_font_sizes/font_size = 12 layout_mode = 2 autowrap_mode = 3 +[node name="DocumentationBox" type="VBoxContainer" parent="Scroll/Content"] +visible = false +layout_mode = 2 +theme_override_constants/separation = 10 + +[node name="Header" type="HBoxContainer" parent="Scroll/Content/DocumentationBox"] +layout_mode = 2 +theme_override_constants/separation = 12 + +[node name="Caption" type="Label" parent="Scroll/Content/DocumentationBox/Header"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Languages" type="OptionButton" parent="Scroll/Content/DocumentationBox/Header"] +layout_mode = 2 + +[node name="Source" type="Label" parent="Scroll/Content/DocumentationBox"] +layout_mode = 2 +autowrap_mode = 3 +theme_override_font_sizes/font_size = 12 + +[node name="Body" type="RichTextLabel" parent="Scroll/Content/DocumentationBox"] +layout_mode = 2 +size_flags_horizontal = 3 +fit_content = true +scroll_active = false +selection_enabled = true +script = ExtResource("2_markdown") + [node name="ChangelogBox" type="VBoxContainer" parent="Scroll/Content"] layout_mode = 2 theme_override_constants/separation = 4 diff --git a/source_code/MarkdownDependencies.csproj b/source_code/MarkdownDependencies.csproj new file mode 100644 index 0000000..c670f6b --- /dev/null +++ b/source_code/MarkdownDependencies.csproj @@ -0,0 +1,14 @@ + + + net8.0 + false + + + + + + + + + diff --git a/src/Documentation/ModCodeSyntax.cs b/src/Documentation/ModCodeSyntax.cs new file mode 100644 index 0000000..2995f6a --- /dev/null +++ b/src/Documentation/ModCodeSyntax.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Mods.ModManager +{ + /// + /// Lexical colouring for fenced documentation examples. Follows the site's + /// explicit-language approach and custom scenario/filestree/jsonc rules, + /// returning literal text spans rather than HTML or BBCode. Unknown languages, + /// oversized examples and timeouts retain their complete uncoloured source. + /// + public static class ModCodeSyntax + { + private const string Strings = "(?\"\"\"[\\s\\S]*?\"\"\"|'''[\\s\\S]*?'''|(?:\\$@|@\\$|@)\"(?:\"\"|[^\"])*\"|\\$?\"(?:\\\\.|[^\"\\\\\\r\\n])*\"|'(?:\\\\.|[^'\\\\\\r\\n])*')"; + private const string Tokens = @"(?\b(?:0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)[fFdDmM]?\b)|(?\$\{[^}\r\n]+\}|\$[A-Za-z_]\w*)|(?[A-Za-z_]\w*)|(?[{}\[\](),:;=+*/<>!&|.\-?])"; + private static readonly Regex CStyle = Create(@"(?//[^\r\n]*|/\*[\s\S]*?\*/)|" + Strings + "|" + Tokens); + private static readonly Regex Json = Create(Strings + "|" + Tokens); + private static readonly Regex HashStyle = Create(@"(?\#[^\r\n]*)|" + Strings + "|" + Tokens); + private static readonly Regex Scenario = Create(@"(?^---[ \t]*$)|(?\#[^\r\n]*|--[^\r\n]*)|" + Strings + @"|(?