Skip to content

Commit

Permalink
AiStoryでhtmlにルビを出力するように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Apr 30, 2024
1 parent c42d74d commit e74202d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions KoeBook.Core/Models/AiStory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ public class AiStory
public Line[][] Lines { get; init; } = [];

public record Line(
[property: XmlElement("Text", typeof(TextElement), IsNullable = false), XmlElement("Ruby", typeof(Ruby), IsNullable = false)] InlineElement[] Inlines)
[property: XmlElement("Text", typeof(Text), IsNullable = false), XmlElement("Ruby", typeof(Ruby), IsNullable = false)] InlineElement[] Inlines)
{
private Line() : this([]) { }

public string GetText() => string.Concat(Inlines.Select(e => e.Text));
public string GetText() => string.Concat(Inlines.Select(e => e.Html));

public string GetScript() => string.Concat(Inlines.Select(e => e.Script));
}

public abstract record class InlineElement
{
public abstract string Text { get; }
public abstract string Html { get; }
public abstract string Script { get; }
}

public record TextElement([property: XmlText] string InnerText) : InlineElement
public record Text([property: XmlText] string InnerText) : InlineElement
{
private TextElement() : this("") { }
private Text() : this("") { }

public override string Text => InnerText;
public override string Html => InnerText;
public override string Script => InnerText;
}

Expand All @@ -44,7 +44,7 @@ public record Ruby(
{
private Ruby() : this("", "") { }

public override string Text => Rb;
public override string Html => $"<ruby>{Rb}<rt>{Rt}</rt></ruby>";
public override string Script => Rt;
}
}
2 changes: 1 addition & 1 deletion KoeBook/Views/CreateStoryPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.Pro
l.SelectMany(l =>
l.Inlines.Select(Inline (inline) => inline switch
{
AiStory.TextElement text => new Run() { Text = text.InnerText },
AiStory.Text text => new Run() { Text = text.InnerText },
AiStory.Ruby ruby => new Run() { Text = ruby.Rt },
_ => throw new UnreachableException(),
}).Append(new LineBreak())
Expand Down

0 comments on commit e74202d

Please sign in to comment.