From af631776adc825eee1e81fce84765cacb8228e3b Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Fri, 12 Jan 2018 15:12:53 -0500 Subject: [PATCH 1/3] Add the ability to substitute in a pubyear Useful for an auto-updating copyright statement. --- src/wattsi.pas | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wattsi.pas b/src/wattsi.pas index e54fe13..c4b2ffb 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -869,6 +869,21 @@ TCrossReferences = record end; end else + if ((Element.IsIdentity(nsHTML, eSpan)) and (Element.GetAttribute('class').AsString = 'pubyear')) then + begin + if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then + begin + Fail('pubyear span must contain exactly one text node'); + end + else + begin + Scratch := Default(Rope); + DecodeDate(Date, TodayYear, TodayMonth, TodayDay); + Scratch.Append(IntToStr(TodayYear)); + TText(Element.FirstChild).Data := Scratch; + end; + end + else if (Element.IsIdentity(nsHTML, eDFN)) then begin if (Element.HasAttribute(kLTAttribute)) then From 15d23c87cd777449dd3eb381cb048be954d72751 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 18 Jan 2018 11:46:15 +0100 Subject: [PATCH 2/3] deduplicate a bit --- src/wattsi.pas | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/wattsi.pas b/src/wattsi.pas index c4b2ffb..b9e0e7c 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -850,35 +850,24 @@ TCrossReferences = record end; end else - if ((Element.IsIdentity(nsHTML, eSpan)) and (Element.GetAttribute('class').AsString = 'pubdate')) then - begin - if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then - begin - Fail('pubdate span must contain exactly one text node'); - 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; - end; - end - else - if ((Element.IsIdentity(nsHTML, eSpan)) and (Element.GetAttribute('class').AsString = 'pubyear')) then + if ((Element.IsIdentity(nsHTML, eSpan)) and ((Element.GetAttribute('class').AsString = 'pubdate') or (Element.GetAttribute('class').AsString = 'pubyear'))) then begin + ClassName := Element.GetAttribute('class').AsString; if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then begin - Fail('pubyear span must contain exactly one text node'); + 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; From 247ff91135bc40abc7079782def925ecd35ed3d6 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 18 Jan 2018 14:04:31 +0100 Subject: [PATCH 3/3] deduplicate even more --- src/wattsi.pas | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/wattsi.pas b/src/wattsi.pas index b9e0e7c..bbf2785 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -850,26 +850,38 @@ TCrossReferences = record end; end else - if ((Element.IsIdentity(nsHTML, eSpan)) and ((Element.GetAttribute('class').AsString = 'pubdate') or (Element.GetAttribute('class').AsString = 'pubyear'))) then + if (Element.IsIdentity(nsHTML, eSpan)) then begin ClassName := Element.GetAttribute('class').AsString; - if ((not Element.HasChildNodes()) or (not (Element.FirstChild is TText))) then + if ((ClassName = 'pubdate') or (ClassName = 'pubyear')) then begin - Fail(ClassName + ' 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); - 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; + if (Element.HasAttribute(kLTAttribute)) then + Fail(' with lt="" found, use data-x="" instead; span is ' + Describe(Element)); + if (Assigned(InDFN)) then + Fail(' inside ; span is ' + Describe(Element)) + else + SaveCrossReference(Element); end; end else @@ -924,16 +936,6 @@ TCrossReferences = record Result := False; end else - if (Element.IsIdentity(nsHTML, eSpan)) then - begin - if (Element.HasAttribute(kLTAttribute)) then - Fail(' with lt="" found, use data-x="" instead; span is ' + Describe(Element)); - if (Assigned(InDFN)) then - Fail(' inside ; span is ' + Describe(Element)) - else - SaveCrossReference(Element); - end - else if (Element.isIdentity(nsHTML, eA) and (not Element.HasAttribute(kHrefAttribute))) then begin Fail(' without href found: ' + Describe(Element));