Skip to content

Commit e0467fa

Browse files
committed
Preserve imported front matter titles
1 parent 8c857fa commit e0467fa

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/PrompterOne.Core/Editor/Services/ScriptDocumentImportService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ public async Task<ScriptImportDescriptor> ImportAsync(
2727
throw new ArgumentException(UnsupportedFileNameMessage, nameof(fileName));
2828
}
2929

30-
var text = ScriptDocumentFileTypes.CanReadAsText(normalizedFileName)
30+
var isTextImport = ScriptDocumentFileTypes.CanReadAsText(normalizedFileName);
31+
var text = isTextImport
3132
? await ReadTextAsync(stream, cancellationToken)
3233
: await ConvertToMarkdownAsync(stream, normalizedFileName, mimeType, cancellationToken);
3334
var importedDocumentName = ScriptDocumentFileTypes.BuildImportedDocumentName(normalizedFileName);
3435
var descriptor = _descriptorService.Build(importedDocumentName, text);
3536

36-
return descriptor with
37-
{
38-
Title = ScriptDocumentFileTypes.ResolvePickerTitle(normalizedFileName)
39-
};
37+
return isTextImport
38+
? descriptor
39+
: descriptor with
40+
{
41+
Title = ScriptDocumentFileTypes.ResolvePickerTitle(normalizedFileName)
42+
};
4043
}
4144

4245
private static async Task<string> ConvertToMarkdownAsync(

tests/PrompterOne.Core.Tests/Editor/ScriptDocumentImportServiceTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public sealed class ScriptDocumentImportServiceTests
1414
private const string ImportedHeading = "Converted heading should stay in the editor body";
1515
private const string ImportedParagraph = "MarkItDown should convert this DOCX paragraph into Markdown for the editor.";
1616
private const string FrontMatterMarkdownFileName = "Quarterly Town Hall.md";
17-
private const string FrontMatterMarkdownTitle = "Quarterly Town Hall";
17+
private const string FrontMatterMarkdownTitle = "Front matter title should win";
1818
private const string FrontMatterMarkdownText =
1919
"""
2020
---
21-
title: "Front matter title should not win"
21+
title: "Front matter title should win"
2222
---
2323
2424
## [Opening|140WPM|Professional]
2525
### [First block|140WPM|Warm]
26-
Imported markdown should keep the file stem as the editor title.
26+
Imported markdown should preserve the explicit front matter title in the editor.
2727
""";
2828
private const string NativeScriptFileName = "camera-check.tps";
2929
private const string NativeScriptText =
@@ -94,7 +94,7 @@ public async Task ImportAsync_NativeTpsPreservesDocumentName_AndText()
9494
}
9595

9696
[Test]
97-
public async Task ImportAsync_MarkdownImport_UsesFileStemTitle_EvenWhenFrontMatterDefinesAnotherTitle()
97+
public async Task ImportAsync_MarkdownImport_PreservesFrontMatterTitle_WhenProvided()
9898
{
9999
var service = new ScriptDocumentImportService(new ScriptImportDescriptorService());
100100
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(FrontMatterMarkdownText));

0 commit comments

Comments
 (0)