feat: 初期コミット(Markdownからダッシュボード風HTMLへの変換ツール)
This commit is contained in:
commit
e166525cb8
8 files changed
+1948
No files matched your search
+482
@@ -0,0 +1,482 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from `dotnet new gitignore`
|
||||||
|
|
||||||
|
# dotenv files
|
||||||
|
.env
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# Tye
|
||||||
|
.tye/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
# but not Directory.Build.rsp, as it configures directory-level build defaults
|
||||||
|
!Directory.Build.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
*.ncb
|
||||||
|
*.aps
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
##
|
||||||
|
## Visual studio for Mac
|
||||||
|
##
|
||||||
|
|
||||||
|
|
||||||
|
# globs
|
||||||
|
Makefile.in
|
||||||
|
*.userprefs
|
||||||
|
*.usertasks
|
||||||
|
config.make
|
||||||
|
config.status
|
||||||
|
aclocal.m4
|
||||||
|
install-sh
|
||||||
|
autom4te.cache/
|
||||||
|
*.tar.gz
|
||||||
|
tarballs/
|
||||||
|
test-results/
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
# Vim temporary swap files
|
||||||
|
*.swp
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<Solution>
|
||||||
|
<Project Path="MdToHtmlDashboard/MdToHtmlDashboard.csproj" />
|
||||||
|
</Solution>
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using HtmlAgilityPack;
|
||||||
|
using Markdig;
|
||||||
|
using MdToHtmlDashboard.Templates;
|
||||||
|
|
||||||
|
namespace MdToHtmlDashboard.Converter;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Markdown文字列を解析し、インタラクティブ機能付きの完全自己完結HTMLへ変換するコンバーター
|
||||||
|
/// </summary>
|
||||||
|
public class MarkdownConverter
|
||||||
|
{
|
||||||
|
private readonly MarkdownPipeline _pipeline;
|
||||||
|
|
||||||
|
public MarkdownConverter()
|
||||||
|
{
|
||||||
|
// Markdig 高度拡張パイプライン(パイプテーブル、タスクリスト、コードブロック等)
|
||||||
|
_pipeline = new MarkdownPipelineBuilder()
|
||||||
|
.UseAdvancedExtensions()
|
||||||
|
.UseEmojiAndSmiley()
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Markdownファイルを読み込み、インタラクティブHTMLを生成して保存します
|
||||||
|
/// </summary>
|
||||||
|
public string ConvertFile(string markdownFilePath, string? outputHtmlPath = null)
|
||||||
|
{
|
||||||
|
if (!File.Exists(markdownFilePath))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException($"Markdownファイルが見つかりません: {markdownFilePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
outputHtmlPath ??= Path.ChangeExtension(markdownFilePath, ".html");
|
||||||
|
|
||||||
|
var markdownContent = File.ReadAllText(markdownFilePath, Encoding.UTF8);
|
||||||
|
var html = ConvertText(markdownContent, Path.GetFileNameWithoutExtension(markdownFilePath));
|
||||||
|
|
||||||
|
File.WriteAllText(outputHtmlPath, html, new UTF8Encoding(true));
|
||||||
|
return outputHtmlPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// MarkdownテキストをインタラクティブHTMLに変換します
|
||||||
|
/// </summary>
|
||||||
|
public string ConvertText(string markdownContent, string defaultTitle = "ドキュメント")
|
||||||
|
{
|
||||||
|
// 1. Markdig による基本HTML変換
|
||||||
|
var rawHtml = Markdown.ToHtml(markdownContent, _pipeline);
|
||||||
|
|
||||||
|
// 2. HtmlAgilityPack によるDOM解析・エンリッチメント
|
||||||
|
var doc = new HtmlDocument();
|
||||||
|
doc.LoadHtml(rawHtml);
|
||||||
|
|
||||||
|
var title = defaultTitle;
|
||||||
|
var subtitle = "";
|
||||||
|
|
||||||
|
// タイトル抽出(最初のH1)
|
||||||
|
var firstH1 = doc.DocumentNode.SelectSingleNode("//h1");
|
||||||
|
if (firstH1 != null)
|
||||||
|
{
|
||||||
|
title = firstH1.InnerText.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 目次(TOC)抽出と見出しへのID付与
|
||||||
|
var tocHtml = BuildTableOfContents(doc);
|
||||||
|
|
||||||
|
// テーブルの拡張(レスポンシブラッパーの追加)
|
||||||
|
EnrichTables(doc);
|
||||||
|
|
||||||
|
// コードブロックの拡張(コピーボタン、言語ヘッダー、diffハイライト)
|
||||||
|
EnrichCodeBlocks(doc);
|
||||||
|
|
||||||
|
// ファイルパス・リンクの拡張(コピーボタン付与)
|
||||||
|
EnrichLinksAndPaths(doc);
|
||||||
|
|
||||||
|
// H2セクションの安全なアコーディオン構造化(線形再構築)
|
||||||
|
EnrichSections(doc);
|
||||||
|
|
||||||
|
var bodyHtml = doc.DocumentNode.OuterHtml;
|
||||||
|
|
||||||
|
// 3. テンプレートへ統合
|
||||||
|
return HtmlTemplate.Render(title, subtitle, bodyHtml, tocHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 見出しから目次(TOC)ツリーを生成し、見出し要素にアンカーIDを付与します
|
||||||
|
/// </summary>
|
||||||
|
private string BuildTableOfContents(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
var headings = doc.DocumentNode.SelectNodes("//h1 | //h2 | //h3 | //h4");
|
||||||
|
if (headings == null || headings.Count == 0)
|
||||||
|
{
|
||||||
|
return "<p style=\"color: #94a3b8; font-size: 13px;\">目次項目はありません</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.AppendLine("<ul>");
|
||||||
|
int index = 1;
|
||||||
|
|
||||||
|
foreach (var h in headings)
|
||||||
|
{
|
||||||
|
var level = int.Parse(h.Name.Substring(1));
|
||||||
|
var text = h.InnerText.Trim();
|
||||||
|
if (string.IsNullOrWhiteSpace(text)) continue;
|
||||||
|
|
||||||
|
var anchorId = $"heading-{index++}";
|
||||||
|
h.SetAttributeValue("id", anchorId);
|
||||||
|
|
||||||
|
var indent = (level - 1) * 12;
|
||||||
|
sb.AppendLine($" <li style=\"padding-left: {indent}px;\"><a href=\"#{anchorId}\" onclick=\"if(window.innerWidth<=992)toggleSidebar(false);\">{System.Net.WebUtility.HtmlEncode(text)}</a></li>");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine("</ul>");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// テーブル要素を横スクロールラッパーで囲みます
|
||||||
|
/// </summary>
|
||||||
|
private void EnrichTables(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
var tables = doc.DocumentNode.SelectNodes("//table");
|
||||||
|
if (tables == null) return;
|
||||||
|
|
||||||
|
foreach (var table in tables)
|
||||||
|
{
|
||||||
|
var parent = table.ParentNode;
|
||||||
|
if (parent == null) continue;
|
||||||
|
|
||||||
|
var wrapper = doc.CreateElement("div");
|
||||||
|
wrapper.SetAttributeValue("class", "table-container");
|
||||||
|
|
||||||
|
parent.ReplaceChild(wrapper, table);
|
||||||
|
wrapper.AppendChild(table);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// コードブロックにコピーボタンと言語表示ヘッダーを付与し、diffブロックをハイライトします
|
||||||
|
/// </summary>
|
||||||
|
private void EnrichCodeBlocks(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
var preNodes = doc.DocumentNode.SelectNodes("//pre");
|
||||||
|
if (preNodes == null) return;
|
||||||
|
|
||||||
|
foreach (var pre in preNodes)
|
||||||
|
{
|
||||||
|
var parent = pre.ParentNode;
|
||||||
|
if (parent == null) continue;
|
||||||
|
|
||||||
|
var codeNode = pre.SelectSingleNode("code");
|
||||||
|
var lang = "code";
|
||||||
|
|
||||||
|
if (codeNode != null)
|
||||||
|
{
|
||||||
|
var classAttr = codeNode.GetAttributeValue("class", "");
|
||||||
|
var match = Regex.Match(classAttr, @"language-([\w-]+)");
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
lang = match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// diff コードブロックの行ハイライト
|
||||||
|
if (lang.Equals("diff", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
HighlightDiff(codeNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var container = doc.CreateElement("div");
|
||||||
|
container.SetAttributeValue("class", "code-container");
|
||||||
|
|
||||||
|
var header = doc.CreateElement("div");
|
||||||
|
header.SetAttributeValue("class", "code-header");
|
||||||
|
header.InnerHtml = $"<span>{System.Net.WebUtility.HtmlEncode(lang)}</span><button class=\"code-copy-btn\" onclick=\"copyPreCode(this)\">📋 コピー</button>";
|
||||||
|
|
||||||
|
container.AppendChild(header);
|
||||||
|
|
||||||
|
parent.ReplaceChild(container, pre);
|
||||||
|
container.AppendChild(pre);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// diff 内の行頭 + / - をクラス付けしてハイライトします
|
||||||
|
/// </summary>
|
||||||
|
private void HighlightDiff(HtmlNode codeNode)
|
||||||
|
{
|
||||||
|
var rawText = codeNode.InnerText;
|
||||||
|
var lines = rawText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var trimmed = line.TrimStart();
|
||||||
|
if (trimmed.StartsWith("+") && !trimmed.StartsWith("+++"))
|
||||||
|
{
|
||||||
|
sb.AppendLine($"<span class=\"diff-add\">{System.Net.WebUtility.HtmlEncode(line)}</span>");
|
||||||
|
}
|
||||||
|
else if (trimmed.StartsWith("-") && !trimmed.StartsWith("---"))
|
||||||
|
{
|
||||||
|
sb.AppendLine($"<span class=\"diff-del\">{System.Net.WebUtility.HtmlEncode(line)}</span>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.AppendLine(System.Net.WebUtility.HtmlEncode(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
codeNode.InnerHtml = sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ファイルリンクや file:/// 形式のリンクを拡張し、パスコピー機能を提供します
|
||||||
|
/// </summary>
|
||||||
|
private void EnrichLinksAndPaths(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
var links = doc.DocumentNode.SelectNodes("//a[@href]");
|
||||||
|
if (links == null) return;
|
||||||
|
|
||||||
|
foreach (var a in links)
|
||||||
|
{
|
||||||
|
var href = a.GetAttributeValue("href", "");
|
||||||
|
if (href.StartsWith("file:///") || href.EndsWith(".aspx") || href.EndsWith(".vb") || href.EndsWith(".cs") || href.EndsWith(".md"))
|
||||||
|
{
|
||||||
|
var parent = a.ParentNode;
|
||||||
|
if (parent == null) continue;
|
||||||
|
|
||||||
|
var cleanPath = href.Replace("file:///", "").TrimStart('/');
|
||||||
|
var badge = doc.CreateElement("span");
|
||||||
|
badge.SetAttributeValue("class", "file-path-badge");
|
||||||
|
badge.InnerHtml = $"<button class=\"badge-copy-btn\" onclick=\"copyText('{cleanPath.Replace("\\", "\\\\")}')\" title=\"パスをコピー\">📋</button>";
|
||||||
|
|
||||||
|
parent.InsertAfter(badge, a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// H2見出し単位で安全に details/summary セクションを線形再構築します(重複バグの完全解消)
|
||||||
|
/// </summary>
|
||||||
|
private void EnrichSections(HtmlDocument doc)
|
||||||
|
{
|
||||||
|
var nodes = doc.DocumentNode.ChildNodes.ToList();
|
||||||
|
if (nodes.Count == 0) return;
|
||||||
|
|
||||||
|
var newContainer = doc.CreateElement("div");
|
||||||
|
newContainer.SetAttributeValue("class", "doc-flow");
|
||||||
|
|
||||||
|
HtmlNode? currentSectionContent = null;
|
||||||
|
HtmlNode? introContainer = null;
|
||||||
|
|
||||||
|
foreach (var node in nodes)
|
||||||
|
{
|
||||||
|
// 空白テキストノードの無視
|
||||||
|
if (node.NodeType == HtmlNodeType.Text && string.IsNullOrWhiteSpace(node.InnerText))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.Name.Equals("h2", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// 新しい H2 セクション開始
|
||||||
|
var details = doc.CreateElement("details");
|
||||||
|
details.SetAttributeValue("class", "doc-section");
|
||||||
|
details.SetAttributeValue("open", "open"); // デフォルト展開
|
||||||
|
|
||||||
|
var summary = doc.CreateElement("summary");
|
||||||
|
summary.SetAttributeValue("class", "doc-section-header");
|
||||||
|
summary.AppendChild(node.CloneNode(true));
|
||||||
|
|
||||||
|
currentSectionContent = doc.CreateElement("div");
|
||||||
|
currentSectionContent.SetAttributeValue("class", "doc-section-content");
|
||||||
|
|
||||||
|
details.AppendChild(summary);
|
||||||
|
details.AppendChild(currentSectionContent);
|
||||||
|
|
||||||
|
newContainer.AppendChild(details);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (currentSectionContent != null)
|
||||||
|
{
|
||||||
|
// 既存セクションの中に追加
|
||||||
|
currentSectionContent.AppendChild(node.CloneNode(true));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 最初の H2 が来る前のイントロ要素群
|
||||||
|
if (introContainer == null)
|
||||||
|
{
|
||||||
|
introContainer = doc.CreateElement("div");
|
||||||
|
introContainer.SetAttributeValue("class", "doc-intro");
|
||||||
|
newContainer.AppendChild(introContainer);
|
||||||
|
}
|
||||||
|
introContainer.AppendChild(node.CloneNode(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doc.DocumentNode.RemoveAllChildren();
|
||||||
|
foreach (var child in newContainer.ChildNodes)
|
||||||
|
{
|
||||||
|
doc.DocumentNode.AppendChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HtmlAgilityPack" Version="1.13.0" />
|
||||||
|
<PackageReference Include="Markdig" Version="1.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using MdToHtmlDashboard.Converter;
|
||||||
|
|
||||||
|
namespace MdToHtmlDashboard;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
private static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.OutputEncoding = Encoding.UTF8;
|
||||||
|
Console.WriteLine("=================================================================");
|
||||||
|
Console.WriteLine(" MdToHtmlDashboard - 汎用Markdown インタラクティブHTML変換ツール");
|
||||||
|
Console.WriteLine("=================================================================");
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
var converter = new MarkdownConverter();
|
||||||
|
|
||||||
|
// 引数なし(ダブルクリック時など)の処理
|
||||||
|
if (args.Length == 0)
|
||||||
|
{
|
||||||
|
HandleInteractiveMode(converter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// コマンドライン引数 / ドラッグ&ドロップ時の処理
|
||||||
|
var openBrowser = true;
|
||||||
|
var filesToProcess = new List<string>();
|
||||||
|
string? specifiedOutput = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
var arg = args[i];
|
||||||
|
if (arg.Equals("--no-open", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
openBrowser = false;
|
||||||
|
}
|
||||||
|
else if (arg.Equals("-o", StringComparison.OrdinalIgnoreCase) && i + 1 < args.Length)
|
||||||
|
{
|
||||||
|
specifiedOutput = args[++i];
|
||||||
|
}
|
||||||
|
else if (Directory.Exists(arg))
|
||||||
|
{
|
||||||
|
var mdFiles = Directory.GetFiles(arg, "*.md", SearchOption.AllDirectories);
|
||||||
|
filesToProcess.AddRange(mdFiles);
|
||||||
|
}
|
||||||
|
else if (File.Exists(arg))
|
||||||
|
{
|
||||||
|
filesToProcess.Add(arg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine($"[警告] 指定されたファイルまたはフォルダが見つかりません: {arg}");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filesToProcess.Count == 0)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[エラー] 変換対象のMarkdownファイル(.md)が指定されていません。");
|
||||||
|
Console.ResetColor();
|
||||||
|
ShowUsage();
|
||||||
|
WaitForKey();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? lastGeneratedHtml = null;
|
||||||
|
|
||||||
|
foreach (var mdPath in filesToProcess)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write($"変換中: {Path.GetFileName(mdPath)} ... ");
|
||||||
|
var outputPath = (filesToProcess.Count == 1 && !string.IsNullOrWhiteSpace(specifiedOutput))
|
||||||
|
? specifiedOutput
|
||||||
|
: null;
|
||||||
|
|
||||||
|
var resultHtml = converter.ConvertFile(mdPath, outputPath);
|
||||||
|
lastGeneratedHtml = resultHtml;
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine($"成功 -> {Path.GetFileName(resultHtml)}");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.WriteLine($" 出力先: {resultHtml}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"失敗 ({ex.Message})");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine($"[完了] 合計 {filesToProcess.Count} 件の処理が完了しました。");
|
||||||
|
Console.ResetColor();
|
||||||
|
|
||||||
|
// 1件のみ変換した場合はブラウザで自動表示
|
||||||
|
if (openBrowser && filesToProcess.Count == 1 && !string.IsNullOrWhiteSpace(lastGeneratedHtml))
|
||||||
|
{
|
||||||
|
OpenInBrowser(lastGeneratedHtml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ダブルクリック時などの対話処理
|
||||||
|
/// </summary>
|
||||||
|
private static void HandleInteractiveMode(MarkdownConverter converter)
|
||||||
|
{
|
||||||
|
Console.WriteLine("ファイル選択ダイアログを開いています...");
|
||||||
|
Console.WriteLine("(変換したい Markdown ファイルを選択してください)");
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
var targetMd = OpenFileDialog();
|
||||||
|
|
||||||
|
// ダイアログでキャンセルされた場合のフォールバックメニュー
|
||||||
|
if (string.IsNullOrWhiteSpace(targetMd))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("ファイル選択ダイアログでファイルが選択されませんでした。");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("【その他の選択方法】");
|
||||||
|
|
||||||
|
var currentDirMds = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.md");
|
||||||
|
if (currentDirMds.Length > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("このフォルダ内のファイル一覧:");
|
||||||
|
for (int i = 0; i < currentDirMds.Length; i++)
|
||||||
|
{
|
||||||
|
Console.WriteLine($" [{i + 1}] {Path.GetFileName(currentDirMds[i])}");
|
||||||
|
}
|
||||||
|
Console.Write($"番号を選択するか、ファイルパスを入力してください (1-{currentDirMds.Length}): ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.Write("Markdownファイル(.md)のパスを入力するか、この画面にドラッグ&ドロップしてください: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
var input = Console.ReadLine()?.Trim('"', ' ');
|
||||||
|
if (!string.IsNullOrWhiteSpace(input))
|
||||||
|
{
|
||||||
|
if (int.TryParse(input, out int sel) && sel >= 1 && sel <= currentDirMds.Length)
|
||||||
|
{
|
||||||
|
targetMd = currentDirMds[sel - 1];
|
||||||
|
}
|
||||||
|
else if (File.Exists(input))
|
||||||
|
{
|
||||||
|
targetMd = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(targetMd) || !File.Exists(targetMd))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("有効なファイルが指定されなかったため、処理を終了します。");
|
||||||
|
Console.ResetColor();
|
||||||
|
WaitForKey();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.Write($"変換中: {Path.GetFileName(targetMd)} ... ");
|
||||||
|
var output = converter.ConvertFile(targetMd);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine($"[成功]");
|
||||||
|
Console.ResetColor();
|
||||||
|
Console.WriteLine($"出力ファイル: {output}");
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
OpenInBrowser(output);
|
||||||
|
|
||||||
|
WaitForKey();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"[エラー] 変換に失敗しました: {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
WaitForKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// PowerShell を介して Windows 標準のファイル選択ダイアログ(GUI)を表示
|
||||||
|
/// </summary>
|
||||||
|
private static string? OpenFileDialog()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "powershell",
|
||||||
|
Arguments = "-NoProfile -Command \"Add-Type -AssemblyName System.Windows.Forms; $f = New-Object System.Windows.Forms.OpenFileDialog; $f.Filter = 'Markdown Files (*.md)|*.md|All Files (*.*)|*.*'; $f.Title = '変換するMarkdownファイルを選択してください'; if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { Write-Output $f.FileName }\"",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
CreateNoWindow = true
|
||||||
|
};
|
||||||
|
using var process = Process.Start(psi);
|
||||||
|
if (process != null)
|
||||||
|
{
|
||||||
|
var output = process.StandardOutput.ReadToEnd().Trim();
|
||||||
|
process.WaitForExit();
|
||||||
|
if (!string.IsNullOrWhiteSpace(output) && File.Exists(output))
|
||||||
|
{
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ダイアログ起動エラー: {ex.Message}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OpenInBrowser(string htmlPath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = htmlPath,
|
||||||
|
UseShellExecute = true
|
||||||
|
};
|
||||||
|
Process.Start(psi);
|
||||||
|
Console.WriteLine("ブラウザで開きました。");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"ブラウザの起動に失敗しました: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WaitForKey()
|
||||||
|
{
|
||||||
|
Console.WriteLine("何かキーを押すと終了します...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Console.IsInputRedirected)
|
||||||
|
{
|
||||||
|
Console.ReadKey(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ReadLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ShowUsage()
|
||||||
|
{
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine("【使用方法】");
|
||||||
|
Console.WriteLine(" 1. ドラッグ&ドロップ:");
|
||||||
|
Console.WriteLine(" .md ファイルを「ドラッグ&ドロップでHTML変換.bat」に重ねてドロップ");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(" 2. ダブルクリック:");
|
||||||
|
Console.WriteLine(" 「ドラッグ&ドロップでHTML変換.bat」をダブルクリック -> ファイル選択ダイアログが開きます");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine(" 3. コマンドライン実行:");
|
||||||
|
Console.WriteLine(" MdToHtmlDashboard.exe <markdown_file.md>");
|
||||||
|
Console.WriteLine(" MdToHtmlDashboard.exe <markdown_file.md> -o <output.html>");
|
||||||
|
Console.WriteLine(" MdToHtmlDashboard.exe <folder_path> (フォルダ内を一括変換)");
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,775 @@
|
|||||||
|
namespace MdToHtmlDashboard.Templates;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 完全自己完結型インタラクティブHTMLを生成するためのテンプレート定義クラス
|
||||||
|
/// </summary>
|
||||||
|
public static class HtmlTemplate
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// HTMLドキュメント全体のテンプレート
|
||||||
|
/// </summary>
|
||||||
|
public static string Render(string title, string subtitle, string bodyContent, string tocHtml)
|
||||||
|
{
|
||||||
|
return $$"""
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ja">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>{{title}}</title>
|
||||||
|
<style>
|
||||||
|
{{GetCss()}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- ヘッダー -->
|
||||||
|
<header>
|
||||||
|
<div class="header-container">
|
||||||
|
<h1 class="header-title">
|
||||||
|
<span class="header-icon">📑</span>
|
||||||
|
<span id="docTitle">{{title}}</span>
|
||||||
|
</h1>
|
||||||
|
{{(string.IsNullOrWhiteSpace(subtitle) ? "" : $"<p class=\"header-subtitle\">{subtitle}</p>")}}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- レイアウトコンテナ -->
|
||||||
|
<div class="main-wrapper">
|
||||||
|
|
||||||
|
<!-- 目次(サイドバー) -->
|
||||||
|
<aside class="toc-sidebar" id="tocSidebar">
|
||||||
|
<div class="toc-header">
|
||||||
|
<span class="toc-title">📋 目次</span>
|
||||||
|
<button class="toc-close-btn" onclick="toggleSidebar(false)">✕</button>
|
||||||
|
</div>
|
||||||
|
<nav class="toc-nav">
|
||||||
|
{{tocHtml}}
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<!-- メインコンテンツ -->
|
||||||
|
<main class="content-area">
|
||||||
|
|
||||||
|
<!-- コントロールバー(検索・一括開閉・目次切替) -->
|
||||||
|
<div class="controls-card">
|
||||||
|
<div class="search-box">
|
||||||
|
<span class="search-icon">🔍</span>
|
||||||
|
<input type="text" id="globalSearch" class="search-input" placeholder="ページ内をリアルタイム検索(見出し・表・コード・本文)..." oninput="handleSearch()">
|
||||||
|
</div>
|
||||||
|
<div class="control-actions">
|
||||||
|
<button class="action-btn" onclick="toggleSidebar()">📑 目次表示</button>
|
||||||
|
<button class="action-btn" onclick="expandAllSections(true)">すべて展開</button>
|
||||||
|
<button class="action-btn" onclick="expandAllSections(false)">すべて折りたたむ</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 本文領域 -->
|
||||||
|
<article class="markdown-body" id="markdownBody">
|
||||||
|
{{bodyContent}}
|
||||||
|
</article>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- トースト通知 -->
|
||||||
|
<div id="toast">クリップボードにコピーしました</div>
|
||||||
|
|
||||||
|
<!-- インタラクティブ制御スクリプト -->
|
||||||
|
<script>
|
||||||
|
{{GetJavaScript()}}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// モダンで洗練された完全自己完結CSS
|
||||||
|
/// </summary>
|
||||||
|
private static string GetCss()
|
||||||
|
{
|
||||||
|
return """
|
||||||
|
:root {
|
||||||
|
--primary: #1e3a8a;
|
||||||
|
--primary-light: #2563eb;
|
||||||
|
--primary-bg: #eff6ff;
|
||||||
|
--text-main: #1f2937;
|
||||||
|
--text-muted: #4b5563;
|
||||||
|
--border-color: #e2e8f0;
|
||||||
|
--bg-card: #ffffff;
|
||||||
|
--bg-body: #f8fafc;
|
||||||
|
--sidebar-width: 290px;
|
||||||
|
--success: #10b981;
|
||||||
|
--success-bg: #ecfdf5;
|
||||||
|
--diff-add-bg: #e6ffed;
|
||||||
|
--diff-add-color: #15803d;
|
||||||
|
--diff-del-bg: #ffeef0;
|
||||||
|
--diff-del-color: #b91c1c;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Yu Gothic", "Meiryo", sans-serif;
|
||||||
|
background-color: var(--bg-body);
|
||||||
|
color: var(--text-main);
|
||||||
|
line-height: 1.68;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ヘッダー */
|
||||||
|
header {
|
||||||
|
background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #2563eb 100%);
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 24px 32px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-container {
|
||||||
|
max-width: 1400px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title {
|
||||||
|
font-size: 22px;
|
||||||
|
font-weight: 700;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-icon {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-subtitle {
|
||||||
|
font-size: 13.5px;
|
||||||
|
opacity: 0.9;
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* メインレイアウト */
|
||||||
|
.main-wrapper {
|
||||||
|
max-width: 1400px;
|
||||||
|
margin: 20px auto;
|
||||||
|
padding: 0 24px;
|
||||||
|
display: flex;
|
||||||
|
gap: 24px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 目次サイドバー */
|
||||||
|
.toc-sidebar {
|
||||||
|
width: var(--sidebar-width);
|
||||||
|
flex-shrink: 0;
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 20px;
|
||||||
|
height: calc(100vh - 140px);
|
||||||
|
position: sticky;
|
||||||
|
top: 100px;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.03);
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-sidebar.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
border-bottom: 2px solid var(--border-color);
|
||||||
|
padding-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-title {
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 15px;
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-close-btn {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: var(--text-muted);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-nav ul {
|
||||||
|
list-style: none;
|
||||||
|
padding-left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-nav > ul {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-nav li {
|
||||||
|
margin: 6px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-nav a {
|
||||||
|
color: var(--text-muted);
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 13px;
|
||||||
|
display: block;
|
||||||
|
padding: 3px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.15s;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toc-nav a:hover {
|
||||||
|
color: var(--primary-light);
|
||||||
|
background: var(--primary-bg);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* メインコンテンツエリア */
|
||||||
|
.content-area {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* コントロールバー */
|
||||||
|
.controls-card {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 14px 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
align-items: center;
|
||||||
|
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 280px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input {
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 14px 10px 38px;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 13.5px;
|
||||||
|
outline: none;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input:focus {
|
||||||
|
border-color: var(--primary-light);
|
||||||
|
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-icon {
|
||||||
|
position: absolute;
|
||||||
|
left: 12px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.control-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
padding: 8px 14px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 12.5px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-main);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:hover {
|
||||||
|
background: #f1f5f9;
|
||||||
|
border-color: #cbd5e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Markdown 本文コンテナ */
|
||||||
|
.markdown-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.doc-intro {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 24px 32px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* セクションアコーディオンカード(details/summary) */
|
||||||
|
details.doc-section {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 10px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
details.doc-section[open] {
|
||||||
|
border-color: #cbd5e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.doc-section-header {
|
||||||
|
padding: 16px 24px;
|
||||||
|
background: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
border-bottom: 1px solid transparent;
|
||||||
|
transition: background 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.doc-section-header::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.doc-section-header:hover {
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
details[open] > summary.doc-section-header {
|
||||||
|
background: #f1f5f9;
|
||||||
|
border-bottom: 1px solid var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.doc-section-header h2 {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
border: none !important;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--primary);
|
||||||
|
scroll-margin-top: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 開閉バッジアイコン */
|
||||||
|
summary.doc-section-header::after {
|
||||||
|
content: "▼ 折りたたむ";
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-muted);
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
flex-shrink: 0;
|
||||||
|
margin-left: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
details:not([open]) > summary.doc-section-header::after {
|
||||||
|
content: "▶ 展開する";
|
||||||
|
background: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.doc-section-content {
|
||||||
|
padding: 24px 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 見出しスタイル */
|
||||||
|
.markdown-body h1 {
|
||||||
|
font-size: 24px;
|
||||||
|
color: var(--primary);
|
||||||
|
border-bottom: 2px solid var(--border-color);
|
||||||
|
padding-bottom: 10px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body h3 {
|
||||||
|
font-size: 16px;
|
||||||
|
color: #1e40af;
|
||||||
|
margin-top: 24px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
border-left: 4px solid var(--primary-light);
|
||||||
|
padding-left: 10px;
|
||||||
|
scroll-margin-top: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body h4 {
|
||||||
|
font-size: 14.5px;
|
||||||
|
color: #334155;
|
||||||
|
margin-top: 20px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
scroll-margin-top: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body p {
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body ul,
|
||||||
|
.markdown-body ol {
|
||||||
|
padding-left: 24px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body li {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body hr {
|
||||||
|
border: 0;
|
||||||
|
height: 1px;
|
||||||
|
background: var(--border-color);
|
||||||
|
margin: 24px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body blockquote {
|
||||||
|
border-left: 4px solid var(--primary-light);
|
||||||
|
background: #f8fafc;
|
||||||
|
padding: 12px 18px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
border-radius: 0 6px 6px 0;
|
||||||
|
color: #334155;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* テーブル */
|
||||||
|
.table-container {
|
||||||
|
margin: 18px 0;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow-x: auto;
|
||||||
|
background: #ffffff;
|
||||||
|
box-shadow: 0 1px 4px rgba(0,0,0,0.02);
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background: #f1f5f9;
|
||||||
|
color: #1e293b;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 11px 14px;
|
||||||
|
border-bottom: 2px solid var(--border-color);
|
||||||
|
white-space: nowrap;
|
||||||
|
user-select: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
th:hover {
|
||||||
|
background: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
td {
|
||||||
|
padding: 11px 14px;
|
||||||
|
border-bottom: 1px solid var(--border-color);
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) td {
|
||||||
|
background-color: #fcfdfe;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover td {
|
||||||
|
background-color: #f1f5f9;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* コードブロック */
|
||||||
|
.code-container {
|
||||||
|
position: relative;
|
||||||
|
margin: 16px 0;
|
||||||
|
background: #1e293b;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-header {
|
||||||
|
background: #0f172a;
|
||||||
|
color: #94a3b8;
|
||||||
|
padding: 6px 14px;
|
||||||
|
font-size: 11px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
font-family: Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-copy-btn {
|
||||||
|
background: #334155;
|
||||||
|
color: #f1f5f9;
|
||||||
|
border: none;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-copy-btn:hover {
|
||||||
|
background: var(--primary-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
padding: 14px 18px;
|
||||||
|
overflow-x: auto;
|
||||||
|
font-family: Consolas, Monaco, "Courier New", monospace;
|
||||||
|
font-size: 12.5px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: Consolas, Monaco, "Courier New", monospace;
|
||||||
|
background: #f1f5f9;
|
||||||
|
color: #0f172a;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 88%;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
background: transparent;
|
||||||
|
color: inherit;
|
||||||
|
padding: 0;
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* diff ハイライト */
|
||||||
|
.diff-add {
|
||||||
|
color: #4ade80;
|
||||||
|
background: rgba(74, 222, 128, 0.12);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.diff-del {
|
||||||
|
color: #f87171;
|
||||||
|
background: rgba(248, 113, 113, 0.12);
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* パスコピーバッジ */
|
||||||
|
.file-path-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
background: #f1f5f9;
|
||||||
|
border: 1px solid #cbd5e1;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-family: Consolas, monospace;
|
||||||
|
margin: 2px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-copy-btn {
|
||||||
|
background: #ffffff;
|
||||||
|
border: 1px solid #94a3b8;
|
||||||
|
padding: 1px 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-copy-btn:hover {
|
||||||
|
background: var(--primary-light);
|
||||||
|
color: #ffffff;
|
||||||
|
border-color: var(--primary-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* トースト通知 */
|
||||||
|
#toast {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 24px;
|
||||||
|
right: 24px;
|
||||||
|
background: #1e293b;
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||||||
|
font-size: 13px;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(20px);
|
||||||
|
transition: all 0.25s ease;
|
||||||
|
z-index: 9999;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#toast.show {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* レスポンシブ */
|
||||||
|
@media (max-width: 992px) {
|
||||||
|
.toc-sidebar {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
z-index: 1000;
|
||||||
|
box-shadow: 2px 0 16px rgba(0,0,0,0.15);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.toc-sidebar.mobile-open {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.toc-close-btn {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.doc-section-content, .doc-intro {
|
||||||
|
padding: 18px 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// クライアント側で動作するVanilla JavaScript
|
||||||
|
/// </summary>
|
||||||
|
private static string GetJavaScript()
|
||||||
|
{
|
||||||
|
return """
|
||||||
|
// テーブルのソート機能
|
||||||
|
document.querySelectorAll('table').forEach(table => {
|
||||||
|
const headers = table.querySelectorAll('th');
|
||||||
|
headers.forEach((th, colIndex) => {
|
||||||
|
th.title = 'クリックでソート';
|
||||||
|
th.addEventListener('click', () => {
|
||||||
|
sortTable(table, colIndex);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function sortTable(table, colIndex) {
|
||||||
|
const tbody = table.querySelector('tbody') || table;
|
||||||
|
const rows = Array.from(tbody.querySelectorAll('tr')).filter(r => r.querySelectorAll('td').length > 0);
|
||||||
|
const isAsc = table.getAttribute('data-sort-col') != colIndex || table.getAttribute('data-sort-dir') === 'desc';
|
||||||
|
|
||||||
|
rows.sort((rowA, rowB) => {
|
||||||
|
const cellA = (rowA.children[colIndex]?.innerText || '').trim();
|
||||||
|
const cellB = (rowB.children[colIndex]?.innerText || '').trim();
|
||||||
|
const numA = parseFloat(cellA.replace(/[^0-9.-]+/g, ''));
|
||||||
|
const numB = parseFloat(cellB.replace(/[^0-9.-]+/g, ''));
|
||||||
|
|
||||||
|
if (!isNaN(numA) && !isNaN(numB) && cellA === numA.toString()) {
|
||||||
|
return isAsc ? numA - numB : numB - numA;
|
||||||
|
}
|
||||||
|
return isAsc ? cellA.localeCompare(cellB, 'ja') : cellB.localeCompare(cellA, 'ja');
|
||||||
|
});
|
||||||
|
|
||||||
|
rows.forEach(r => tbody.appendChild(r));
|
||||||
|
table.setAttribute('data-sort-col', colIndex);
|
||||||
|
table.setAttribute('data-sort-dir', isAsc ? 'asc' : 'desc');
|
||||||
|
|
||||||
|
// ヘッダーアイコン更新
|
||||||
|
table.querySelectorAll('th').forEach((th, i) => {
|
||||||
|
th.innerText = th.innerText.replace(/ [▲▼↕]$/, '');
|
||||||
|
if (i === colIndex) {
|
||||||
|
th.innerText += isAsc ? ' ▲' : ' ▼';
|
||||||
|
} else {
|
||||||
|
th.innerText += ' ↕';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// リアルタイムインクリメンタル検索
|
||||||
|
function handleSearch() {
|
||||||
|
const query = document.getElementById('globalSearch').value.toLowerCase().trim();
|
||||||
|
|
||||||
|
// テーブル行のフィルタリング
|
||||||
|
document.querySelectorAll('table tbody tr').forEach(row => {
|
||||||
|
if (row.querySelectorAll('td').length === 0) return;
|
||||||
|
const text = row.innerText.toLowerCase();
|
||||||
|
row.style.display = (query === '' || text.includes(query)) ? '' : 'none';
|
||||||
|
});
|
||||||
|
|
||||||
|
// セクション単位のフィルタリング(ヒットしたセクションは自動展開)
|
||||||
|
document.querySelectorAll('details.doc-section').forEach(sec => {
|
||||||
|
const text = sec.innerText.toLowerCase();
|
||||||
|
if (query === '') {
|
||||||
|
sec.style.display = '';
|
||||||
|
} else if (text.includes(query)) {
|
||||||
|
sec.style.display = '';
|
||||||
|
sec.open = true; // 検索ヒット時は自動展開
|
||||||
|
} else {
|
||||||
|
sec.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// サイドバー開閉
|
||||||
|
function toggleSidebar(forceState) {
|
||||||
|
const sidebar = document.getElementById('tocSidebar');
|
||||||
|
if (window.innerWidth <= 992) {
|
||||||
|
sidebar.classList.toggle('mobile-open', forceState);
|
||||||
|
} else {
|
||||||
|
sidebar.classList.toggle('hidden', forceState !== undefined ? !forceState : undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// すべて展開 / 折りたたみ
|
||||||
|
function expandAllSections(expand) {
|
||||||
|
document.querySelectorAll('details.doc-section').forEach(d => {
|
||||||
|
d.open = expand;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// コピー機能
|
||||||
|
function copyText(text) {
|
||||||
|
navigator.clipboard.writeText(text).then(() => {
|
||||||
|
showToast('クリップボードにコピーしました: ' + text);
|
||||||
|
}).catch(() => {
|
||||||
|
showToast('コピーに失敗しました');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPreCode(btn) {
|
||||||
|
const pre = btn.closest('.code-container').querySelector('pre');
|
||||||
|
if (pre) {
|
||||||
|
navigator.clipboard.writeText(pre.innerText).then(() => {
|
||||||
|
showToast('コードをコピーしました');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showToast(msg) {
|
||||||
|
const toast = document.getElementById('toast');
|
||||||
|
toast.textContent = msg;
|
||||||
|
toast.classList.add('show');
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.classList.remove('show');
|
||||||
|
}, 2500);
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# MdToHtmlDashboard (汎用Markdown → インタラクティブHTML変換ツール)
|
||||||
|
|
||||||
|
任意の Markdown(`.md`)ファイルから、Antigravity IDE の Artifacts と同様(またはそれ以上)のリッチなテーブル整形・目次ナビゲーション・リアルタイム検索・差分ハイライトを備えた **完全自己完結型インタラクティブHTML** を自動生成する .NET 10.0 製の高速変換ツールです。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🌟 主な特徴
|
||||||
|
|
||||||
|
1. **完全自己完結(スタンドアロン)**:
|
||||||
|
- 外部インターネット接続やCDN(外部CSS/JS)に一切依存せず、生成された単一の `.html` ファイルをダブルクリックするだけで Edge や Chrome 等でいつでも美麗に開けます。
|
||||||
|
2. **インタラクティブ・テーブル**:
|
||||||
|
- Markdown内の全テーブルに、列ヘッダークリックによる「昇順/降順ソート機能」および「インクリメンタル検索」を自動付与。
|
||||||
|
3. **目次(TOC)サイドバーの自動生成**:
|
||||||
|
- 見出し(H1〜H4)の階層構造を自動解析し、折りたたみ可能な目次ナビゲーションを生成。
|
||||||
|
4. **差分コード(diff)ハイライト**:
|
||||||
|
- ````diff` 内の `+`(緑ハイライト)および `-`(赤ハイライト)を行単位で綺麗に色分け。
|
||||||
|
5. **ワンクリック・コピー機能**:
|
||||||
|
- 各コードブロックやローカルファイルパスの横に `[📋 コピー]` ボタンを自動付与。
|
||||||
|
6. **H2セクション単位のアコーディオン展開/折りたたみ**:
|
||||||
|
- 長大なドキュメントでも見通し良く閲覧可能。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 使い方
|
||||||
|
|
||||||
|
### 方法1: ドラッグ&ドロップ(最も簡単)
|
||||||
|
1. エクスプローラーで変換したい `.md` ファイルを選択します。
|
||||||
|
2. 本フォルダ直下にある **`ドラッグ&ドロップでHTML変換.bat`** にドラッグ&ドロップします。
|
||||||
|
3. 同一フォルダに `.html` ファイルが生成され、自動的にブラウザで開きます。
|
||||||
|
|
||||||
|
### 方法2: コマンドライン実行 (CLI)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 基本変換(入力ファイルと同じフォルダに .html を出力し自動オープン)
|
||||||
|
MdToHtmlDashboard.exe document.md
|
||||||
|
|
||||||
|
# 出力先パスを指定して変換
|
||||||
|
MdToHtmlDashboard.exe input.md -o output_report.html
|
||||||
|
|
||||||
|
# フォルダ内の全 .md ファイルを一括変換
|
||||||
|
MdToHtmlDashboard.exe D:\Work\Documents\
|
||||||
|
|
||||||
|
# ブラウザの自動起動を抑止
|
||||||
|
MdToHtmlDashboard.exe document.md --no-open
|
||||||
|
```
|
||||||
|
|
||||||
|
### 方法3: 対話モード
|
||||||
|
`ドラッグ&ドロップでHTML変換.bat` または `MdToHtmlDashboard.exe` を引数なしでダブルクリックすると、ファイルパスの入力受付またはカレントフォルダ内の `.md` 候補選択メニューが表示されます。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠 開発・ビルド方法 (Visual Studio / .NET 10.0)
|
||||||
|
|
||||||
|
- **ソリューションファイル**: `MdToHtmlDashboard.slnx`(Visual Studio 2022 / 2026 で開けます)
|
||||||
|
- **ターゲットフレームワーク**: `.NET 10.0`
|
||||||
|
- **主要ライブラリ**:
|
||||||
|
- `Markdig` (高度拡張Markdownパーサー)
|
||||||
|
- `HtmlAgilityPack` (DOMエンリッチメント)
|
||||||
|
|
||||||
|
### 単一実行ファイル (.exe) の発行コマンド
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd D:\VS2026_git\自作ツール\MdToHtmlDashboard
|
||||||
|
dotnet publish MdToHtmlDashboard\MdToHtmlDashboard.csproj -c Release -r win-x64 --self-contained false -o publish
|
||||||
|
```
|
||||||
|
上記を実行すると、`publish\` フォルダに高速起動する `MdToHtmlDashboard.exe` が生成されます。
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
cd /d "%~dp0"
|
||||||
|
|
||||||
|
set "EXE_PATH=%~dp0publish\MdToHtmlDashboard.exe"
|
||||||
|
|
||||||
|
if not exist "%EXE_PATH%" (
|
||||||
|
echo [MdToHtmlDashboard] Building executable...
|
||||||
|
dotnet publish "%~dp0MdToHtmlDashboard\MdToHtmlDashboard.csproj" -c Release -r win-x64 --self-contained false -o "%~dp0publish"
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%~1"=="" (
|
||||||
|
"%EXE_PATH%"
|
||||||
|
) else (
|
||||||
|
"%EXE_PATH%" %*
|
||||||
|
)
|
||||||
|
|
||||||
|
if %ERRORLEVEL% neq 0 (
|
||||||
|
echo.
|
||||||
|
echo [Error] Process failed.
|
||||||
|
pause
|
||||||
|
)
|
||||||
|
endlocal
|
||||||
Reference in new issue
Block a user