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

Add the ability to substitute in a pubyear #67

Merged
merged 3 commits into from Jan 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 27 additions & 21 deletions src/wattsi.pas
Expand Up @@ -850,22 +850,38 @@ TCrossReferences = record
end;
end
else
if ((Element.IsIdentity(nsHTML, eSpan)) and (Element.GetAttribute('class').AsString = 'pubdate')) then
if (Element.IsIdentity(nsHTML, eSpan)) then
begin
if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then
ClassName := Element.GetAttribute('class').AsString;
if ((ClassName = 'pubdate') or (ClassName = 'pubyear')) then
begin
Fail('pubdate span must contain exactly one text node');
if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then
begin
Fail(ClassName + ' span must contain exactly one text node');
end
else
begin
Scratch := Default(Rope);
DecodeDate(Date, TodayYear, TodayMonth, TodayDay);
if (ClassName = 'pubdate') then
begin
Scratch.Append(IntToStr(TodayDay));
Scratch.Append($0020);
Scratch.Append(@Months[TodayMonth][1], Length(Months[TodayMonth])); // $R-
Scratch.Append($0020);
end;
Scratch.Append(IntToStr(TodayYear));
TText(Element.FirstChild).Data := Scratch;
end;
end
else
begin
Scratch := Default(Rope);
DecodeDate(Date, TodayYear, TodayMonth, TodayDay);
Scratch.Append(IntToStr(TodayDay));
Scratch.Append($0020);
Scratch.Append(@Months[TodayMonth][1], Length(Months[TodayMonth])); // $R-
Scratch.Append($0020);
Scratch.Append(IntToStr(TodayYear));
TText(Element.FirstChild).Data := Scratch;
if (Element.HasAttribute(kLTAttribute)) then
Fail('<span> with lt="" found, use data-x="" instead; span is ' + Describe(Element));
if (Assigned(InDFN)) then
Fail('<span> inside <dfn>; span is ' + Describe(Element))
else
SaveCrossReference(Element);
end;
end
else
Expand Down Expand Up @@ -920,16 +936,6 @@ TCrossReferences = record
Result := False;
end
else
if (Element.IsIdentity(nsHTML, eSpan)) then
begin
if (Element.HasAttribute(kLTAttribute)) then
Fail('<span> with lt="" found, use data-x="" instead; span is ' + Describe(Element));
if (Assigned(InDFN)) then
Fail('<span> inside <dfn>; span is ' + Describe(Element))
else
SaveCrossReference(Element);
end
else
if (Element.isIdentity(nsHTML, eA) and (not Element.HasAttribute(kHrefAttribute))) then
begin
Fail('<a> without href found: ' + Describe(Element));
Expand Down