Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
html2amp is simple
converter from HTML into AMP(Accelerated Mobile Pages).
This library allow you to convert simple
html into AMP. What does the simple
mean ?
As you know AMP has many restrictions to make it such as ...
<amp-img />
, <amp-iframe />
)You can see full Specification here.
AMP HTML Specification
It could be hard to convert any html into AMP perfectly but if it's simple
one it's possible to convert automatically.
For example...
So this library's target is To convert simple html into AMP
.
$ npm install html2amp --save
const html2amp = require('html2amp')
const html = `<your html>`
const options = {}
const amp = html2amp(html, options)
console.log(amp) // amp string
name | default value | note |
---|---|---|
cwd | . | image / styles base path |
gaConfigPath | amp-analytics config json path for google analytics | |
serviceWorker | attributes of amp-install-serviceworker e.g. src , data-iframe-src | |
optimize | false | if true, this module will optimize the html by using @ampproject/toolbox-optimizer |
cssPlugins | [] | you can add custom converter for css. |
htmlPlugins | [] | you can add custom converter for css. |
CSS Plugin allow you to add custom converter for CSS.
/**
* elementString :
* e.g. '<style id="test">.test { color: red; }</style>'
* e.g. '<link rel="stylesheet" href="http://example.com/test.css"></style>'
* cssText :
* e.g. '.test{ color: red; }'
* options : module options
**/
const plugin = (elementString, cssText, options) => {
// you need to return cssText which you modified.
return cssText.replace('red', '#ccc')
}
// options
const options = {
cssPlugins: [ plugin ]
}
HTML Plugin allow you to add custom converter for HTML.
/**
* htmlString :
* e.g. '<html><body><h1>Normal HTML</h1></body></html>'
* options : module options
**/
const plugin = (htmlString, options) => {
// you need to return htmlString which you modified.
return htmlString.replace('Normal', 'AMP')
}
// options
const options = {
htmlPlugins: [ plugin ]
}
This library ...
<meta charset="utf-8" />
if it does not existamp
attribute to the <html>
viewport
meta if it does not exist
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>/* css is here */<style/>
!imporant
keyword<img />
, <picture><source /></picture>
with <amp-img />
layout="responsive"
attribute<iframe />
with <amp-iframe />
<amp-analytics />
<a href="/test">
is replaced with <a href="https//original-url.com/test">
<link ref="preload" type="script">
, <link ref="preload" type="fetch">
To make your html valid AMP your html also should ...
!imporant
syntax are removed in cssFAQs
Simple converter from HTML into AMP(Accelerated Mobile Pages)
We found that html2amp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.