【问题标题】:Convert only specific tags using ng-bind-html使用 ng-bind-html 仅转换特定标签
【发布时间】:2016-12-09 23:45:01
【问题描述】:

我正在使用文本编辑器TinyMCE,并且在从数据库中检索数据时,我试图将code 与一般描述区分开来。它旨在类似于 StackOverflows 编辑器。但是,我可以使用 ng-bind-html 转换 all html 标签,这是主要问题。我不想转换 code 部分。 例如:

<strong>hello</strong>
<code>
     <div>i dont want the tags inside code to be converted</div>
     <p>i am para</p>
</code>

想要的输出是:

你好

<code>
     <div>i dont want the tags inside code to be converted</div>
     <p>i am para</p>
</code>

但是,我使用 ng-bind-html 得到的输出是:

" 你好

我不希望代码中的标签被转换

我是帕拉。”

我正在使用angular 1.52laravel php

我的部分:

<div ng-bind-html="myResult">

</div>

后端控制器:

public function getquesdet(){
    $id = Request::input('id');

    $data= Data::where('id','=',$id)->first();
    $body = html_entity_decode($data['body']);

    return html_entity_decode($body);

}

我的 angularjs 控制器:

app.controller('seperatequestion',['$scope','$rootScope','$http','$stateParams',function($scope,$rootScope,$http,$stateParams){
$http({
    method:'GET',
    url : $rootScope.apiend + '/getquestiondet',
    params:{
        id:$stateParams.qid
    }
}).success(function(result){
    $scope.myResult= result;

}).error(function(data){
    console.log(data);
})

}])

所以,我想要的只是转换html标签,不包括code标签内的标签。

【问题讨论】:

    标签: html angularjs laravel tinymce ng-bind-html


    【解决方案1】:

    TinyMCE 已经有一个插件来解决你想要做的事情:

    https://www.tinymce.com/docs/plugins/codesample/

    请注意,当您在 TinyMCE 之外渲染内容时,您需要在渲染页面中包含 Prism (http://prismjs.com/index.html) 以获得相同的外观。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多