Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append a self-link to each heading #30

Merged
merged 8 commits into from
Oct 31, 2016
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