简体   繁体   English

如何从PHP类调用npm模块

[英]How can I call npm module from PHP class

I found a javascript plugin to convert HTML to markdown here https://github.com/domchristie/to-markdown . 我在这里https://github.com/domchristie/to-markdown找到了一个可将HTML转换为markdown的JavaScript插件。

I'm using Laravel 5. Let's say a user post an HTML string and I take the request from my PHP class. 我正在使用Laravel5。假设某个用户发布了HTML字符串,然后从我的PHP类中获取了请求。 Here's my controller: 这是我的控制器:

<?php
    class TheController extends Controller
    {
        ...
        public function index()
        {
            $html_text = Request::input('html_text');
            // Convert $html_text to $markdown
        }
    }
?>

If I were in a javascript file I could've called the function like this: 如果我在一个javascript文件中,我可以这样调用函数:

var toMarkdown = require('to-markdown');
toMarkdown('<h1>Hello world!</h1>');

How do I convert $html_text to $markdown without converting it to a text file and read it, if possible 如何将$html_text转换$html_text $markdown而不将其转换为文本文件并读取(如果可能)

You shouldn't use a npm package for that, there are plenty php packages to do this. 您不应该为此使用npm软件包,有很多php软件包可以做到这一点。 You can find a lot of packages compatible with Laravel on packalyst . 你可以找到很多与Laravel兼容包packalyst

For example: http://packalyst.com/packages/package/alfredo-ramos/parsedown-extra-laravel 例如: http : //packalyst.com/packages/package/alfredo-ramos/parsedown-extra-laravel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 html onclick 中的 javascript 模块调用函数 - How can I call a function from javascript module in html onclick 遇到错误:如何从打字稿中正确使用已翻译并键入的打字稿npm模块? - Getting errors: How can I properly consume my transpiled and typed typescript npm module from typescript? 如何在不安装节点的情况下在 django-admin 小部件中使用 npm 中的模块? - How can I use a module from npm in a django-admin widget, without installing node? npm 模块如何支持导入和要求? - How can i do npm module support import and require? npm测试时“找不到模块”如何解决 - How can I solve "cannot find module" when npm test 如何调试使用 webpack 编译的 npm 模块? - How can I debug an npm module compiled with webpack? 当模块已被 Z424516CA53B4AD4BEFZ37ED0 捆绑时,如何从 HTML 的模块中调用 javascript function? - How can I call a javascript function in a module from HTML when the module has been bundled by webpack? 如何添加 UMD 以便我可以在浏览器中使用我的模块并将其用作 NPM 模块? - How can I add UMD so I can use my module in the browser and as an NPM module? 如何从类中的另一个函数调用函数 - How can I call a function from another function inside a Class 如何重构 switch case 以从类调用方法? - How can I refactor the switch case to call methods from a class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM