Revize c9762683
Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
24 | 24 |
private readonly IMapper mapper; |
25 | 25 |
|
26 | 26 |
private const string TAG_ID_ATTRIBUTE_NAME = "aswi-tag-id"; |
27 |
private const string TAG_INSTANCE_ATTRIBUTE_NAME = "aswi-iag-instance";
|
|
27 |
private const string TAG_INSTANCE_ATTRIBUTE_NAME = "aswi-tag-instance";
|
|
28 | 28 |
|
29 | 29 |
public AnnotationServiceEF(DatabaseContext context, ILogger logger, IMapper mapper) |
30 | 30 |
{ |
... | ... | |
166 | 166 |
FillNodeDict(descendantsOriginal, descendantsToEdit); |
167 | 167 |
AssignIdsToOriginalDocument(descendantsOriginal, ref currentId); |
168 | 168 |
|
169 |
var cssNode = GenerateCSS(docToEdit, tags, new()); |
|
170 |
docToEdit.DocumentNode.ChildNodes.Add(cssNode); |
|
171 |
|
|
172 | 169 |
WrapTextInSpan(descendantsOriginal, docToEdit); |
173 | 170 |
|
174 |
int descendantsCount = descendantsToEdit.Count(); |
|
175 | 171 |
foreach (var tag in tags) |
176 | 172 |
{ |
177 | 173 |
int i = 0; |
178 | 174 |
List<HtmlNode> addedForSelection = new(); |
179 |
while (i < descendantsCount)
|
|
175 |
while (i < descendantsToEdit.Count())
|
|
180 | 176 |
{ |
181 |
for (; i < descendantsCount; i++)
|
|
177 |
for (; i < descendantsToEdit.Count(); i++)
|
|
182 | 178 |
{ |
183 | 179 |
var node = descendantsToEdit.ElementAt(i); |
184 | 180 |
if (!node.Name.Contains("#text") || addedForSelection.Contains(node) || addedForSelection.Contains(node.ParentNode) || |
... | ... | |
187 | 183 |
continue; |
188 | 184 |
} |
189 | 185 |
|
190 |
var start = TagStartPositions[node.ParentNode.GetAttributeValue(TAG_ID_ATTRIBUTE_NAME, -1)]; |
|
191 |
var end = TagClosingPositions[node.ParentNode.GetAttributeValue(TAG_ID_ATTRIBUTE_NAME, -1)]; |
|
186 |
int nodeId = node.ParentNode.GetAttributeValue(TAG_ID_ATTRIBUTE_NAME, -1); |
|
187 |
|
|
188 |
var start = TagStartPositions[nodeId] + TagStartLengths[nodeId]; |
|
189 |
var end = TagClosingPositions[nodeId]; |
|
192 | 190 |
|
193 | 191 |
int selectionStart = tag.Position; |
194 | 192 |
int selectionEnd = tag.Position + tag.Length; |
... | ... | |
223 | 221 |
sanitizer.AllowedAttributes.Clear(); |
224 | 222 |
sanitizer.AllowedAttributes.Add(TAG_ID_ATTRIBUTE_NAME); |
225 | 223 |
sanitizer.AllowedAttributes.Add(TAG_INSTANCE_ATTRIBUTE_NAME); |
224 |
sanitizer.AllowedAttributes.Add("end"); |
|
225 |
sanitizer.AllowedAttributes.Add("start"); |
|
226 |
sanitizer.AllowedAttributes.Add("class"); |
|
226 | 227 |
if (sanitizer.AllowedTags.Contains("script")) |
227 | 228 |
{ |
228 | 229 |
sanitizer.AllowedTags.Remove("script"); |
230 |
} |
|
231 |
if (!sanitizer.AllowedTags.Contains("style")) |
|
232 |
{ |
|
233 |
sanitizer.AllowedTags.Add("style"); |
|
229 | 234 |
} |
230 |
|
|
231 | 235 |
docToRender = sanitizer.Sanitize(docToRender); |
232 | 236 |
|
233 |
return docToRender; |
|
237 |
HtmlDocument doc = new HtmlDocument(); |
|
238 |
doc.LoadHtml(docToRender); |
|
239 |
var cssNode = GenerateCSS(doc, tags, new()); |
|
240 |
doc.DocumentNode.ChildNodes.Insert(0, cssNode); |
|
241 |
|
|
242 |
return doc.DocumentNode.OuterHtml; |
|
234 | 243 |
} |
235 | 244 |
|
236 | 245 |
private HtmlNode SolveFullFill(HtmlNode node, int selectionStart, int selectionEnd, int start, int end, HtmlDocument docToEdit, AnnotationTag tag) |
... | ... | |
443 | 452 |
inner += "span {line-height: 30px}\n"; |
444 | 453 |
|
445 | 454 |
// TODO temporary |
446 |
int lastPadding = 1;
|
|
455 |
int lastPadding = 0;
|
|
447 | 456 |
foreach (var tag in tags) |
448 | 457 |
{ |
449 |
inner += $"span[{TAG_INSTANCE_ATTRIBUTE_NAME}=\"{tag.Instance}\"] {{ border-color:{tag.Tag.Color}; padding-bottom: {lastPadding}px }}"; |
|
458 |
inner += $"span[{TAG_INSTANCE_ATTRIBUTE_NAME}=\"{tag.Instance}\"] {{ border-color:{tag.Tag.Color}; padding-bottom: {lastPadding % 5}px }}";
|
|
450 | 459 |
lastPadding += 2; |
451 | 460 |
} |
452 | 461 |
|
Také k dispozici: Unified diff
Fixed indexing bugs in backend, minor changes in frontend