162 |
162 |
annotation.CachedLengths = JsonConvert.SerializeObject(TagStartLengths);
|
163 |
163 |
annotation.CachedClosingPositions = JsonConvert.SerializeObject(TagClosingPositions);
|
164 |
164 |
annotation.CachedClosingLengths = JsonConvert.SerializeObject(TagClosingLengths);
|
165 |
|
//annotation.CachedNodeDict = JsonConvert.SerializeObject(NodeDict);
|
|
165 |
annotation.CachedCSS = JsonConvert.SerializeObject(TagInstanceCSS);
|
166 |
166 |
annotation.ModifiedType = EModified.NONE;
|
167 |
167 |
annotation.CachedDocumentHTML = docToRender;
|
168 |
168 |
context.SaveChanges();
|
... | ... | |
222 |
222 |
private List<int> TagClosingPositions = new();
|
223 |
223 |
private List<int> TagClosingLengths = new();
|
224 |
224 |
private Dictionary<HtmlNode, HtmlNode> NodeDict = new();
|
|
225 |
private List<TagInstanceCSSInfo> TagInstanceCSS = new();
|
225 |
226 |
|
226 |
227 |
/*
|
227 |
228 |
* Full HTML Preprocessing -------------------------------------------------------------------------------
|
... | ... | |
313 |
314 |
{
|
314 |
315 |
sanitizer.AllowedTags.Add("style");
|
315 |
316 |
}
|
316 |
|
docToRender = sanitizer.Sanitize(docToRender);
|
317 |
|
|
318 |
|
HtmlDocument doc = new HtmlDocument();
|
319 |
|
doc.LoadHtml(docToRender);
|
320 |
|
var cssNode = GenerateCSS(doc, tags);
|
321 |
|
doc.DocumentNode.ChildNodes.Insert(0, cssNode);
|
322 |
|
|
323 |
|
return doc.DocumentNode.OuterHtml;
|
|
317 |
docToRender = sanitizer.Sanitize(docToRender);
|
|
318 |
GenerateCSS(tags);
|
|
319 |
return docToRender;
|
324 |
320 |
}
|
325 |
321 |
|
326 |
322 |
private HtmlNode SolveFullFill(HtmlNode node, int selectionStart, int selectionEnd, int start, int end, HtmlDocument docToEdit, AnnotationTag tag)
|
... | ... | |
541 |
537 |
}
|
542 |
538 |
}
|
543 |
539 |
|
544 |
|
private HtmlNode GenerateCSS(HtmlDocument docToEdit, List<AnnotationTag> tags)
|
|
540 |
private void GenerateCSS(List<AnnotationTag> tags)
|
545 |
541 |
{
|
546 |
|
HtmlNode style = docToEdit.CreateElement("style");
|
547 |
|
|
548 |
|
string inner = "span.annotation {border-bottom: 2px solid;}";
|
549 |
|
inner += "span {line-height: 30px}\n";
|
|
542 |
/*string inner = "span.annotation {border-bottom: 2px solid;}";
|
|
543 |
inner += "span {line-height: 30px}\n";*/
|
550 |
544 |
|
551 |
545 |
var tagPaddingDict = Intersections.ColorGraph(Intersections.FindIntersections(tags));
|
552 |
|
|
553 |
546 |
foreach (var tag in tags)
|
554 |
547 |
{
|
555 |
548 |
var padding = (tagPaddingDict[tag] + 1) * 2;
|
556 |
|
inner += $"span[{TAG_INSTANCE_ATTRIBUTE_NAME}=\"{tag.Instance}\"] {{ border-color:{tag.Tag.Color}; padding-bottom: {padding}px }}";
|
|
549 |
TagInstanceCSS.Add(new()
|
|
550 |
{
|
|
551 |
InstanceId = tag.Instance,
|
|
552 |
Color = tag.Tag.Color,
|
|
553 |
Padding = padding
|
|
554 |
});
|
557 |
555 |
}
|
558 |
|
|
559 |
|
inner += "span[end=\"1\"] {border-end-end-radius: 0px; border-right: 1px solid darkgray}\n";
|
560 |
|
inner += "span[start=\"1\"] {border-end-start-radius: 0px; border-left: 1px solid darkgray}\n";
|
561 |
|
|
562 |
|
style.InnerHtml = inner;
|
563 |
|
return style;
|
564 |
556 |
}
|
565 |
557 |
|
566 |
558 |
private void AssignIdsToOriginalDocument(IEnumerable<HtmlNode> descendantsOriginal, ref int currentId)
|
... | ... | |
619 |
611 |
docToEdit.LoadHtml(htmlToEdit);
|
620 |
612 |
|
621 |
613 |
var descendantsToEdit = docToEdit.DocumentNode.DescendantsAndSelf().ToList();
|
622 |
|
RemoveCSS(docToEdit);
|
623 |
614 |
|
624 |
615 |
int i = 0;
|
625 |
616 |
List<HtmlNode> addedForSelection = new();
|
... | ... | |
669 |
660 |
}
|
670 |
661 |
}
|
671 |
662 |
|
672 |
|
var cssNode = GenerateCSS(docToEdit, tags);
|
673 |
|
docToEdit.DocumentNode.ChildNodes.Insert(0, cssNode);
|
674 |
|
|
|
663 |
GenerateCSS(tags);
|
675 |
664 |
return docToEdit.DocumentNode.OuterHtml;
|
676 |
665 |
}
|
677 |
666 |
|
... | ... | |
684 |
673 |
docToEdit.LoadHtml(htmlToEdit);
|
685 |
674 |
|
686 |
675 |
var descendantsToEdit = docToEdit.DocumentNode.DescendantsAndSelf().ToList();
|
687 |
|
RemoveCSS(docToEdit);
|
688 |
676 |
|
689 |
677 |
int i = 0;
|
690 |
678 |
int descendantsCount = descendantsToEdit.Count();
|
... | ... | |
739 |
727 |
}
|
740 |
728 |
}
|
741 |
729 |
|
742 |
|
var cssNode = GenerateCSS(docToEdit, tags);
|
743 |
|
docToEdit.DocumentNode.ChildNodes.Insert(0, cssNode);
|
744 |
|
|
|
730 |
GenerateCSS(tags);
|
745 |
731 |
return docToEdit.DocumentNode.OuterHtml;
|
746 |
732 |
}
|
747 |
733 |
|
748 |
|
private void RemoveCSS(HtmlDocument doc)
|
749 |
|
{
|
750 |
|
doc.DocumentNode.ChildNodes.RemoveAt(0);
|
751 |
|
}
|
752 |
|
|
753 |
734 |
/*
|
754 |
735 |
* Partial HTML Preprocessing ----------------------------------------------------------------------------
|
755 |
736 |
*/
|
Caching generated CSS, returning it separate from HTML