在线HTML编辑器源码

在线HTML编辑器源码

  • 效果图
    • 部分源码
      • 领取源码
        • 下期更新预报

效果图

在这里插入图片描述
在这里插入图片描述

部分源码

index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>在线HTML编辑器</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.bundle.min.js"></script>
    <script src="js/ace.min.js"></script>
    <script src="js/mode-html.js"></script>
    <script src="js/ext-language_tools.min.js"></script>
    <script src="js/clipboard.min.js"></script>
    <script src="js/FileSaver.min.js"></script>
    <!-- 2021年11月2日 23:30 开始本项目 -->
    <script>
        function loadThemeOption(editor) {
            var list = JSON.parse('[["chrome","chrome\uFF08\u9ED8\u8BA4\u7ECF\u5178\u4E3B\u9898 - \u63A8\u8350\uFF09"],["xcode","xcode\uFF08\u7070\u767D&\u7C89\u7EA2\u5143\u7D20 - \u63A8\u8350\uFF09"],["solarized_light","solarized_light\uFF08\u62A4\u773C\u9EC4\u8272 - \u63A8\u8350\uFF09"],["solarized_dark","solarized_dark\uFF08\u84DD\u7EFF\u80CC\u666F - \u63A8\u8350%29"],["dawn","dawn\uFF08\u7070\u767D&\u68D5\u7EFF\u5143\u7D20\uFF09"],["textmate","textmate\uFF08\u7070\u767D&\u84DD\u7EFF\u5143\u7D20\uFF09"],["twilight","twilight\uFF08\u6DF1\u7A7A\u9ED1\uFF09"],["cobalt","cobalt\uFF08\u6DF1\u6D77\u84DD\uFF09"]]')
            for (var i = 0, html = ''; i < list.length; i++) {
                var item = list[i]
                var thh = ''
                if (localStorage.PonConHtmlEditorsetTheme == item[0]) {
                    var thh = ' selected'
                    editor.setTheme('ace/theme/' + localStorage.PonConHtmlEditorsetTheme)
                }
                html += '<option' + thh + ' value="' + item[0] + '">' + item[1] + '</option>'
            }
            $('#themeList').html(html)
            $('#themeList')[0].addEventListener('input', function () {
                editor.setTheme('ace/theme/' + $(this).val())
                localStorage.PonConHtmlEditorsetTheme = $(this).val()
            })
        }
        $(document).ready(function () {
            // 新建编辑器
            var editor = ace.edit("editor")
            // 开始配置编辑器
            ace.config.set("basePath", 'js')
            // 默认主题
            editor.setTheme("ace/theme/chrome")
            var htmlMode = ace.require("ace/mode/html").Mode
            editor.session.setMode(new htmlMode())
            ace.require("ace/ext/language_tools")
            editor.setOptions({
                enableBasicAutocompletion: true,
                enableSnippets: true,
                enableLiveAutocompletion: true
            })
            // 设置编辑器字体大小
            var mr_setFontSize = localStorage.PonConHtmlEditorsetFontSize
            if (!mr_setFontSize) {
                mr_setFontSize = 18
            }
            editor.setFontSize(parseInt(mr_setFontSize))
            $("label.label-fontsize").html('字号:' + mr_setFontSize)
            $("#set-fontsize").val(mr_setFontSize)
            if (localStorage.PonConHtmlEditorCode) {
                editor.setValue(localStorage.PonConHtmlEditorCode)
            }
            // 消除文本选中状态
            var His_row = localStorage.PonConHtmlEditorCursorRow
            var His_column = localStorage.PonConHtmlEditorCursorColumn
            if (!His_row) {
                His_row = 0;
            }
            if (!His_column) {
                His_column = 0;
            }
            editor.gotoLine(His_row + 1)
            editor.moveCursorTo(His_row, His_column)
            editor.setShowPrintMargin(true)
            // 以上为编辑器配置
            $('.goViewer').click(function () {
                if ($(this).text() == '编辑代码') {
                    $(this).text('预览网页')
                    $('#viewer').hide()
                    $('#editor').fadeIn()
                } else {
                    $(this).text('编辑代码')
                    $('#editor').hide()
                    $('#viewer').fadeIn()
                    $('#viewer').html('<iframe id="iframe" name="iframe" style="width: 100%; height: 100%;"></iframe>')
                    var iframe = window.frames['iframe']
                    iframe.document.open()
                    iframe.document.write(editor.getValue())
                    iframe.document.close()
                }
            })
            // 设置项 - 字体
            var fontsize
            $('#set-fontsize')[0].addEventListener("input", function () {
                fontsize = $("#set-fontsize").val()
                $("label.label-fontsize").html('字号:' + fontsize)
                localStorage.PonConHtmlEditorsetFontSize = fontsize
                editor.setFontSize(parseInt(fontsize))
            })
            // 模态框
            var myModal = new bootstrap.Modal(document.getElementById('modal-seter'))
            // myModal.show()
            // 载入主题选项列表
            loadThemeOption(editor)
            // 复制代码
            $('.btn-group button.toCopy').click(function () {
                $('button.copy').attr('data-clipboard-text', editor.getValue()).click().attr('data-clipboard-text', '')
            })
            // 清空代码
            $('.btn-group button.clean').click(function () {
                if (confirm('确定要清空?')) {
                    editor.setValue('')
                }
            })
            // 下载代码
            $('.btn-group button.download').click(function () {
                var blob = new Blob([editor.getValue()], { type: "text/html;charset=utf-8" })
                saveAs(blob, new Date().getTime() + ".html")
            })
            // HTML转文本
            $('.btn-group button.toText').click(function () {
                $('#toTextResult').html($(editor.getValue()).text().replace(/\n/g, '<br />'))
            })
            // 定时保存
            setInterval(function () {
                localStorage.PonConHtmlEditorCode = editor.getValue()
                localStorage.PonConHtmlEditorCursorColumn = editor.selection.getCursor().column
                localStorage.PonConHtmlEditorCursorRow = editor.selection.getCursor().row
            }, 500)
            $('.container').fadeIn()
            addEventListener('keyup', function (event) {
                if (event.ctrlKey && event.keyCode == 81) {
                    $('button.goViewer').click()
                }
            })
        })
    </script>
</head>

<body>
    <div class="container mt-4 mb-4" style="display: none;">
        <h3 class="mb-3">在线HTML编辑器</h3>
        <div id="editor" class="mb-3 rounded border border-secondary" style="height: 500px;"></div>
        <div id="viewer" class="mb-3 rounded border border-secondary" style="height: 500px; display: none;"></div>
        <div class="btn-group mb-3" role="group">
            <button type="button" class="btn btn-success goViewer">预览网页</button>
            <button type="button" class="btn btn-secondary toCopy">复制</button>
            <button type="button" class="btn btn-danger clean">清空</button>
            <button type="button" class="btn btn-success download">下载</button>
            <button type="button" class="btn btn-secondary toText" data-bs-toggle="modal"
                data-bs-target="#modal-toText">提取文本</button>
            <button type="button" class="btn btn-primary toSet" data-bs-toggle="modal"
                data-bs-target="#modal-seter">设置</button>
        </div>
        <button style="display: none;" class="copy"></button>
        <div class="text-secondary">在线HTML编辑器工具。<a href="https://www.dkewl.com/" target="_blank" rel="noopener">刀客源码网</a></div>
        <div class="rand-words text-info"></div>
        <script>
            $.getJSON('https://v1.hitokoto.cn/', function (data) {
                $('.rand-words').html(data.hitokoto)
            })
        </script>
    </div>
    <div class="modal fade" id="modal-seter" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">设置</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-auto"></div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-auto">
                            <label for="set-fontsize" class="form-label label-fontsize">字号:</label>
                        </div>
                        <div class="col">
                            <input type="range" class="form-range" min="12" max="50" id="set-fontsize" />
                        </div>
                    </div>
                    <div class="form-floating">
                        <select class="form-select" id="themeList" aria-label="Floating label select example"></select>
                        <label for="themeList">当前主题</label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary saveSet" data-bs-dismiss="modal">完成</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="modal-toText" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">HTML转换文本结果</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <!-- <textarea class="form-control" placeholder="无转换结果,请先输入内容" id="toTextResult"
                        style="height: 200px"></textarea> -->
                    <!-- <div class="p-3"> -->
                    <div class="p-3" id="toTextResult" style="word-break: break-all;">

                    </div>
                    <!-- </div> -->
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-success copy" data-clipboard-target="#toTextResult">复制</button>
                    <button type="button" class="btn btn-primary" data-bs-dismiss="modal">完成</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        new ClipboardJS('.copy')
    </script>
</body>

</html>

领取源码

在线HTML编辑器源码

下期更新预报

程序员的浪漫

  • 📢博客主页:孤客网络科技工作室官方账号
  • 📢欢迎点赞👍收藏⭐️留言 📝如有错误敬请指正!
  • 📢本文由孤客原创,若侵权联系作者,首发于CSDN博客
  • 📢停下休息的时候不要忘了别人还在奔跑,希望大家抓紧时间学习,全力奔赴更好的生活💻

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/575245.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

10年交易Anzo Capital昂首资本才发现的适合孕线的止损

拥有10年交易经验的投资者才发现的一种止损方法&#xff0c;那就是Inside-bar孕线止损&#xff0c;有些投资者就有疑问了&#xff0c;止损能明白&#xff0c;但是什么是Inside-bar孕线?其实很简单&#xff0c;Anzo Capital昂首资本就先做个知识普及&#xff1a; inside-bar就…

一文读懂VR数字展览会,从沉浸式体验到市场竞争力的全方位提升

在数字化转型的浪潮中&#xff0c;VR技术正逐渐成为商业展览的新趋势。VR数字展览会通过创新的展示功能和互动体验&#xff0c;为参展商和观众带来前所未有的便利和效果。 一、VR展示功能的沉浸式体验 1、全方位沉浸式体验&#xff1a; VR技术能够创造一个全方位的三维展览环…

备考2024年上海初中生古诗文大会:单选题真题示例和独家解析

上海市中小学生的初中生古诗文大会——即上海中学生古诗文大会&#xff08;初中组&#xff09;和小学生古诗文大会&#xff08;比赛&#xff09;相比&#xff0c;除了题型更丰富之外&#xff0c;最主要的是考察的内容深度和广度不同。初中的题目中对于文言文的考察大幅增加&…

vue3+node.js+mysql+ant design实现表格的查询功能

今日主要分享如何运用vue、nodejs、mysql及ant design构建表格数据查询功能&#xff0c;这也是众多项目开发者关注的问题。最关键在于前端与后端的协作&#xff0c;后端数据则通过nodejs编写。尽管涉及多项技术&#xff0c;看似复杂&#xff0c;但实际操作却并非困难。当然&…

【Harmony3.1/4.0】笔记六-对话框

概念 对话框在任何一款应用中&#xff0c;任何一个系统或者平台上使用都非常频繁&#xff0c;这里介绍一下鸿蒙系统中对话框的用法&#xff0c;分别为:普通文本对话框&#xff0c;自定义提示对话框&#xff0c;对话框菜单&#xff0c;警告提示对话框&#xff0c;列表选择对话框…

数据链路层(计算机网络,待完善)

0、前言 本文大多数图片都来自于 B站UP主&#xff1a;湖科大教书匠 的教学视频&#xff0c;对高军老师及其团队制作出这么优质的课程表示感谢。文章增加了部分个人理解&#xff0c;内容并不是对视频的静态化翻译。 1、概述 1.1、数据链路层在计算机网络体系中的位置 1.2、对…

第58篇:创建Nios II工程之Hello_World<四>

Q&#xff1a;最后我们在DE2-115开发板上演示运行Hello_World程序。 A&#xff1a;先烧录编译Quartus硬件工程时生成的.sof文件&#xff0c;在FPGA上成功配置Nios II系统&#xff1b;然后在Nios II Eclipse窗口右键点击工程名hello_world&#xff0c;选择Run As-->Nios II …

离线语音模块初步学习——LSYT201B(深圳雷龙发展)

一 、产品简介 首先简单介绍下该离线语音模块&#xff0c;官方给出的介绍是&#xff1a;YT2228 是根据智能语音交互市场需求及思必驰算法的发展方向定义开发的 “芯片算法”人工智能人机语音交互解决方案&#xff0c;具有高性能、低功耗等特点。该芯片通过软硬融合的方法&…

搭建web服务器需要哪些步骤?

首先跟大家简单普及一下什么是web服务器&#xff1f; Web服务器也称为WWW(WORLD WIDE WEB)服务器&#xff0c;一般指网站服务器&#xff0c;是指驻留于因特网上某种类型计算机的程序。WEB服务器主要功能是提供网上信息浏览服务&#xff0c;可以处理浏览器等Web客户端的请求并返…

婴儿洗衣机有必要买吗?四款好评婴儿洗衣机性能大对比

由于宝宝的日常衣物是经常需要换洗的&#xff0c;而且有时候一天好几套衣服&#xff0c;遇上尿湿了、吐奶了&#xff0c;换洗就更勤。每次一点点衣物就放进家庭用的大容积洗衣机清洗&#xff0c;会相对的比较容易耗水耗电。而如果把宝宝的换洗衣物堆积一阵子&#xff0c;汇总了…

重磅!!!监控分布式NVIDIA-GPU状态

简介&#xff1a;Uptime Kuma是一个易于使用的自托管监控工具&#xff0c;它的界面干净简洁&#xff0c;部署和使用都非常方便&#xff0c;用来监控GPU是否在占用&#xff0c;非常美观。 历史攻略&#xff1a; docker应用&#xff1a;搭建uptime-kuma监控站点 win下持续观察…

VSCODE自定义代码片段简述与基础使用

目录 一、 简述二 、 基础使用说明2.1 新建一个代码块工作区间2.2 语法 三、 示例四、 参考链接 一、 简述 VSCode的自定义代码片段功能允许开发者根据自己的需求定义和使用自己的代码片段&#xff0c;从而提高编码效率。 优点: 提高效率&#xff1a; 自定义代码片段能够减少…

08 内核开发-避免冲突和死锁-mutex

08 内核开发-避免冲突和死锁-mutex 课程简介&#xff1a; Linux内核开发入门是一门旨在帮助学习者从最基本的知识开始学习Linux内核开发的入门课程。该课程旨在为对Linux内核开发感兴趣的初学者提供一个扎实的基础&#xff0c;让他们能够理解和参与到Linux内核的开发过程中。 …

JAVA实现easyExcel模版导出

easyExcel文档 模板注意&#xff1a; 用 {} 来表示你要用的变量 &#xff0c;如果本来就有"{“,”}" &#xff0c;特殊字符用"{“,”}"代替{} 代表普通变量{.}代表是list的变量 添加pom依赖 <dependency><groupId>com.alibaba</groupId&g…

记一次数据查询问题

背景: 有一个数据表,适用原始查询就能查到数据 select * from t_easy_barcode where FP01 = panel_jitaix32_2024_04_25_10_29_57 当我把表中数据列重命名之后sql如下: 因此 我先统计了一下数据表中数据有多少,查询发现有 2482872条 因此首先想到的问题是查询一…

【机器学习】特征筛选实例与代码详解

机器学习中的特征筛选 一、特征筛选的重要性与基本概念二、特征筛选的方法与实践1. 基于统计的特征筛选2. 基于模型的特征筛选3. 嵌入式特征筛选 三、总结与展望 在机器学习领域&#xff0c;特征筛选作为预处理步骤&#xff0c;对于提高模型性能、简化模型结构以及增强模型解释…

是时候了解替代FTP传文件的最优传输方案了

目前越来越多的企业在寻找替代FTP传文件的方案&#xff0c;主要原因在于其固有的一些弊端&#xff0c;在现代企业数据传输需求中可能导致安全性、效率和可靠性方面的问题。以下是FTP的一些主要弊端&#xff1a; 1.数据传输不加密&#xff1a;FTP在传输过程中不加密数据&#xf…

Mybatis入门(入门案例,IDEA配置SQL提示,JDBC介绍,lombok介绍)

目录 一、Mybatis入门案例介绍整体步骤创建SpringBoot项目pom依赖准备测试数据新建实体类配置Mybatis数据库连接信息新建接口类,编写SQL代码单元测试 二、IDEA配置SQL提示三、JDBC是什么案例JDBC和Mybatis对比 四、数据库连接池介绍如何实现一个数据库连接池切换数据库连接池 五…

commvault学习(6):备份oracle(包括oracle的安装)

1.环境 CS、MA&#xff1a;一台windows server2012 客户端&#xff1a;2台安装了oracle11g的windows server2008 1.1 windows server2008安装oracle11g &#xff08;1&#xff09;右击安装包内的setup&#xff0c;以管理员方式运行 &#xff08;2&#xff09;取消勾选接收安…

前端学习<四>JavaScript——48-jQuery动画详解

前言 jQuery提供的一组网页中常见的动画效果&#xff0c;这些动画是标准的、有规律的效果&#xff1b;同时还提供给我们了自定义动画的功能。 显示动画 方式一&#xff1a; <span style"background-color:#f8f8f8"><span style"color:#333333"…