Repository navigation
Fix crash and misplacement from unclosed style markers #536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,17 +54,7 @@ public UsfmUpdateBlock ProcessBlock(UsfmUpdateBlock block) | |
| elements.Count == 0 | ||
| || alignmentInfo.Alignment.RowCount == 0 | ||
| || alignmentInfo.Alignment.ColumnCount == 0 | ||
| || !elements.Any(e => | ||
| ( | ||
| e.Type == UsfmUpdateBlockElementType.Paragraph | ||
| && alignmentInfo.ParagraphBehavior == UpdateUsfmMarkerBehavior.Preserve | ||
| && e.Tokens.Count == 1 | ||
| ) | ||
| || ( | ||
| e.Type == UsfmUpdateBlockElementType.Style | ||
| && alignmentInfo.StyleBehavior == UpdateUsfmMarkerBehavior.Preserve | ||
| ) | ||
| ) | ||
| || !elements.Any(e => e.IsPlaceable(alignmentInfo.ParagraphBehavior, alignmentInfo.StyleBehavior)) | ||
| ) | ||
| { | ||
| return block; | ||
|
|
@@ -99,10 +89,8 @@ public UsfmUpdateBlock ProcessBlock(UsfmUpdateBlock block) | |
| else if ( | ||
| !( | ||
| element.Type == UsfmUpdateBlockElementType.Embed | ||
| || ( | ||
| element.Type == UsfmUpdateBlockElementType.Text | ||
| && element.Tokens[0].ToUsfm().Trim().Length == 0 | ||
| ) | ||
| || element.Type == UsfmUpdateBlockElementType.Other | ||
| || (element.Type == UsfmUpdateBlockElementType.Text && element.GetText().Trim().Length == 0) | ||
| ) | ||
| ) | ||
| { | ||
|
|
@@ -126,7 +114,7 @@ public UsfmUpdateBlock ProcessBlock(UsfmUpdateBlock block) | |
| { | ||
| if (element.MarkedForRemoval) | ||
| { | ||
| string text = element.Tokens[0].ToUsfm(); | ||
| string text = element.GetText(); | ||
|
|
||
| // Track seen tokens | ||
| while ( | ||
|
|
@@ -146,7 +134,7 @@ public UsfmUpdateBlock ProcessBlock(UsfmUpdateBlock block) | |
| } | ||
| else | ||
| { | ||
| targetSentence += element.Tokens[0].ToUsfm(); | ||
| targetSentence += element.GetText(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: F2. Only the last row's alignment applies: |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -238,6 +226,10 @@ public UsfmUpdateBlock ProcessBlock(UsfmUpdateBlock block) | |
| toInsert.Sort((p1, p2) => p1.Index.CompareTo(p2.Index)); | ||
| toInsert.AddRange(embedElements.Concat(endElements).Select(e => (targetSentence.Length, e))); | ||
|
|
||
| // In the case of unclosed markers, toInsert might be empty | ||
| if (toInsert.Count == 0) | ||
| return block; | ||
|
|
||
| // Construct new text tokens to put between markers | ||
| // and reincorporate headers and empty end-of-verse paragraph markers | ||
| if (toInsert[0].Index > 0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace SIL.Machine.Corpora | ||
| { | ||
|
|
@@ -32,5 +33,21 @@ public List<UsfmToken> GetTokens() | |
| { | ||
| return MarkedForRemoval ? new List<UsfmToken>() : new List<UsfmToken>(Tokens); | ||
| } | ||
|
|
||
| public string GetText() | ||
| { | ||
| return string.Concat(Tokens.Select(t => t.ToUsfm())); | ||
| } | ||
|
|
||
| public bool IsPlaceable(UpdateUsfmMarkerBehavior paragraphBehavior, UpdateUsfmMarkerBehavior styleBehavior) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: F3. This adds public API to a netstandard2.0 package: |
||
| { | ||
| if (MarkedForRemoval) | ||
| return false; | ||
| if (Type == UsfmUpdateBlockElementType.Paragraph) | ||
| return paragraphBehavior == UpdateUsfmMarkerBehavior.Preserve && Tokens.Count == 1; | ||
| if (Type == UsfmUpdateBlockElementType.Style) | ||
| return styleBehavior == UpdateUsfmMarkerBehavior.Preserve; | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.