AMP ⚡ converter library

A library to convert HTML articles, blog posts or similar content to AMP (Accelerated Mobile Pages).

Note: This library is not intended to convert entire HTML documents if you want to convert an entire page you should use a more advanced library, for example: Lullabot/amp-library

Installation:

composer require magyarandras/amp-converter

Currently supported elments:

amp-img amp-img in amp-pan-zoom amp-img with lightbox amp-video amp-audio amp-iframe(A placeholder is automatically added to the iframes, so you can embed iframes even above the fold.) amp-youtube amp-facebook amp-instagram amp-twitter amp-pinterest amp-playbuzz amp-gist(Github gist embed) amp-vimeo amp-soundcloud(You can use amp-iframe instead) amp-vk amp-imgur amp-dailymotion amp-gfycat

Usage:

Simple example:

Make sure your HTML code doesn't contain tags or attributes invalid in HTML5 otherwise, the generated AMP will be invalid too.

<?php use magyarandrasAMPConverterConverter; /* If you have images with unknown dimensions in your HTML code and use relative URLs, you must pass the images' base URL to the constructor. Examples: $converter = new Converter('https://example.com'); $converter = new Converter('https://cdn.example.com'); */ $converter = new Converter(); //Load built-in converters $converter->loadDefaultConverters(); //HTML to convert $html = ' <p><strong>This is a sample HTML code generated by TinyMCE.</strong></p> <p><strong><img src="https://cdn.example.com/photo/example_960_720.jpg" alt="" width="960" height="640" /></strong></p> <p><span style="font-family: 'times new roman', times;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</span></p> <p style="text-align: center;"><iframe src="https://www.youtube.com/embed/gYJ03GyrSrM" width="560" height="314" allowfullscreen="allowfullscreen"></iframe></p> <p style="text-align: center;">&nbsp;</p> <blockquote class="twitter-tweet"> <p dir="ltr" lang="en">Check out the latest post on the AMP Blog to learn how <a href="https://twitter.com/AdobeExpCloud?ref_src=twsrc%5Etfw">@AdobeExpCloud</a> has been working to seamless integrate AMP support into its applications ⚡<br /><br />Learn more here

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。