diff --git a/PocketSharp.Reader/PocketReader.cs b/PocketSharp.Reader/PocketReader.cs index 29aa4d0..fac28c1 100644 --- a/PocketSharp.Reader/PocketReader.cs +++ b/PocketSharp.Reader/PocketReader.cs @@ -59,15 +59,17 @@ namespace PocketSharp /// The PocketReader is based on a custom PCL port of NReadability and SgmlReader. /// /// An URI. + /// if set to true [only body is returned]. + /// if set to true [no headline (h1) is included]. /// A Pocket article with extracted content and title. /// - public async Task Read(Uri uri) + public async Task Read(Uri uri, bool bodyOnly = true, bool noHeadline = false) { return await Read(new PocketItem() { ID = 0, Uri = uri - }); + }, bodyOnly, noHeadline); } @@ -78,9 +80,13 @@ namespace PocketSharp /// The PocketReader is based on a custom PCL port of NReadability and SgmlReader. /// /// The pocket item. - /// A Pocket article with extracted content and title. + /// if set to true [only body is returned]. + /// if set to true [no headline (h1) is included]. + /// + /// A Pocket article with extracted content and title. + /// /// - public async Task Read(PocketItem item) + public async Task Read(PocketItem item, bool bodyOnly = true, bool noHeadline = false) { // initialize transcoder NReadabilityTranscoder transcoder = new NReadabilityTranscoder( @@ -101,11 +107,12 @@ namespace PocketSharp Url = item.Uri.ToString(), DomSerializationParams = new DomSerializationParams() { - BodyOnly = true, + BodyOnly = bodyOnly, + NoHeadline = noHeadline, PrettyPrint = true, DontIncludeContentTypeMetaElement = true, DontIncludeMobileSpecificMetaElements = true, - DontIncludeDocTypeMetaElement = true, + DontIncludeDocTypeMetaElement = false, DontIncludeGeneratorMetaElement = true } }; diff --git a/PocketSharp.Tests/ReadTests.cs b/PocketSharp.Tests/ReadTests.cs index 4f49d3d..cae04d2 100644 --- a/PocketSharp.Tests/ReadTests.cs +++ b/PocketSharp.Tests/ReadTests.cs @@ -26,6 +26,23 @@ namespace PocketSharp.Tests Uri = new Uri("http://frontendplay.com/story/4/http-caching-demystified-part-2-implementation") }); + Assert.DoesNotContain("", result.Content); + Assert.Contains("

", result.Content); + Assert.True(result.Content.Length > 15000); + } + + + [Fact] + public async Task ReadArticleWithContainerNoHeadlineTest() + { + PocketArticle result = await reader.Read(new PocketItem() + { + ID = 99, + Uri = new Uri("http://frontendplay.com/story/4/http-caching-demystified-part-2-implementation") + }, false, true); + + Assert.Contains("", result.Content); + Assert.DoesNotContain("

", result.Content); Assert.True(result.Content.Length > 15000); } diff --git a/PortablePorts/NReadability/DomSerializationParams.cs b/PortablePorts/NReadability/DomSerializationParams.cs index 9f66b1a..cbc3d69 100644 --- a/PortablePorts/NReadability/DomSerializationParams.cs +++ b/PortablePorts/NReadability/DomSerializationParams.cs @@ -1,5 +1,4 @@ -using System; - + namespace PocketSharp.Ports.NReadability { public class DomSerializationParams @@ -48,6 +47,10 @@ namespace PocketSharp.Ports.NReadability /// public bool BodyOnly { get; set; } + /// + /// Remove headline of website + /// + public bool NoHeadline { get; set; } #endregion } } diff --git a/PortablePorts/NReadability/SgmlDomSerializer.cs b/PortablePorts/NReadability/SgmlDomSerializer.cs index 5c95ec4..7789c3a 100644 --- a/PortablePorts/NReadability/SgmlDomSerializer.cs +++ b/PortablePorts/NReadability/SgmlDomSerializer.cs @@ -92,6 +92,16 @@ namespace PocketSharp.Ports.NReadability } } + if (domSerializationParams.NoHeadline) + { + var h1 = document.Root.GetElementsByTagName("h1").FirstOrDefault(); + + if (h1 != null) + { + result = result.Replace(h1.ToString(), ""); + } + } + return result; }