Skip to content

Commit

Permalink
Add PreviewMarkdown plugin (#1641)
Browse files Browse the repository at this point in the history
* Add PreviewMarkdown plugin (1)

* Add PreviewMarkdown plugin (2)

* Add PreviewMarkdown plugin (3)

* Add PreviewMarkdown plugin (4)

* Add PreviewMarkdown plugin (5)

* Add PreviewMarkdown plugin (6)

* Add PreviewMarkdown plugin (7)

* Add PreviewMarkdown plugin (8)
  • Loading branch information
sdottaka authored Jan 8, 2023
1 parent 54da23b commit cdb3042
Show file tree
Hide file tree
Showing 93 changed files with 727 additions and 345 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
[submodule "Externals/winwebdiff"]
path = Externals/winwebdiff
url = https://github.com/WinMerge/winwebdiff
[submodule "Externals/md4c"]
path = Externals/md4c
url = https://github.com/mity/md4c
7 changes: 6 additions & 1 deletion BuildArc.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if "%1" == "x64" (
)

rem Create folder structure
for %%i in (ColorSchemes Languages\ShellExtension Filters MergePlugins Docs Frhed\Docs Frhed\Languages WinIMerge WinWebDiff Merge7z\Lang Commands\Apache-Tika Commands\tidy-html5 Commands\jq Commands\q Commands\GnuWin32) do (
for %%i in (ColorSchemes Languages\ShellExtension Filters MergePlugins Docs Frhed\Docs Frhed\Languages WinIMerge WinWebDiff Merge7z\Lang Commands\Apache-Tika Commands\tidy-html5 Commands\jq Commands\q Commands\GnuWin32 Commands\md4c) do (
mkdir "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\%%i" 2> NUL
)

Expand Down Expand Up @@ -193,6 +193,11 @@ echo Copy tidy-html5...
copy Build\tidy-html5\bin\tidy.* "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\Commands\tidy-html5\" > NUL
copy Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\Commands\tidy-html5\" > NUL

rem Copy md4c...
echo Copy md4c...
copy Build\md4c\mingw32\bin\*.* "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\Commands\md4c\" > NUL
copy Build\md4c\mingw32\share\licenses\md4c\LICENSE.md "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\Commands\md4c\" > NUL

rem Plugin.xml
copy Plugins\Plugins.xml "%DISTDIR%\%PLATFORMH%zip-version\WinMerge\MergePlugins\" > NUL

Expand Down
64 changes: 59 additions & 5 deletions Docs/Manual/EN/Plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1044,15 +1044,15 @@
</segmentedlist></para>
</section>

<section id="Plugins_VisualizeGraphviz">
<title><filename>VisualizeGraphviz<indexterm>
<primary>VisualizeGraphviz plugin file</primary>
<section id="Plugins_PreviewGraphviz">
<title><filename>PreviewGraphviz<indexterm>
<primary>PreviewGraphviz plugin file</primary>
</indexterm></filename></title>

<para>Graphviz Visualizer</para>
<para>Graphviz Previewer</para>

<cmdsynopsis sepchar=" ">
<command>VisualizeGraphviz</command>
<command>PreviewGraphviz</command>

<arg choice="opt"
rep="repeat"><replaceable>arguments</replaceable></arg>
Expand Down Expand Up @@ -1098,6 +1098,60 @@
</segmentedlist></para>
</section>

<section id="Plugins_PreviewMarkdown">
<title><filename>PreviewMarkdown<indexterm>
<primary>PreviewMarkdown plugin file</primary>
</indexterm></filename></title>

<para>Markdown Previewer</para>

<cmdsynopsis sepchar=" ">
<command>PreviewMarkdown</command>

<arg choice="opt"
rep="repeat"><replaceable>arguments</replaceable></arg>
</cmdsynopsis>

<variablelist>
<varlistentry>
<term><option><replaceable>arguments</replaceable></option></term>
<listitem>
<para>Command line options passed to the md2html command</para>
</listitem>
</varlistentry>
</variablelist>

<para><segmentedlist>
<segtitle>Category</segtitle>

<segtitle>File filter</segtitle>

<segtitle>Plugin arguments</segtitle>

<segtitle>Packing</segtitle>

<segtitle>Settings dialog support</segtitle>

<segtitle>Dependency</segtitle>

<seglistitem>
<seg>Unpacker</seg>

<seg><filename class="extension">*.md</filename>,
<filename class="extension">,*.markdown</filename>
</seg>

<seg>Yes</seg>

<seg>No</seg>

<seg>No</seg>

<seg><ulink url="https://github.com/mity/md4c">md4c</ulink></seg>
</seglistitem>
</segmentedlist></para>
</section>

<section id="Plugins_ApacheTika">
<title><filename>ApacheTika<indexterm>
<primary>ApacheTika plugin file</primary>
Expand Down
62 changes: 58 additions & 4 deletions Docs/Manual/JP/Plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,15 +1042,15 @@
</segmentedlist></para>
</section>

<section id="Plugins_VisualizeGraphviz">
<title><filename>VisualizeGraphviz<indexterm>
<primary>VisualizeGraphviz plugin file</primary>
<section id="Plugins_PreviewGraphviz">
<title><filename>PreviewGraphviz<indexterm>
<primary>PreviewGraphviz plugin file</primary>
</indexterm></filename></title>

<para>Graphviz ファイルを画像化します。</para>

<cmdsynopsis sepchar=" ">
<command>VisualizeGraphviz</command>
<command>PreviewGraphviz</command>

<arg choice="opt"
rep="repeat"><replaceable>arguments</replaceable></arg>
Expand Down Expand Up @@ -1096,6 +1096,60 @@
</segmentedlist></para>
</section>

<section id="Plugins_PreviewMarkdown">
<title><filename>PreviewMarkdown<indexterm>
<primary>PreviewMarkdown plugin file</primary>
</indexterm></filename></title>

<para>Markdown ファイルをHTMLに変換して表示します。</para>

<cmdsynopsis sepchar=" ">
<command>PreviewMarkdown</command>

<arg choice="opt"
rep="repeat"><replaceable>arguments</replaceable></arg>
</cmdsynopsis>

<variablelist>
<varlistentry>
<term><option><replaceable>arguments</replaceable></option></term>
<listitem>
<para>md2html コマンドに渡すコマンドラインオプション。</para>
</listitem>
</varlistentry>
</variablelist>

<para><segmentedlist>
<segtitle>分類</segtitle>

<segtitle>ファイルフィルター</segtitle>

<segtitle>プラグイン引数</segtitle>

<segtitle>書き戻し</segtitle>

<segtitle>設定ダイアログサポート</segtitle>

<segtitle>依存するもの</segtitle>

<seglistitem>
<seg>展開プラグイン</seg>

<seg><filename class="extension">*.md</filename>,
<filename class="extension">,*.markdown</filename>
</seg>

<seg>Yes</seg>

<seg>No</seg>

<seg>No</seg>

<seg><ulink url="https://github.com/mity/md4c">md4c</ulink></seg>
</seglistitem>
</segmentedlist></para>
</section>

<section id="Plugins_ApacheTika">
<title><filename>ApacheTika<indexterm>
<primary>ApacheTika plugin file</primary>
Expand Down
12 changes: 11 additions & 1 deletion DownloadDeps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ https://github.com/htacg/tidy-html5/releases/download/5.4.0/tidy-5.4.0-w32-mt-XP
https://github.com/htacg/tidy-html5/archive/refs/tags/5.4.0.zip!Build\tidy-html5 ^
https://github.com/stedolan/jq/releases/download/jq-1.4/jq-win32.exe!Build\jq ^
https://github.com/stedolan/jq/archive/refs/tags/jq-1.4.zip!Build\jq ^
https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-v1.5.2-win64.zip!Build\zstd ^
https://mirror.msys2.org/mingw/mingw32/mingw-w64-i686-md4c-0.4.8-2-any.pkg.tar.zst!Build\md4c ^
http://www.magicnotes.com/steelbytes/SBAppLocale_ENG.zip!Docs\Manual\Tools

pushd "%~dp0"
Expand All @@ -46,7 +48,11 @@ for %%p in (%urls_destdirs%) do (
7z x %downloadsdir%\%%~nxu -aoa -o%%v
) else (
mkdir %%v > NUL
copy %downloadsdir%\%%~nxu %%v
if "%%~xu" == ".zst" (
Build\zstd\zstd-v1.5.2-win64\zstd.exe -dc %downloadsdir%\%%~nxu | tar xf - -C %%v
) else (
copy %downloadsdir%\%%~nxu %%v
)
)
)
)
Expand All @@ -65,6 +71,7 @@ for %%i in (x86 x64 ARM ARM64) do (
mkdir Build\%%i\%%j\Commands\jq 2> NUL
mkdir Build\%%i\%%j\Commands\tidy-html5 2> NUL
mkdir Build\%%i\%%j\Commands\GnuWin32 2> NUL
mkdir Build\%%i\%%j\Commands\md4c 2> NUL
xcopy /s/y Build\%%i\Release\Merge7z Build\%%i\%%j\Merge7z\
xcopy /s/y Build\%%i\Release\Frhed Build\%%i\%%j\Frhed\
copy Build\%%i\Release\WinIMerge\WinIMergeLib.dll Build\%%i\%%j\WinIMerge\
Expand All @@ -74,6 +81,9 @@ for %%i in (x86 x64 ARM ARM64) do (
copy Build\jq\jq-jq-1.4\COPYING Build\%%i\%%j\Commands\jq\
copy Build\tidy-html5\bin\tidy.* Build\%%i\%%j\Commands\tidy-html5\
copy Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md Build\%%i\%%j\Commands\tidy-html5\
copy Build\md4c\mingw32\bin\*.exe Build\%%i\%%j\Commands\md4c\
copy Build\md4c\mingw32\bin\*.dll Build\%%i\%%j\Commands\md4c\
copy Build\md4c\mingw32\share\licenses\md4c\LICENSE.md Build\%%i\%%j\Commands\md4c\
xcopy /s/y Plugins\Commands Build\%%i\%%j\Commands
xcopy /s/y Filters Build\%%i\%%j\Filters\
xcopy /s/y ColorSchemes Build\%%i\%%j\ColorSchemes\
Expand Down
1 change: 1 addition & 0 deletions Externals/md4c
Submodule md4c added at c3340b
1 change: 1 addition & 0 deletions Externals/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ This file lists versions of the external components we are using.
- html-tidy5: 5.4.0
- jq: 1.4
- wil: 209ff9c7e30e71bf6d1405557bf78544920f8157 on Sep 9, 2021
- md4c: 0.4.8
4 changes: 4 additions & 0 deletions Installer/InnoSetup/WinMergeARM64.is6.iss
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@ Source: ..\..\Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md; DestDir: {app
; jq
Source: ..\..\Build\jq\jq-win32.exe; DestDir: {app}\Commands\jq; DestName: jq.exe; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\jq\jq-jq-1.4\COPYING; DestDir: {app}\Commands\jq; Flags: recursesubdirs; Components: Commands
; md4c
Source: ..\..\Build\md4c\mingw32\bin\*.*; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\md4c\mingw32\share\licenses\md4c\LICENSE.md; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\md4c\*.bat; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
; Apache Tika
Source: ..\..\Plugins\Commands\Apache-Tika\*.bat; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\Apache-Tika\*.txt; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Expand Down
4 changes: 4 additions & 0 deletions Installer/InnoSetup/WinMergeX64.is6.iss
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ Source: ..\..\Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md; DestDir: {app
; jq
Source: ..\..\Build\jq\jq-win32.exe; DestDir: {app}\Commands\jq; DestName: jq.exe; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\jq\jq-jq-1.4\COPYING; DestDir: {app}\Commands\jq; Flags: recursesubdirs; Components: Commands
; md4c
Source: ..\..\Build\md4c\mingw32\bin\*.*; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\md4c\mingw32\share\licenses\md4c\LICENSE.md; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\md4c\*.bat; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
; Apache Tika
Source: ..\..\Plugins\Commands\Apache-Tika\*.bat; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\Apache-Tika\*.txt; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Expand Down
4 changes: 4 additions & 0 deletions Installer/InnoSetup/WinMergeX64.iss
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ Source: ..\..\Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md; DestDir: {app
; jq
Source: ..\..\Build\jq\jq-win32.exe; DestDir: {app}\Commands\jq; DestName: jq.exe; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\jq\jq-jq-1.4\COPYING; DestDir: {app}\Commands\jq; Flags: recursesubdirs; Components: Commands
; md4c
Source: ..\..\Build\md4c\mingw32\bin\*.*; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\md4c\mingw32\share\licenses\md4c\LICENSE.md; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\md4c\*.bat; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
; Apache Tika
Source: ..\..\Plugins\Commands\Apache-Tika\*.bat; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\Apache-Tika\*.txt; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Expand Down
4 changes: 4 additions & 0 deletions Installer/InnoSetup/WinMergeX64NonAdmin.iss
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ Source: ..\..\Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md; DestDir: {app
; jq
Source: ..\..\Build\jq\jq-win32.exe; DestDir: {app}\Commands\jq; DestName: jq.exe; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\jq\jq-jq-1.4\COPYING; DestDir: {app}\Commands\jq; Flags: recursesubdirs; Components: Commands
; md4c
Source: ..\..\Build\md4c\mingw32\bin\*.*; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\md4c\mingw32\share\licenses\md4c\LICENSE.md; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\md4c\*.bat; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
; Apache Tika
Source: ..\..\Plugins\Commands\Apache-Tika\*.bat; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\Apache-Tika\*.txt; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Expand Down
4 changes: 4 additions & 0 deletions Installer/InnoSetup/WinMergeX86.iss
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ Source: ..\..\Build\tidy-html5\tidy-html5-5.4.0\README\LICENSE.md; DestDir: {app
; jq
Source: ..\..\Build\jq\jq-win32.exe; DestDir: {app}\Commands\jq; DestName: jq.exe; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\jq\jq-jq-1.4\COPYING; DestDir: {app}\Commands\jq; Flags: recursesubdirs; Components: Commands
; md4c
Source: ..\..\Build\md4c\mingw32\bin\*.*; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Build\md4c\mingw32\share\licenses\md4c\LICENSE.md; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\md4c\*.bat; DestDir: {app}\Commands\md4c; Flags: recursesubdirs; Components: Commands
; Apache Tika
Source: ..\..\Plugins\Commands\Apache-Tika\*.bat; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Source: ..\..\Plugins\Commands\Apache-Tika\*.txt; DestDir: {app}\Commands\Apache-Tika; Flags: recursesubdirs; Components: Commands
Expand Down
12 changes: 12 additions & 0 deletions Plugins/Commands/md4c/md2html.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off
echo ^<!DOCTYPE html^>
echo ^<html^>
echo ^<head^>
echo ^<title^>^</title^>
echo ^<meta name="generator" content="md2html"^>
echo ^<base href="file:///%~dp1"^>
echo ^</head^>
echo ^<body^>
type %1 | "%~dp0\md2html.exe" %2 %3 %4 %5 %6 %7 %8 %9
echo ^</body^>
echo ^</html^>
18 changes: 15 additions & 3 deletions Plugins/Plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,30 @@
<command>cmd /c type "${SRC_FILE}" | "${WINMERGE_HOME}\Commands\tidy-html5\tidy.exe" ${*} 2> "${DST_FILE}" | exit 0</command>
</unpack-file>
</plugin>
<plugin name="VisualizeGraphviz">
<plugin name="PreviewGraphviz">
<event value="FILE_PACK_UNPACK" />
<description value="Graphviz Visualizer. &#xD;&#xA;Arguments: Command line options passed to the dot command." />
<description value="Graphviz Previewer. &#xD;&#xA;Arguments: Command line options passed to the dot command." />
<file-filters value="\.gv;$\.dot$" />
<is-automatic value="false" />
<unpacked-file-extension value=".png" />
<extended-properties value="ProcessType=Visualization;MenuCaption=Visualize Graphviz" />
<extended-properties value="ProcessType=Preview;MenuCaption=Preview Graphviz;PreferredWindowType=Image" />
<arguments value="-Tpng" />
<unpack-file>
<command>dot.exe ${*} -o"${DST_FILE}" "${SRC_FILE}"</command>
</unpack-file>
</plugin>
<plugin name="PreviewMarkdown">
<event value="FILE_PACK_UNPACK" />
<description value="Markdown Previewer. &#xD;&#xA;Arguments: Command line options passed to the md2html command." />
<file-filters value="\.md$;\.markdown$" />
<is-automatic value="false" />
<unpacked-file-extension value=".html" />
<extended-properties value="ProcessType=Preview;MenuCaption=Preview Markdown;PreferredWindowType=Webpage" />
<arguments value="" />
<unpack-file>
<command>"${WINMERGE_HOME}\Commands\md4c\md2html.bat" "${SRC_FILE}" ${*} > "${DST_FILE}"</command>
</unpack-file>
</plugin>
<plugin name="ApacheTika">
<event value="FILE_PACK_UNPACK" />
<description value="General content extractor with Apache Tika. &#xD;&#xA;Arguments: Command line options passed to the tika-app.jar." />
Expand Down
25 changes: 24 additions & 1 deletion Src/FileTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ bool PackingInfo::pack(String & filepath, const String& dstFilepath, const std::
return false;
}

if (m_bWebBrowser && m_PluginPipeline.empty())
return true;

auto itSubcode = handlerSubcodes.rbegin();
for (auto& [plugin, args, bWithFile] : plugins)
{
Expand Down Expand Up @@ -411,6 +414,9 @@ bool PackingInfo::Unpacking(std::vector<int> * handlerSubcodes, String & filepat
return false;
}

if (m_bWebBrowser && m_PluginPipeline.empty())
return true;

for (auto& [plugin, args, bWithFile] : plugins)
{
bool bHandled = false;
Expand Down Expand Up @@ -475,15 +481,32 @@ bool PackingInfo::Unpacking(std::vector<int> * handlerSubcodes, String & filepat
return true;
}

String PackingInfo::GetUnpackedFileExtension(const String& filteredFilenames) const
String PackingInfo::GetUnpackedFileExtension(const String& filteredFilenames, int& preferredWindowType) const
{
preferredWindowType = -1;
String ext;
String errorMessage;
std::vector<std::tuple<PluginInfo*, std::vector<String>, bool>> plugins;
if (GetPackUnpackPlugin(filteredFilenames, false, false, plugins, nullptr, nullptr, errorMessage))
{
for (auto& [plugin, args, bWithFile] : plugins)
{
ext += plugin->m_ext;
auto preferredWindowTypeStr = plugin->GetExtendedPropertyValue(_T("PreferredWindowType"));
if (preferredWindowTypeStr.has_value())
{
if (preferredWindowTypeStr == L"Text")
preferredWindowType = 0;
else if (preferredWindowTypeStr == L"Table")
preferredWindowType = 1;
else if (preferredWindowTypeStr == L"Binary")
preferredWindowType = 2;
else if (preferredWindowTypeStr == L"Image")
preferredWindowType = 3;
else if (preferredWindowTypeStr == L"Webpage")
preferredWindowType = 4;
}
}
}
return ext;
}
Expand Down
Loading

0 comments on commit cdb3042

Please sign in to comment.