将<p>添加到角度的未格式化文本中

时间:2017-03-01 23:59:33

标签: angularjs wysiwyg copy-paste summernote

我正在粘贴纯文本,如下所示,只是在summernote的文本框中并处理它以删除所有html格式。但我需要再次处理它以更新模型,将<!-- to generate the karaf feature file from feature template file --> <plugin> <groupId>org.apache.karaf.tooling</groupId> <artifactId>karaf-maven-plugin</artifactId> <version>4.0.2</version> <configuration> <aggregateFeatures>false</aggregateFeatures> <includeTransitiveDependency>false</includeTransitiveDependency> <addBundlesToPrimaryFeature>true</addBundlesToPrimaryFeature> <addTransitiveFeatures>false</addTransitiveFeatures> </configuration> <executions> <execution> <id>plugin-feature</id> <goals> <goal>features-generate-descriptor</goal> </goals> </execution> </executions> </plugin> 添加到段落并删除空行。

这就是我所拥有的

<p>

和...

这就是我需要的:

Example Test
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.

Nulla consequat massa quis enim.

这是我的观点:

<p>Example Test</p>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
<p>Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.</p>
<p>Nulla consequat massa quis enim.</p>

这是我用于粘贴的脚本:

<div summernote config="options" ng-model="post.description" on-paste="snPaste(evt)"></div>

1 个答案:

答案 0 :(得分:1)

结果如下:

result

这是对你的控制器的调整:

angular.module('summernoteDemo', ['summernote'])
  .controller('CodeCtrl', function($scope) {
    $scope.snPaste = function(e) {
      //First define the clean content
      clipboardData = e.originalEvent.clipboardData || window.clipboardData;
      var cleanUp = clipboardData.getData('Text');

      //Have it wait for 0.5 seconds to update the pasted
      setTimeout(function() {
        $scope.$apply(function() {
          $scope.post.description = '<p>' + cleanUp.replace(/\r\n\r\n|\n\n/g, '</p><p>').replace(/\r\n|\n/g, '</p><p>') + '</p>'; //Here you update the model.
        });
      }, 500);
    };
  });

这是一个有效的JSFiddle,http://jsfiddle.net/rekrah/nkosyafs/