Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ TCrossReferences = record
var
CandidateChild, SelectedForTransfer: TNode;
CurrentHeadingRank: THeadingRank;
Element, NewLI, SecondLI, NewLink, NewP, NewI, TempElement: TElement;
Element, HeadingSelfLink, NewLI, SecondLI, NewLink, NewP, NewI, TempElement: TElement;
Scratch, ImageSrc: Rope;
ExtractedData: CutRope;
ClassName, Instruction, CrossReferenceName, Revision, ReferenceName: UTF8String;
Expand All @@ -494,7 +494,26 @@ TCrossReferences = record
LastSeenHeadingID := MungeTopicToID(Element.TextContent.AsString);
if (LastSeenHeadingID = '') then
LastSeenHeadingID := 'blank-heading';
LastSeenHeadingID := EnsureID(Element, LastSeenHeadingID).AsString;
ExtractedData := EnsureID(Element, LastSeenHeadingID);
Assert(not ExtractedData.IsEmpty);
LastSeenHeadingID := ExtractedData.AsString;

// Append a self-link to each header
if (ClassName <> 'no-num no-toc') then
begin
HeadingSelfLink := ConstructHTMLElement(eA);
HeadingSelfLink.SetAttribute('class', 'self-link');

Scratch := Default(Rope);
Scratch.Append('#');
Scratch.AppendDestructively(ExtractedData);
HeadingSelfLink.SetAttributeDestructively('href', Scratch);

Element.AppendChild(HeadingSelfLink);
end;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would add a comment here saying ExtractedData is no longer valid past this point

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it can be assigned again, right? You did not add such comments for other AppendDestructively. Should we comment all of them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only non-obvious here because you only destroy in one branch of the if block.

// ExtractedData is no longer valid

if (CurrentHeadingRank > LastHeadingRank) then
begin
Inc(LastHeadingRank);
Expand Down