Name exported web pages after their file

This commit is contained in:
Thorsten Sommer committed 2026-09-23 14:38:00 +02:00
1 parent 5c907afc50
commit e16b0789a4
4 files changed
+38 -3

No files matched your search

@@ -311,6 +311,19 @@ public static class FileExportFormatExtensions
_ => true,
};
/// <summary>
/// Determines whether Pandoc has to be told the title of a document in the format.
/// </summary>
/// <remarks>
/// A web page shows its title in the browser tab. Without one, Pandoc names the page after its
/// input file, which is a temporary file of ours with a random name. Word and OpenDocument show
/// no such title, and handed one anyway, they keep it as a document property nobody asked for;
/// verified with Pandoc 3.8.3 on 2026-09-23. LaTeX ignores it.
/// </remarks>
/// <param name="format">The format.</param>
/// <returns>True, when a document of this format needs a title besides its content.</returns>
public static bool NeedsPageTitle(this FileExportFormat format) => format is FileExportFormat.HTML;
/// <summary>
/// Returns the name Pandoc knows the format by.
/// </summary>
+12 -3
View File
@@ -43,14 +43,23 @@ public static class PandocExport
await File.WriteAllTextAsync(tempMarkdownFilePath, markdownText, new UTF8Encoding(false), token);
// Call Pandoc to create the document:
var pandoc = await PandocProcessBuilder
var pandocBuilder = PandocProcessBuilder
.Create()
.UseStandaloneMode()
.WithInputFormat("gfm+emoji+tex_math_dollars")
.WithOutputFormat(format.ToPandocOutputFormat())
.WithOutputFile(targetFilePath)
.WithInputFile(tempMarkdownFilePath)
.BuildAsync(rustService);
.WithInputFile(tempMarkdownFilePath);
//
// The document is named after the file it is written to. Set as metadata, the name
// reaches the page as a string which Pandoc escapes; only a file named true or false
// is read as a switch and keeps the temporary name.
//
if (format.NeedsPageTitle())
pandocBuilder.AddArgument("-M").AddArgument($"pagetitle={Path.GetFileNameWithoutExtension(targetFilePath)}");
var pandoc = await pandocBuilder.BuildAsync(rustService);
using var process = Process.Start(pandoc.StartInfo);
if (process is null)