Skip to content

Commit

Permalink
Added code to QuoteAnnotationPlugin to illustrate usage of IProject.C…
Browse files Browse the repository at this point in the history
…onvertToUSFMTokens
  • Loading branch information
tombogle committed Sep 13, 2022
1 parent f63244f commit 8e8c2d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions QuoteAnnotationPlugin/AnnotationSource.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Paratext.PluginInterfaces;
Expand All @@ -9,12 +10,13 @@ namespace QuoteAnnotationPlugin
{
internal class AnnotationSource : IPluginAnnotationSource
{
private readonly IQuotationMarkInfo quotationMarks;
private readonly List<Regex> findMarksRegexes = new List<Regex>();
private readonly IProject m_project;
private readonly List<Regex> findMarksRegexes = new List<Regex>();

public AnnotationSource(IProject project)
{
quotationMarks = project.Language.QuotationMarkInfo;
m_project = project;
var quotationMarks = project.Language.QuotationMarkInfo;
if (quotationMarks == null)
return;

Expand Down Expand Up @@ -76,8 +78,18 @@ public IReadOnlyList<IPluginAnnotation> GetAnnotations(IVerseRef verseRef, strin
List<IPluginAnnotation> annotations = new List<IPluginAnnotation>();
for (int level = 0; level < findMarksRegexes.Count; level++)
{
if (findMarksRegexes[level] == null)
var tokens = m_project.ConvertToUSFMTokens(usfm, verseRef.BookNum,
verseRef.ChapterNum, verseRef.VerseNum);

if (findMarksRegexes[level] == null)
continue;

// If this is in intro material or the verse only has section heads or other
// non-Scripture text, let's not annotate it. (In real life, this would probably
// not be the most sensible thing to do.)
if (tokens.OfType<IUSFMTextToken>().All(t => !t.IsScripture))
continue;

foreach (Match match in findMarksRegexes[level].Matches(usfm))
{
Selection sel = new Selection(match.Value, usfm.Substring(0, match.Index),
Expand Down
2 changes: 1 addition & 1 deletion QuoteAnnotationPlugin/QuoteAnnotationPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</Target>

<ItemGroup>
<PackageReference Include="ParatextPluginInterfaces" Version="2.0.9" />
<PackageReference Include="ParatextPluginInterfaces" Version="2.0.23" />
</ItemGroup>

</Project>

0 comments on commit 8e8c2d0

Please sign in to comment.