Quill.js文本编辑器

<html>
<head>
    <title>Text Editor</title>
    <link rel="stylesheet" href="quill.snow.css">
    <link rel="stylesheet" href="quill.bubble.css">
    <link rel="stylesheet" href="sakura.css">
    <script src="quill.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/to-markdown/3.1.1/to-markdown.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/markdown-it/12.0.2/markdown-it.js"></script>
    <style>

        #editor-container {
            height: 200px;
        }

        #markdown {
            background-color: #eeffee;
            min-height: 200px;
        }

        #html {
            background-color: #ffeeee;
            min-height: 200px;
        }

        #output-quill {
            background-color: #ffeeff;
            min-height: 200px;
        }

        ol.ql-indent-1
        {
            margin-left: 200px;
        }

        #output-markdown {
            background-color: #ffeeff;
            min-height: 200px;
        }
    </style>
</head>
<body>


    <h1>Quill JS Editor</h1>
    <hr>
    <div id="editor-container">
    </div>

    <h1>Rendered Markdown</h1>
    <hr>
    <div id="output-markdown"></div>

    <h1>Rendered HTML</h1>
    <hr>
    <div id="output-quill"></div>

    <h1>RAW HTML</h1>
    <hr>
    <div id="html"></div>

    <h1>Markdown Code</h1>
    <hr>
    <div>
        <pre id="markdown"></pre>
    </div>

    <script>

        (function () {
            function init(raw_markdown) {
                var quill = new Quill("#editor-container", {
                    modules: {
                        toolbar: [
                            [{ header: [1, 2, false] }],
                            ["bold", "italic", "underline"],
                            [{ 'list': 'ordered' }, { 'list': 'bullet' }],
                            ["image", "code-block"]
                        ]
                    },
                    placeholder: "Compose an epic...",
                    theme: "snow" // or 'bubble'
                });

                var md = window.markdownit();
                md.set({
                    html: true
                });

                var result = md.render(raw_markdown);

                quill.clipboard.dangerouslyPasteHTML(result + "\n");

				//我们在传递初始数据时需要进行第一次执行。
                var html = quill.container.firstChild.innerHTML;
                $("#markdown").text(toMarkdown(html));
                $("#html").text(html);
                $("#output-quill").html(html);
                $("#output-markdown").html(result);

				// text-change 可能不是正确的事件挂钩。 现在可以使用。
                quill.on("text-change", function (delta, source) {
                    var html = quill.container.firstChild.innerHTML;
                    var markdown = toMarkdown(html);
                    var rendered_markdown = md.render(markdown);
                    $("#markdown").text(markdown);
                    $("#html").text(html);
                    $("#output-quill").html(html);
                    $("#output-markdown").html(rendered_markdown);
                });
            }

            //只有一些构造的markdown来自服务器。
            var text = "";
            text += "# Dillinger" + "\n";
            text += " " + "\n";
            text += "[![N|Solid](https://cldup.com/dTxpPi9lDf.thumb.png)](https://nodesource.com/products/nsolid)" + "\n";
            text += " " + "\n";
            text += "Dillinger is a cloud-enabled, mobile-ready, offline-storage, AngularJS powered HTML5 Markdown editor." + "\n";
            text += " " + "\n";
            text += "  - Type some Markdown on the left" + "\n";
            text += "  - See HTML in the right" + "\n";
            text += "  - Magic" + "\n";
            text += " " + "\n";
            text += "# New Features!" + "\n";
            text += " " + "\n";
            text += "  - Import a HTML file and watch it magically convert to Markdown" + "\n";
            text += "  - Drag and drop images (requires your Dropbox account be linked)" + "\n";
            text += " " + "\n";
            text += " " + "\n";
            text += "You can also:" + "\n";
            text += "  - Import and save files from GitHub, Dropbox, Google Drive and One Drive" + "\n";
            text += "  - Drag and drop markdown and HTML files into Dillinger" + "\n";
            text += "  - Export documents as Markdown, HTML and PDF" + "\n";
            text += " " + "\n";
            text += "Markdown is a lightweight markup language based on the formatting conventions that people naturally use in email.  As [John Gruber] writes on the [Markdown site][df1]" + "\n";
            text += " " + "\n";
            text += "> The overriding design goal for Markdown's" + "\n";
            text += "> formatting syntax is to make it as readable" + "\n";
            text += "> as possible. The idea is that a" + "\n";
            text += "> Markdown-formatted document should be" + "\n";
            text += "> publishable as-is, as plain text, without" + "\n";
            text += "> looking like it's been marked up with tags" + "\n";
            text += "> or formatting instructions." + "\n";
            text += " " + "\n";
            text += "This text you see here is *actually* written in Markdown! To get a feel for Markdown's syntax, type some text into the left window and watch the results in the right." + "\n";
            text += " " + "\n";
            text += "### Tech" + "\n";
            text += " " + "\n";
            text += "Dillinger uses a number of open source projects to work properly:" + "\n";
            text += " " + "\n";
            text += "* [AngularJS] - HTML enhanced for web apps!" + "\n";
            text += "* [Ace Editor] - awesome web-based text editor" + "\n";
            text += "* [markdown-it] - Markdown parser done right. Fast and easy to extend." + "\n";
            text += "* [Twitter Bootstrap] - great UI boilerplate for modern web apps" + "\n";
            text += "* [node.js] - evented I/O for the backend" + "\n";
            text += "* [Express] - fast node.js network app framework [@tjholowaychuk]" + "\n";
            text += "* [Gulp] - the streaming build system" + "\n";
            text += "* [Breakdance](http://breakdance.io) - HTML to Markdown converter" + "\n";
            text += "* [jQuery] - duh" + "\n";
            text += " " + "\n";
            text += "And of course Dillinger itself is open source with a [public repository][dill]" + "\n";
            text += " on GitHub." + "\n";
            text += " " + "\n";
            text += "### Installation" + "\n";
            text += " " + "\n";
            text += "Dillinger requires [Node.js](https://nodejs.org/) v4+ to run." + "\n";
            text += " " + "\n";
            text += "Install the dependencies and devDependencies and start the server." + "\n";
            text += " " + "\n";
            text += "```sh" + "\n";
            text += "$ cd dillinger" + "\n";
            text += "$ npm install -d" + "\n";
            text += "$ node app" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "For production environments..." + "\n";
            text += " " + "\n";
            text += "```sh" + "\n";
            text += "$ npm install --production" + "\n";
            text += "$ npm run predeploy" + "\n";
            text += "$ NODE_ENV=production node app" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "### Plugins" + "\n";
            text += " " + "\n";
            text += "Dillinger is currently extended with the following plugins. Instructions on how to use them in your own application are linked below." + "\n";
            text += " " + "\n";
            text += "| Plugin | README |" + "\n";
            text += "| ------ | ------ |" + "\n";
            text += "| Dropbox | [plugins/dropbox/README.md] [PlDb] |" + "\n";
            text += "| Github | [plugins/github/README.md] [PlGh] |" + "\n";
            text += "| Google Drive | [plugins/googledrive/README.md] [PlGd] |" + "\n";
            text += "| OneDrive | [plugins/onedrive/README.md] [PlOd] |" + "\n";
            text += "| Medium | [plugins/medium/README.md] [PlMe] |" + "\n";
            text += "| Google Analytics | [plugins/googleanalytics/README.md] [PlGa] |" + "\n";
            text += " " + "\n";
            text += " " + "\n";
            text += "### Development" + "\n";
            text += " " + "\n";
            text += "Want to contribute? Great!" + "\n";
            text += " " + "\n";
            text += "Dillinger uses Gulp + Webpack for fast developing." + "\n";
            text += "Make a change in your file and instantanously see your updates!" + "\n";
            text += " " + "\n";
            text += "Open your favorite Terminal and run these commands." + "\n";
            text += " " + "\n";
            text += "First Tab:" + "\n";
            text += "```sh" + "\n";
            text += "$ node app" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "Second Tab:" + "\n";
            text += "```sh" + "\n";
            text += "$ gulp watch" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "(optional) Third:" + "\n";
            text += "```sh" + "\n";
            text += "$ karma test" + "\n";
            text += "```" + "\n";
            text += "#### Building for source" + "\n";
            text += "For production release:" + "\n";
            text += "```sh" + "\n";
            text += "$ gulp build --prod" + "\n";
            text += "```" + "\n";
            text += "Generating pre-built zip archives for distribution:" + "\n";
            text += "```sh" + "\n";
            text += "$ gulp build dist --prod" + "\n";
            text += "```" + "\n";
            text += "### Docker" + "\n";
            text += "Dillinger is very easy to install and deploy in a Docker container." + "\n";
            text += " " + "\n";
            text += "By default, the Docker will expose port 80, so change this within the Dockerfile if necessary. When ready, simply use the Dockerfile to build the image." + "\n";
            text += " " + "\n";
            text += "```sh" + "\n";
            text += "cd dillinger" + "\n";
            text += "docker build -t joemccann/dillinger:${package.json.version}" + "\n";
            text += "```" + "\n";
            text += "This will create the dillinger image and pull in the necessary dependencies. Be sure to swap out `${package.json.version}` with the actual version of Dillinger." + "\n";
            text += " " + "\n";
            text += "Once done, run the Docker image and map the port to whatever you wish on your host. In this example, we simply map port 8000 of the host to port 80 of the Docker (or whatever port was exposed in the Dockerfile):" + "\n";
            text += " " + "\n";
            text += "```sh" + "\n";
            text += "docker run -d -p 8000:8080 --restart=\"always\" <youruser>/dillinger:${package.json.version}" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "Verify the deployment by navigating to your server address in your preferred browser." + "\n";
            text += " " + "\n";
            text += "```sh" + "\n";
            text += "127.0.0.1:8000" + "\n";
            text += "```" + "\n";
            text += " " + "\n";
            text += "#### Kubernetes + Google Cloud" + "\n";
            text += " " + "\n";
            text += "See [KUBERNETES.md](https://github.com/joemccann/dillinger/blob/master/KUBERNETES.md)" + "\n";
            text += " " + "\n";
            text += " " + "\n";
            text += "### Todos" + "\n";
            text += " " + "\n";
            text += " - Write MOAR Tests" + "\n";
            text += " - Add Night Mode" + "\n";
            text += " " + "\n";
            text += "License" + "\n";
            text += "----" + "\n";
            text += " " + "\n";
            text += "MIT" + "\n";
            text += " " + "\n";
            text += " " + "\n";
            text += "**Free Software, Hell Yeah!**" + "\n";
            text += " " + "\n";
            text += "[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)" + "\n";
            text += " " + "\n";
            text += " " + "\n";
            text += "   [dill]: <https://github.com/joemccann/dillinger>" + "\n";
            text += "   [git-repo-url]: <https://github.com/joemccann/dillinger.git>" + "\n";
            text += "   [john gruber]: <http://daringfireball.net>" + "\n";
            text += "   [df1]: <http://daringfireball.net/projects/markdown/>" + "\n";
            text += "   [markdown-it]: <https://github.com/markdown-it/markdown-it>" + "\n";
            text += "   [Ace Editor]: <http://ace.ajax.org>" + "\n";
            text += "   [node.js]: <http://nodejs.org>" + "\n";
            text += "   [Twitter Bootstrap]: <https://twitter.github.com/bootstrap/>" + "\n";
            text += "   [jQuery]: <https://jquery.com>" + "\n";
            text += "   [@tjholowaychuk]: <https://twitter.com/tjholowaychuk>" + "\n";
            text += "   [express]: <http://expressjs.com>" + "\n";
            text += "   [AngularJS]: <https://angularjs.org>" + "\n";
            text += "   [Gulp]: <http://gulpjs.com>" + "\n";
            text += " " + "\n";
            text += "   [PlDb]: <https://github.com/joemccann/dillinger/tree/master/plugins/dropbox/README.md>" + "\n";
            text += "   [PlGh]: <https://github.com/joemccann/dillinger/tree/master/plugins/github/README.md>" + "\n";
            text += "   [PlGd]: <https://github.com/joemccann/dillinger/tree/master/plugins/googledrive/README.md>" + "\n";
            text += "   [PlOd]: <https://github.com/joemccann/dillinger/tree/master/plugins/onedrive/README.md>" + "\n";
            text += "   [PlMe]: <https://github.com/joemccann/dillinger/tree/master/plugins/medium/README.md>" + "\n";
            text += "   [PlGa]: <https://github.com/RahulHP/dillinger/blob/master/plugins/googleanalytics/README.md>" + "\n";

            text = "<ol><li>List Item 1<li><li><ol><li>Point a</li></ol></li></ol>";

            init(text);
        })();

    </script>
</body>
</html>

如图

在这里插入图片描述

下载

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Quill 是一个基于浏览器的富文本编辑器,它提供了一种简单、灵活、强大的方式来创建和编辑富文本内容。下面是 Quill文本编辑器的使用教程: 1. 引入 Quill 库 首先,在你的 HTML 文件中引入 Quill 库: ```html <script src="//cdn.quilljs.com/1.3.6/quill.js"></script> <link href="//cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet"> ``` 2. 创建 Quill 实例 在页面中创建一个空的 div 元素,用于 Quill 编辑器的容器: ```html <div id="editor"></div> ``` 然后,在 JavaScript 中创建一个 Quill 实例: ```javascript var quill = new Quill('#editor', { theme: 'snow' // 使用 snow 主题 }); ``` 3. 添加编辑器内容 在 Quill 编辑器中添加内容可以通过 `setContents` 方法或 `setText` 方法实现。 ```javascript // 使用 setContents 方法添加内容 quill.setContents([ { insert: 'Hello World!' } ]); // 使用 setText 方法添加内容 quill.setText('Hello World!'); ``` 4. 监听编辑器内容变化 如果你需要在内容变化时执行一些操作,可以监听 `text-change` 事件: ```javascript quill.on('text-change', function(delta, oldDelta, source) { console.log('内容已经变化'); }); ``` 5. 获取编辑器内容 你可以使用 `getContents` 方法获取 Quill 编辑器中的内容: ```javascript var content = quill.getContents(); console.log(content); ``` 6. 获取编辑器纯文本内容 你可以使用 `getText` 方法获取 Quill 编辑器中的纯文本内容: ```javascript var text = quill.getText(); console.log(text); ``` 7. 自定义编辑器样式 你可以通过修改 CSS 样式来自定义编辑器的样式,Quill 提供了许多 CSS 类名,用于定制不同的编辑器元素。 例如,你可以修改编辑器的背景颜色: ```css .ql-editor { background-color: #f5f5f5; } ``` 以上就是 Quill文本编辑器的使用教程,希望能对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值