From 34ab8214cc3923870282d43be1ef8d2e7784e9c9 Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Tue, 12 Jul 2016 18:06:24 +0200 Subject: [PATCH 1/2] Add test for #60 --- spec/Flatten.coffee | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/Flatten.coffee b/spec/Flatten.coffee index 53b7c43..e1786bc 100644 --- a/spec/Flatten.coffee +++ b/spec/Flatten.coffee @@ -681,7 +681,7 @@ describe 'Flatten', -> path: 'foo/bar.html' items: [ id: 'http://html5doctor.com/the-article-element/' - html: "

Apple

The apple is the pomaceous fruit of the apple tree...

Red Delicious

These bright red apples are the most common found in many supermarkets...

" + html: "

Apple

The apple is the pomaceous fruit of the apple tree...

Red Delicious

These bright red apples are the most common found in many supermarkets...

" ] expected = @@ -699,6 +699,10 @@ describe 'Flatten', -> title: 'Red Delicious' caption: 'These bright red apples are the most common found in many supermarkets...' src: 'http://www.theproducemom.com/wp-content/uploads/2012/01/red_delicious_jpg.jpg' + , + type: 'image' + html: "" + src: 'https://s3-us-west-2.amazonaws.com/the-grid-img/p/904a32ea9f56b9e7bf1b500e5e2e2217a090b225.jpg' ] ] From c36b2da719fd3a55d463cb5a137f0cb8558b16cc Mon Sep 17 00:00:00 2001 From: Henri Bergius Date: Tue, 12 Jul 2016 18:09:12 +0200 Subject: [PATCH 2/2] Handle article with only an image, fixes #60 --- index.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.coffee b/index.coffee index 5020311..573bf94 100644 --- a/index.coffee +++ b/index.coffee @@ -259,6 +259,12 @@ module.exports = class Flatten caption = null title = null src = null + if tag.children.length is 1 and tag.children[0].name is 'img' and tag.children[0].attribs?.src + results.push + type: 'image' + html: @tagToHtml tag.children[0] + src: @normalizeUrl tag.children[0].attribs.src + return results for child in tag.children if child.name is 'h1' and not title title = ''