From 242318d5a4ce44bff7231b18634c1846af54fc5a Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jan 2024 16:02:59 -0500 Subject: [PATCH 1/3] 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-. --- USFMToolsSharp/Models/Markers/WMarker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USFMToolsSharp/Models/Markers/WMarker.cs b/USFMToolsSharp/Models/Markers/WMarker.cs index c1a629c..9757bed 100644 --- a/USFMToolsSharp/Models/Markers/WMarker.cs +++ b/USFMToolsSharp/Models/Markers/WMarker.cs @@ -12,7 +12,7 @@ public class WMarker : Marker { public string Term; public Dictionary 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) From b34eb6770f600c8f0f210bd76606ceea6747b232 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jan 2024 21:10:50 +0000 Subject: [PATCH 2/3] Add User Defined Word Attribute Test --- USFMToolsSharpTest/USFMParserTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/USFMToolsSharpTest/USFMParserTest.cs b/USFMToolsSharpTest/USFMParserTest.cs index 76fa763..9a3ba05 100644 --- a/USFMToolsSharpTest/USFMParserTest.cs +++ b/USFMToolsSharpTest/USFMParserTest.cs @@ -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] From 990bb41f3c0329e7fcb9be0d8a203980db7647f2 Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 3 Jan 2024 16:12:17 -0500 Subject: [PATCH 3/3] Update USFMParserTest.cs --- USFMToolsSharpTest/USFMParserTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USFMToolsSharpTest/USFMParserTest.cs b/USFMToolsSharpTest/USFMParserTest.cs index 9a3ba05..e1dd472 100644 --- a/USFMToolsSharpTest/USFMParserTest.cs +++ b/USFMToolsSharpTest/USFMParserTest.cs @@ -399,7 +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"]); + 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]