Skip to content

Commit 676f62f

Browse files
LT-22039: xhtml has new nodeId attribute (#283)
Co-authored-by: Jake Oliver <jeoliver97@gmail.com>
1 parent 7affcfe commit 676f62f

6 files changed

Lines changed: 88 additions & 84 deletions

File tree

Src/xWorks/ConfiguredLcmGenerator.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ internal static IFragment GenerateContentForEntry(ICmObject entry, ConfigurableD
344344
{
345345
var clerk = settings.PropertyTable.GetValue<RecordClerk>("ActiveClerk", null);
346346
var entryClassName = settings.StylesGenerator.AddStyles(configuration).Trim('.');
347-
settings.ContentGenerator.StartEntry(xw, configuration,
347+
settings.ContentGenerator.StartEntry(xw, configuration, settings,
348348
entryClassName, entry.Guid, index, clerk);
349349
settings.ContentGenerator.AddEntryData(xw, pieces);
350350
settings.ContentGenerator.EndEntry(xw);
@@ -883,7 +883,7 @@ private static IFragment GenerateContentForPicture(ICmFile pictureFile, Configur
883883
// An XHTML id attribute must be unique but the ICmfile is used for all references to the same file within the project.
884884
// The ICmPicture that owns the file does have unique guid so we use that.
885885
var ownerGuid = owner.Guid.ToString();
886-
return settings.ContentGenerator.AddImage(config, className, srcAttribute, ownerGuid);
886+
return settings.ContentGenerator.AddImage(config, settings, className, srcAttribute, ownerGuid);
887887
}
888888
return settings.ContentGenerator.CreateFragment();
889889
}
@@ -1936,7 +1936,7 @@ private static IFragment GenerateSenseContent(ConfigurableDictionaryNode config,
19361936
if (bldr.Length() == 0)
19371937
return bldr;
19381938

1939-
return settings.ContentGenerator.AddSenseData(config, senseNumberSpan, ((ICmObject)item).Owner.Guid, bldr, first);
1939+
return settings.ContentGenerator.AddSenseData(config, settings, senseNumberSpan, ((ICmObject)item).Owner.Guid, bldr, first);
19401940
}
19411941

19421942
private static IFragment GeneratePictureContent(ConfigurableDictionaryNode config, DictionaryPublicationDecorator publicationDecorator,
@@ -2021,7 +2021,7 @@ private static IFragment GenerateCollectionItemContent(ConfigurableDictionaryNod
20212021
if (bldr.Length() == 0)
20222022
return bldr;
20232023
var collectionContent = bldr;
2024-
return settings.ContentGenerator.AddCollectionItem(config, IsBlockProperty(config), GetCollectionItemClassAttribute(config), collectionContent, first);
2024+
return settings.ContentGenerator.AddCollectionItem(config, settings, IsBlockProperty(config), GetCollectionItemClassAttribute(config), collectionContent, first);
20252025
}
20262026

20272027
private static void GenerateContentForLexRefCollection(ConfigurableDictionaryNode config,
@@ -2155,7 +2155,7 @@ private static IFragment GenerateCrossReferenceChildren(ConfigurableDictionaryNo
21552155
if (!content.IsNullOrEmpty())
21562156
{
21572157
// targets
2158-
settings.ContentGenerator.AddCollection(xw, child, IsBlockProperty(child),
2158+
settings.ContentGenerator.AddCollection(xw, child, settings, IsBlockProperty(child),
21592159
CssGenerator.GetClassAttributeForConfig(child), content);
21602160
settings.StylesGenerator.AddStyles(child);
21612161
}
@@ -2222,7 +2222,7 @@ private static IFragment GenerateSenseNumberSpanIfNeeded(ConfigurableDictionaryN
22222222
var senseNumberWs = string.IsNullOrEmpty(info.HomographConfig.WritingSystem) ? "en" : info.HomographConfig.WritingSystem;
22232223
if (string.IsNullOrEmpty(formattedSenseNumber))
22242224
return settings.ContentGenerator.CreateFragment();
2225-
return settings.ContentGenerator.GenerateSenseNumber(senseConfigNode, formattedSenseNumber, senseNumberWs);
2225+
return settings.ContentGenerator.GenerateSenseNumber(senseConfigNode, settings, formattedSenseNumber, senseNumberWs);
22262226
}
22272227

22282228
private static string GetSenseNumber(string numberingStyle, ref SenseInfo info)
@@ -2604,7 +2604,7 @@ private static IFragment GenerateContentForSimpleString(ConfigurableDictionaryNo
26042604
var writingSystem = GetLanguageFromFirstOptionOrAnalysis(config.DictionaryNodeOptions as DictionaryNodeWritingSystemOptions,
26052605
settings.Cache);
26062606
var cssClassName = settings.StylesGenerator.AddStyles(config).Trim('.');
2607-
return settings.ContentGenerator.AddProperty(config, settings.PropertyTable, cssClassName, false, simpleString, writingSystem);
2607+
return settings.ContentGenerator.AddProperty(config, settings, cssClassName, false, simpleString, writingSystem);
26082608

26092609
}
26102610

@@ -2777,12 +2777,12 @@ private static IFragment GenerateContentForString(ITsString fieldValue, Configur
27772777
{
27782778
writingSystem = writingSystem ?? GetLanguageFromFirstOption(config.DictionaryNodeOptions as DictionaryNodeWritingSystemOptions,
27792779
settings.Cache);
2780-
settings.ContentGenerator.StartMultiRunString(writer, config, writingSystem);
2780+
settings.ContentGenerator.StartMultiRunString(writer, config, settings, writingSystem);
27812781
var wsRtl = settings.Cache.WritingSystemFactory.get_Engine(writingSystem).RightToLeftScript;
27822782
if (rightToLeft != wsRtl)
27832783
{
27842784
rightToLeft = wsRtl; // the outer WS direction will be used to identify embedded runs of the opposite direction.
2785-
settings.ContentGenerator.StartBiDiWrapper(writer, config, rightToLeft);
2785+
settings.ContentGenerator.StartBiDiWrapper(writer, config, settings, rightToLeft);
27862786
}
27872787
}
27882788

@@ -2858,11 +2858,11 @@ private static IFragment GenerateAudioWsContent(string wsId,
28582858
private static void GenerateRunWithPossibleLink(GeneratorSettings settings, string writingSystem, IFragmentWriter writer, string style,
28592859
string text, Guid linkDestination, bool rightToLeft, ConfigurableDictionaryNode config, bool first, string externalLink = null)
28602860
{
2861-
settings.ContentGenerator.StartRun(writer, config, settings.PropertyTable, writingSystem, first);
2861+
settings.ContentGenerator.StartRun(writer, config, settings, writingSystem, first);
28622862
var wsRtl = settings.Cache.WritingSystemFactory.get_Engine(writingSystem).RightToLeftScript;
28632863
if (rightToLeft != wsRtl)
28642864
{
2865-
settings.ContentGenerator.StartBiDiWrapper(writer, config, wsRtl);
2865+
settings.ContentGenerator.StartBiDiWrapper(writer, config, settings, wsRtl);
28662866
}
28672867
if (!String.IsNullOrEmpty(style))
28682868
{
@@ -2913,7 +2913,7 @@ private static IFragment GenerateContentForAudioFile(ConfigurableDictionaryNode
29132913
if (string.IsNullOrEmpty(audioId) && string.IsNullOrEmpty(srcAttribute) && string.IsNullOrEmpty(audioIcon))
29142914
return settings.ContentGenerator.CreateFragment();
29152915
var safeAudioId = GetSafeXHTMLId(audioId);
2916-
return settings.ContentGenerator.GenerateAudioLinkContent(config, classname, srcAttribute, audioIcon, safeAudioId);
2916+
return settings.ContentGenerator.GenerateAudioLinkContent(config, settings, classname, srcAttribute, audioIcon, safeAudioId);
29172917
}
29182918

29192919
private static string GetSafeXHTMLId(string audioId)
@@ -3082,7 +3082,7 @@ private static void GenerateTableRow(ITsString rowUSFM, IFragmentWriter writer,
30823082
private static void GenerateError(IFragmentWriter writer, GeneratorSettings settings, ConfigurableDictionaryNode config, string text)
30833083
{
30843084
var writingSystem = settings.Cache.WritingSystemFactory.GetStrFromWs(settings.Cache.WritingSystemFactory.UserWs);
3085-
settings.ContentGenerator.StartRun(writer, null, settings.PropertyTable, writingSystem, true);
3085+
settings.ContentGenerator.StartRun(writer, null, settings, writingSystem, true);
30863086
settings.ContentGenerator.SetRunStyle(writer, null, settings.PropertyTable, writingSystem, null, true);
30873087
if (text.Contains(TxtLineSplit))
30883088
{
@@ -3258,6 +3258,7 @@ public class GeneratorSettings
32583258
public string ExportPath { get; }
32593259
public bool RightToLeft { get; }
32603260
public bool IsWebExport { get; }
3261+
public bool IsXhtmlExport { get; set; }
32613262
public bool IsTemplate { get; }
32623263

32633264
public GeneratorSettings(LcmCache cache, PropertyTable propertyTable, bool relativePaths,bool copyFiles, string exportPath, bool rightToLeft = false, bool isWebExport = false)
@@ -3285,6 +3286,7 @@ public GeneratorSettings(LcmCache cache, ReadOnlyPropertyTable propertyTable, bo
32853286
RightToLeft = rightToLeft;
32863287
IsWebExport = isWebExport;
32873288
IsTemplate = isTemplate;
3289+
IsXhtmlExport = false;
32883290
StylesGenerator.Init(propertyTable);
32893291
}
32903292
}

Src/xWorks/DictionaryExportService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void ExportConfiguredXhtml(string xhtmlPath, DictionaryConfigurationMode
140140
var publicationDecorator = ConfiguredLcmGenerator.GetPublicationDecoratorAndEntries(m_propertyTable, out var entriesToSave, exportType);
141141
if (progress != null)
142142
progress.Maximum = entriesToSave.Length;
143-
LcmXhtmlGenerator.SavePublishedHtmlWithStyles(entriesToSave, publicationDecorator, int.MaxValue, configuration, m_propertyTable, xhtmlPath, progress);
143+
LcmXhtmlGenerator.SavePublishedHtmlWithStyles(entriesToSave, publicationDecorator, int.MaxValue, configuration, m_propertyTable, xhtmlPath, progress, true);
144144
}
145145

146146
public List<JArray> ExportConfiguredJson(string folderPath, DictionaryConfigurationModel configuration, out int[] entryIds)

Src/xWorks/ILcmContentGenerator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ namespace SIL.FieldWorks.XWorks
1616
public interface ILcmContentGenerator
1717
{
1818
IFragment GenerateWsPrefixWithString(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool displayAbbreviation, int wsId, IFragment content);
19-
IFragment GenerateAudioLinkContent(ConfigurableDictionaryNode config, string classname, string srcAttribute, string caption, string safeAudioId);
19+
IFragment GenerateAudioLinkContent(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classname, string srcAttribute, string caption, string safeAudioId);
2020
IFragment WriteProcessedObject(ConfigurableDictionaryNode config, bool isBlock, IFragment elementContent, string className);
2121
IFragment WriteProcessedCollection(ConfigurableDictionaryNode config, bool isBlock, IFragment elementContent, string className);
2222
IFragment GenerateGramInfoBeforeSensesContent(IFragment content, ConfigurableDictionaryNode config);
2323
IFragment GenerateGroupingNode(ConfigurableDictionaryNode config, object field, string className, DictionaryPublicationDecorator publicationDecorator, ConfiguredLcmGenerator.GeneratorSettings settings,
2424
Func<object, ConfigurableDictionaryNode, DictionaryPublicationDecorator, ConfiguredLcmGenerator.GeneratorSettings, IFragment> childContentGenerator);
25-
IFragment AddSenseData(ConfigurableDictionaryNode config, IFragment senseNumberSpan, Guid ownerGuid, IFragment senseContent, bool first);
26-
IFragment AddCollectionItem(ConfigurableDictionaryNode config, bool isBlock, string collectionItemClass, IFragment content, bool first);
27-
IFragment AddProperty(ConfigurableDictionaryNode config, ReadOnlyPropertyTable propTable, string className, bool isBlockProperty, string content, string writingSystem);
25+
IFragment AddSenseData(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, IFragment senseNumberSpan, Guid ownerGuid, IFragment senseContent, bool first);
26+
IFragment AddCollectionItem(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool isBlock, string collectionItemClass, IFragment content, bool first);
27+
IFragment AddProperty(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string className, bool isBlockProperty, string content, string writingSystem);
2828
IFragment CreateFragment();
2929
IFragment CreateFragment(string str);
3030
IFragmentWriter CreateWriter(IFragment fragment);
31-
void StartMultiRunString(IFragmentWriter writer, ConfigurableDictionaryNode config, string writingSystem);
31+
void StartMultiRunString(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string writingSystem);
3232
void EndMultiRunString(IFragmentWriter writer);
33-
void StartBiDiWrapper(IFragmentWriter writer, ConfigurableDictionaryNode config, bool rightToLeft);
33+
void StartBiDiWrapper(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool rightToLeft);
3434
void EndBiDiWrapper(IFragmentWriter writer);
35-
void StartRun(IFragmentWriter writer, ConfigurableDictionaryNode config, ReadOnlyPropertyTable propTable, string writingSystem, bool first);
35+
void StartRun(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string writingSystem, bool first);
3636
void EndRun(IFragmentWriter writer);
3737
void SetRunStyle(IFragmentWriter writer, ConfigurableDictionaryNode config, ReadOnlyPropertyTable propertyTable, string writingSystem, string runStyle, bool error);
3838
void StartLink(IFragmentWriter writer, ConfigurableDictionaryNode config, Guid destination);
@@ -48,16 +48,16 @@ IFragment GenerateGroupingNode(ConfigurableDictionaryNode config, object field,
4848
void EndTableRow(IFragmentWriter writer);
4949
void EndTableBody(IFragmentWriter writer);
5050
void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config);
51-
void StartEntry(IFragmentWriter writer, ConfigurableDictionaryNode config, string className, Guid entryGuid, int index, RecordClerk clerk);
51+
void StartEntry(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string className, Guid entryGuid, int index, RecordClerk clerk);
5252
void AddEntryData(IFragmentWriter writer, List<ConfiguredLcmGenerator.ConfigFragment> pieces);
5353
void EndEntry(IFragmentWriter writer);
54-
void AddCollection(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className, IFragment content);
54+
void AddCollection(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool isBlockProperty, string className, IFragment content);
5555
void BeginObjectProperty(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string getCollectionItemClassAttribute);
5656
void EndObject(IFragmentWriter writer);
5757
void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionaryNode config, IFragment contents);
58-
IFragment AddImage(ConfigurableDictionaryNode config, string classAttribute, string srcAttribute, string pictureGuid);
58+
IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid);
5959
IFragment AddImageCaption(ConfigurableDictionaryNode config, IFragment captionContent);
60-
IFragment GenerateSenseNumber(ConfigurableDictionaryNode config, string formattedSenseNumber, string senseNumberWs);
60+
IFragment GenerateSenseNumber(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string formattedSenseNumber, string senseNumberWs);
6161
IFragment AddLexReferences(ConfigurableDictionaryNode config, bool generateLexType, IFragment lexTypeContent, string className, IFragment referencesContent, bool typeBefore);
6262
void BeginCrossReference(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className);
6363
void EndCrossReference(IFragmentWriter writer);

Src/xWorks/LcmJsonGenerator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public IFragment GenerateWsPrefixWithString(ConfigurableDictionaryNode config, C
4444
return content;
4545
}
4646

47-
public IFragment GenerateAudioLinkContent(ConfigurableDictionaryNode config, string classname, string srcAttribute, string caption,
47+
public IFragment GenerateAudioLinkContent(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classname, string srcAttribute, string caption,
4848
string safeAudioId)
4949
{
5050
/*"audio": {
@@ -117,14 +117,14 @@ public IFragment GenerateGroupingNode(ConfigurableDictionaryNode config, object
117117
return new StringFragment();
118118
}
119119

120-
public IFragment AddCollectionItem(ConfigurableDictionaryNode config, bool isBlock, string className, IFragment content, bool first)
120+
public IFragment AddCollectionItem(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool isBlock, string className, IFragment content, bool first)
121121
{
122122
var fragment = new StringFragment();
123123
fragment.StrBuilder.Append(content.IsNullOrEmpty() ? string.Empty : $"{{{content}}},");
124124
return fragment;
125125
}
126126

127-
public IFragment AddProperty(ConfigurableDictionaryNode config, ReadOnlyPropertyTable propTable, string className, bool isBlockProperty, string content, string writingSystem)
127+
public IFragment AddProperty(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string className, bool isBlockProperty, string content, string writingSystem)
128128
{
129129
var fragment = new StringFragment($"\"{className}\": \"{content}\",");
130130
return fragment;
@@ -145,23 +145,23 @@ public IFragmentWriter CreateWriter(IFragment bldr)
145145
return new JsonFragmentWriter(((StringFragment)bldr).StrBuilder);
146146
}
147147

148-
public void StartMultiRunString(IFragmentWriter writer, ConfigurableDictionaryNode config, string writingSystem)
148+
public void StartMultiRunString(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string writingSystem)
149149
{
150150
}
151151

152152
public void EndMultiRunString(IFragmentWriter writer)
153153
{
154154
}
155155

156-
public void StartBiDiWrapper(IFragmentWriter writer, ConfigurableDictionaryNode config, bool rightToLeft)
156+
public void StartBiDiWrapper(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool rightToLeft)
157157
{
158158
}
159159

160160
public void EndBiDiWrapper(IFragmentWriter writer)
161161
{
162162
}
163163

164-
public void StartRun(IFragmentWriter writer, ConfigurableDictionaryNode config, ReadOnlyPropertyTable propTable, string writingSystem, bool first)
164+
public void StartRun(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string writingSystem, bool first)
165165
{
166166
var jsonWriter = (JsonFragmentWriter)writer;
167167
jsonWriter.StartObject();
@@ -253,7 +253,7 @@ public void EndTable(IFragmentWriter writer, ConfigurableDictionaryNode config)
253253
// TODO: decide on a useful json representation for tables
254254
}
255255

256-
public void StartEntry(IFragmentWriter xw, ConfigurableDictionaryNode config, string className, Guid entryGuid, int index, RecordClerk clerk)
256+
public void StartEntry(IFragmentWriter xw, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string className, Guid entryGuid, int index, RecordClerk clerk)
257257
{
258258
var jsonWriter = (JsonFragmentWriter)xw;
259259
jsonWriter.StartObject();
@@ -292,7 +292,7 @@ public void EndEntry(IFragmentWriter xw)
292292
((JsonFragmentWriter)xw).EndObject();
293293
}
294294

295-
public void AddCollection(IFragmentWriter writer, ConfigurableDictionaryNode config, bool isBlockProperty, string className, IFragment content)
295+
public void AddCollection(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool isBlockProperty, string className, IFragment content)
296296
{
297297
((JsonFragmentWriter)writer).InsertPropertyName(className);
298298
BeginArray(writer);
@@ -335,7 +335,7 @@ public void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionar
335335
}
336336
}
337337

338-
public IFragment AddImage(ConfigurableDictionaryNode config, string classAttribute, string srcAttribute, string pictureGuid)
338+
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid)
339339
{
340340
var bldr = new StringBuilder();
341341
var fragment = new StringFragment();
@@ -358,7 +358,7 @@ public IFragment AddImageCaption(ConfigurableDictionaryNode config, IFragment ca
358358
return new StringFragment(captionContent.ToString());
359359
}
360360

361-
public IFragment GenerateSenseNumber(ConfigurableDictionaryNode config, string formattedSenseNumber, string wsId)
361+
public IFragment GenerateSenseNumber(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string formattedSenseNumber, string wsId)
362362
{
363363
return new StringFragment(formattedSenseNumber);
364364
}
@@ -435,7 +435,7 @@ public IFragment GenerateErrorContent(StringBuilder badStrBuilder)
435435
return new StringFragment($"\\u+0FFF\\u+0FFF\\u+0FFF{badStrBuilder}");
436436
}
437437

438-
public IFragment AddSenseData(ConfigurableDictionaryNode config, IFragment senseNumberSpan, Guid ownerGuid, IFragment senseContent, bool first)
438+
public IFragment AddSenseData(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, IFragment senseNumberSpan, Guid ownerGuid, IFragment senseContent, bool first)
439439
{
440440
var bldr = new StringBuilder();
441441
var fragment = new StringFragment(bldr);

0 commit comments

Comments
 (0)