Skip to content

Commit

Permalink
Parse User Defined Attributes in WMarker.cs (#137)
Browse files Browse the repository at this point in the history
* Parse User Defined Attributes in WMarker.cs

As per the USFM Documentation:
https://ubsicap.github.io/usfm/attributes/index.html#user-defined-attributes

> Any user defined attributes must begin with the prefix x-.

* Add User Defined Word Attribute Test

* Update USFMParserTest.cs
  • Loading branch information
jsarabia authored Jan 3, 2024
1 parent 1e3a4e0 commit 7d9c11f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion USFMToolsSharp/Models/Markers/WMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class WMarker : Marker
{
public string Term;
public Dictionary<string, string> Attributes;
private static Regex wordAttrPattern = new Regex("([\\w]+)=?\"?([\\w,:.]*)\"?", RegexOptions.Singleline);
private static Regex wordAttrPattern = new Regex("([\\w-]+)=?\"?([\\w,:.]*)\"?", RegexOptions.Singleline);
public override string Identifier => "w";

public override string PreProcess(string input)
Expand Down
1 change: 1 addition & 0 deletions USFMToolsSharpTest/USFMParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ public void TestWordEntryParse()
Assert.AreEqual("G5485", ((WMarker)parser.ParseFromString("\\f + \\fr 3:5 \\fk berhala \\ft Lih. \\w gracious|lemma=\"grace\" strong=\"G5485\" \\w* di Daftar Istilah.\\f*").Contents[0].Contents[2].Contents[1]).Attributes["strong"]);
Assert.AreEqual("H1234,G5485", ((WMarker)parser.ParseFromString("\\f + \\fr 3:5 \\fk berhala \\ft Lih. \\w gracious|strong=\"H1234,G5485\" \\w* di Daftar Istilah.\\f*").Contents[0].Contents[2].Contents[1]).Attributes["strong"]);
Assert.AreEqual("gnt5:51.1.2.1", ((WMarker)parser.ParseFromString("\\f + \\fr 3:5 \\fk berhala \\ft Lih. \\w gracious|lemma=\"grace\" srcloc=\"gnt5:51.1.2.1\" \\w* di Daftar Istilah.\\f*").Contents[0].Contents[2].Contents[1]).Attributes["srcloc"]);
Assert.AreEqual("metadata", ((WMarker)parser.ParseFromString("\\f + \\fr 3:5 \\fk berhala \\ft Lih. \\w gracious|lemma=\"grace\" x-myattr=\"metadata\" srcloc=\"gnt5:51.1.2.1\" \\w* di Daftar Istilah.\\f*").Contents[0].Contents[2].Contents[1]).Attributes["x-myattr"]);

}
[TestMethod]
Expand Down

0 comments on commit 7d9c11f

Please sign in to comment.