Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ public async Task<ScriptImportDescriptor> ImportAsync(
throw new ArgumentException(UnsupportedFileNameMessage, nameof(fileName));
}

var text = ScriptDocumentFileTypes.CanReadAsText(normalizedFileName)
var isTextImport = ScriptDocumentFileTypes.CanReadAsText(normalizedFileName);
var text = isTextImport
? await ReadTextAsync(stream, cancellationToken)
: await ConvertToMarkdownAsync(stream, normalizedFileName, mimeType, cancellationToken);
var importedDocumentName = ScriptDocumentFileTypes.BuildImportedDocumentName(normalizedFileName);
var descriptor = _descriptorService.Build(importedDocumentName, text);

return descriptor with
{
Title = ScriptDocumentFileTypes.ResolvePickerTitle(normalizedFileName)
};
return isTextImport
? descriptor
: descriptor with
{
Title = ScriptDocumentFileTypes.ResolvePickerTitle(normalizedFileName)
};
}

private static async Task<string> ConvertToMarkdownAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ public sealed class ScriptDocumentImportServiceTests
private const string ImportedHeading = "Converted heading should stay in the editor body";
private const string ImportedParagraph = "MarkItDown should convert this DOCX paragraph into Markdown for the editor.";
private const string FrontMatterMarkdownFileName = "Quarterly Town Hall.md";
private const string FrontMatterMarkdownTitle = "Quarterly Town Hall";
private const string FrontMatterMarkdownTitle = "Front matter title should win";
private const string FrontMatterMarkdownText =
"""
---
title: "Front matter title should not win"
title: "Front matter title should win"
---

## [Opening|140WPM|Professional]
### [First block|140WPM|Warm]
Imported markdown should keep the file stem as the editor title.
Imported markdown should preserve the explicit front matter title in the editor.
""";
private const string NativeScriptFileName = "camera-check.tps";
private const string NativeScriptText =
Expand Down Expand Up @@ -94,7 +94,7 @@ public async Task ImportAsync_NativeTpsPreservesDocumentName_AndText()
}

[Test]
public async Task ImportAsync_MarkdownImport_UsesFileStemTitle_EvenWhenFrontMatterDefinesAnotherTitle()
public async Task ImportAsync_MarkdownImport_PreservesFrontMatterTitle_WhenProvided()
{
var service = new ScriptDocumentImportService(new ScriptImportDescriptorService());
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(FrontMatterMarkdownText));
Expand Down
Loading