summernote ajax file,summernote

Summernote

Super simple WYSIWYG Editor.

summernote.svg

summernote.svg

summernote.svg

badge.svg?branch=develop&service=github

summernoteis.svg

Summernote

Summernote is a JavaScript library that helps you create WYSIWYG editors online.

Why Summernote?

Summernote has a few special features:

Paste images from clipboard

Saves images directly in the content of the field using base64 encoding, so you don't need to implement image handling at all

Simple UI

Interactive WYSIWYG editing

Handy integration with server

Installation and dependencies

Summernote uses opensource libraries: jQuery, Bootstrap.

For Meteor, just run meteor add summernote:summernote. More info in the Meteor README.

Also there's an adaptation for React: react-summernote

For other/no frameworks:

1. include JS/CSS

Include the following code in the

tag of your HTML:

2. target a element

Then place a div tag somewhere in the body tag. This element will be replaced with the summernote editor.

Hello Summernote

3. summernote

Finally, run this script after the DOM is ready:

$(document).ready(function() {

$('#summernote').summernote();

});

For more examples, please visit to homepage.

API

code - get the HTML source code underlying the text in the editor:

var html = $('#summernote').summernote('code');

For more detail about API, please refer to document.

Warning - code injection

The code view allows the user to enter script contents. Make sure to filter/sanitize the HTML on the server. Otherwise, an attacker can inject arbitrary JavaScript code into clients.

document structure

- body container:

, ,
,

- block node:

,

,

,

,

- void block node:


- inline node: , , , , ...

- void inline node:

- text node: #text

A body container has block node, but

  • has only
  • nodes.

    A body container also has inline nodes sometimes. This inline nodes will be wraped with

    when enter key pressed.

    A block node only has inline nodes.

    A inline nodes has another inline nodes

    #text and void inline node doesn't have children.

    build summernote

    # grunt-cli is need by grunt; you might have this installed already

    npm install -g grunt-cli

    npm install

    # build full version of summernote: dist/summernote.js

    grunt build

    # generate minified copy: dist/summernote.min.js, dist/summernote.css

    grunt dist

    At this point, you should now have a build/ directory populated with everything you need to use summernote.

    test summernote

    run tests with Karma and PhantomJS

    grunt test

    If you want run tests on other browser,

    change the values for broswers properties in Gruntfile.js.

    karma: {

    all: {

    browsers: ['PhantomJS'],

    reporters: ['progress']

    }

    }

    You can use Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS and IE beside PhantomJS.

    Once you run grunt test, it will watch all javascript file. Therefore karma run tests every time you chage code.

    start local server for developing summernote.

    run local server with connect and watch.

    grunt server

    # Open a browser on http://localhost:3000.

    # If you change source code, automatically reload your page.

    Coding convention

    Contribution guide

    Please read CONTRIBUTING.md before sending pull requests.

    Contacts

    License

    summernote may be freely distributed under the MIT license.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用 summernote 的图片上传功能来实现上传图片的功能。具体步骤如下: 1. 在 HTML 文件中引入 summernote 的 CSS 和 JS 文件。 2. 在 HTML 文件中添加一个 textarea 元素,并将其转换为 summernote 编辑器。 3. 在 JS 文件中配置 summernote 编辑器的图片上传功能。可以使用 AJAX 技术将图片上传到服务器,并将上传成功后的图片 URL 返回给 summernote 编辑器。 以下是一个简单的示例代码: HTML 文件: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Summernote Upload Image</title> <link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet"> </head> <body> <textarea id="summernote"></textarea> <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script> <script src="upload.js"></script> </body> </html> ``` JS 文件(upload.js): ```javascript $(document).ready(function() { $('#summernote').summernote({ height: 300, callbacks: { onImageUpload: function(files) { var formData = new FormData(); formData.append('file', files[0]); $.ajax({ url: '/upload', method: 'POST', data: formData, processData: false, contentType: false, success: function(response) { $('#summernote').summernote('insertImage', response.url); }, error: function(jqXHR, textStatus, errorThrown) { console.error(textStatus + " " + errorThrown); } }); } } }); }); ``` 在上面的代码中,我们使用了 jQuery 和 summernote 的库文件,并在 JS 文件中配置了 summernote 编辑器的图片上传功能。具体来说,我们在 `onImageUpload` 回调函数中使用 AJAX 技术将图片上传到服务器,并将上传成功后的图片 URL 返回给 summernote 编辑器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值