Socket
Socket
Sign inDemoInstall

article-json-html-render

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

article-json-html-render - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

19

dist/components/embed.js

@@ -9,10 +9,22 @@ 'use strict';

var _figureCaption = require('./figure-caption');
var _text = require('../text');
var _figureCaption2 = _interopRequireDefault(_figureCaption);
var _text2 = _interopRequireDefault(_text);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var defaultRenderCaption = function defaultRenderCaption(text) {
return (0, _deku.element)(
'figcaption',
null,
text
);
};
var setup = function setup(_ref) {
var embeds = _ref.embeds;
var customCaption = _ref.customCaption;
var renderCaption = customCaption || defaultRenderCaption;
return {

@@ -30,4 +42,5 @@ test: function test(_ref2) {

var embed = embeds[embedType] && embeds[embedType](props);
var captionText = (0, _text2.default)(caption || []);
var captionElm = caption && caption.length > 0 ? (0, _deku.element)(_figureCaption2.default, { items: caption }) : '';
var captionElm = captionText.length > 0 ? renderCaption(captionText) : '';

@@ -34,0 +47,0 @@ return (0, _deku.element)(

30

lib/components/embed.js
import {element} from 'deku';
import FigureCaption from './figure-caption';
import renderText from '../text';
const setup = ({embeds}) => ({
test: ({embedType}) => embeds[embedType],
render: ({props}) => {
const {embedType, caption, figureProps} = props;
const embed = embeds[embedType] && embeds[embedType](props);
const defaultRenderCaption = text => <figcaption>{text}</figcaption>;
const captionElm = (caption && caption.length > 0)
? <FigureCaption items={caption} /> : '';
const setup = ({embeds, customCaption}) => {
const renderCaption = customCaption || defaultRenderCaption;
return <figure {...figureProps}>{embed}{captionElm}</figure>;
}
});
return {
test: ({embedType}) => embeds[embedType],
render: ({props}) => {
const {embedType, caption, figureProps} = props;
const embed = embeds[embedType] && embeds[embedType](props);
const captionText = renderText(caption || []);
const captionElm = (captionText.length > 0)
? renderCaption(captionText)
: '';
return <figure {...figureProps}>{embed}{captionElm}</figure>;
}
};
};
export default setup;
{
"name": "article-json-html-render",
"version": "1.1.0",
"version": "1.2.0",
"description": "Base for html-based article-json renderer, such as [article-json-to-amp](https://www.npmjs.com/package/article-json-to-amp)",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -286,1 +286,45 @@ import test from 'tape';

});
test('custom caption', t => {
const customCaption = data => <figcaption-foo>{data}</figcaption-foo>;
const Article = setupArticle({
embeds: {
image: ({src}) => <img src={src} />
},
customCaption
});
const items = [{
type: 'embed',
embedType: 'image',
src: 'http://example.com/image.jpg',
width: 600,
height: 200,
caption: [{
type: 'text',
content: 'Source: ',
href: null,
italic: false,
bold: false
}, {
type: 'text',
content: 'Author',
href: 'http://example.com/author',
italic: false,
bold: false
}]
}];
const actual = string.render(<Article items={items} />);
const expected = string.render(<article>
<figure>
<img src='http://example.com/image.jpg'></img>
<figcaption-foo>
Source: <a href='http://example.com/author'>Author</a>
</figcaption-foo>
</figure>
</article>);
t.equal(actual, expected);
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc