在线HTML编辑器源码

news2024/10/5 15:49:07

在线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.coloradmin.cn/o/1625357.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

idea配置未运行过的springboot项目

1、File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven&#xff0c;把路径配置成自己的settion、repository 2、在pom.xml中右键&#xff0c;点击"Add as Maven Project" 3、File -> Project Structure… , 把jdk版本设置为该…

OpenCV 实现霍夫圆变换

返回:OpenCV系列文章目录&#xff08;持续更新中......&#xff09; 上一篇&#xff1a;OpenCV实现霍夫变换 下一篇:OpenCV 实现重新映射 目标 在本教程中&#xff0c;您将学习如何&#xff1a; 使用 OpenCV 函数 HoughCircles()检测图像中的圆圈。 理论 Hough 圆变换 H…

模拟从D盘查找图片文件进行预览改进版

<style>#files button {margin-right: 10px;background-color: #0b4180;color: white;}#files button:hover {background-color: #00B83F;color: #0C0C0C;}#file-list li:hover {cursor: pointer;color: red;}#showImg {width: 100%; /* 图片宽度100% */max-height: 80vh…

三种类的免费SSL证书

目前主流的三种域名证书&#xff1a;单域名证书、多域名证书、通配符泛域名证书。 这三种类型的证书根据用户域名的不同情况&#xff0c;应用场景也大不相同。 单域名证书应用场景&#xff1a; 针对于有且只有一个单独域名的单位&#xff0c;使用单域名证书是刚好能够满足需求…

python逆向基础流程(纯小白教程)

一&#xff0c;例题链接 NSSCTF | 在线CTF平台 二&#xff0c;文件特征 使用工具查看文件信息&#xff0c;发现是pyinsatller打包的exe文件&#xff0c;如果硬用ida分析成汇编或c语言根本摸清楚程序的逻辑&#xff0c;所以思路是反编译成py文件直接分析python代码 三&#xf…

Idea:阿里巴巴Java编码插件

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 目录 一、Alibaba Java Coding Guidelines插件介绍 二、使用步骤 总结 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 一、Alibaba Java Coding …

性能测试学习一

文章目录 什么是性能测试性能项目分类性能测试流程在这里插入图片描述 场景分类基准场景 容量场景稳定性场景性能指标性能指标 分布式压测 日期&#xff1a;2024年4月19日 从今日起开始系统更新性能测试学习笔记&#xff0c;一方面督促自身的学习进度&#xff0c;另一方面提高专…

网络爬虫之HTTP原理

** URI和URL URI的全称Uniform Resource Identifier &#xff0c;即统一资源标志符。URL的全称Uniform Resource Locator 即统一资源定位符。 URL是URI的子集&#xff0c;也就是每一个URL就是URI&#xff0c;但是每一个URI不一定是URL&#xff0c;URI还有一个子类叫URN&#x…

企业微信hook接口协议,ipad协议http,发送大视频文件

发送大视频文件 参数名必选类型说明uuid是String每个实例的唯一标识&#xff0c;根据uuid操作具体企业微信send_userid是long要发送的人或群idisRoom是bool是否是群消息 请求示例 {"uuid":"1688853790xxx", //uuid 默认随机生成如果初始化传了id则用初始…

数组和指针有什么区别?

数组&#xff08;Array&#xff09;和指针&#xff08;Pointer&#xff09;是计算机编程中常见的两种数据类型&#xff0c;它们在内存中的表示和使用方式有着显著的区别。 1. 内存中的表示&#xff1a; 数组&#xff1a; 数组是一组相同类型的元素在内存中连续存储的集合。在…

企业数字化管理是什么,如何建立企业数字化管理?

前言 随着信息技术的迅猛发展和数字化浪潮的席卷&#xff0c;企业数字化管理已成为现代企业管理的重要趋势。数字化管理不仅有助于提升企业的运营效率和市场竞争力&#xff0c;还能为企业创造更多的商业价值和机遇。因此&#xff0c;深入了解和掌握企业数字化管理的内涵和建立…

【企业管理战略方案设计】经营驱动与管理控制相结合

在企业发展过程中&#xff0c;是经营为先&#xff0c;还是管理为先&#xff1f;是经营重要还是管理重要&#xff1f;不同的人可能会有不同的答案&#xff0c;也会有不同的简介。但是如何将经营与管理有机地结合在一起&#xff0c;将冲锋陷阵的前方经营与补充粮草的后方管理加以…

C#实现TFTP客户端

1、文件结构 2、TftpConfig.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace TftpTest {public class TftpConfig{}/// <summary>/// 模式/// </summary>public enum Modes{…

前端单元测试的艺术:专业化策略与Vue项目高效实践指南

单元测试是软件开发中的基石&#xff0c;尤其对于前端领域&#xff0c;它为保证代码质量、提升开发效率、强化项目稳定性提供了不可或缺的支持。本文将深入剖析单元测试的核心理念&#xff0c;揭示其在前端开发中的独特价值&#xff0c;并提炼出一套专业且高效的实践策略&#…

闲谈工作边界

在程序员的日常工作中&#xff0c;会遇到很多边界问题。如果这些边界问题不处理好&#xff0c;会面临诸多问题。切不可忽略边界问题&#xff0c;因为这些边界很有可能是日后帮助你摆脱扯皮&#xff0c;避免被甩锅&#xff0c;甚至于好心办坏事。 那么我们来谈一下如何处理边界问…

关于螺栓的注意事项和正确操作方法——SunTorque智能扭矩系统

智能扭矩系统-智能拧紧系统-扭矩自动控制系统-SunTorque 螺栓&#xff0c;作为一种常见的紧固件&#xff0c;广泛应用于各种机械设备和结构中。在日常生活和工作中&#xff0c;我们经常需要接触到螺栓&#xff0c;因此了解螺栓的一些注意事项和正确操作方法对于确保设备的安全…

ASP.NET集成客户关系管理的企业网站的设计与开发

摘 要 企业要在激烈的市场竞争中立于不败之地&#xff0c;就必须找一种全新的管理理念和管理手段&#xff0c;对其内部和外部资源进行有效的整合。新一代ERP产品正在向客户端和供应端延伸&#xff0c;客户端的延伸即是客户关系管理。对于每个企业来说客户管理的完善程度将直接…

2024新版计算机网络视频教程65集完整版(视频+配套资料)

今日学计算机网络&#xff0c;众生皆叹难理解。 却见老师神乎其技&#xff0c;网络通畅如云烟。 协议层次纷繁复杂&#xff0c;ARP、IP、TCP、UDP。 路由器交换机相连&#xff0c;数据包穿梭无限。 网络安全重于泰山&#xff0c;防火墙、加密都来添。 恶意攻击时刻存在&#xf…

平衡二叉树、红黑树、B树、B+树

Tree 1、前言2、平衡二叉树和红黑树3、B树和B树3.1、B树的构建3.2、B树和B树的区别3.3、数据的存储方式 1、前言 本文侧重在理论方面对平衡二叉树、红黑树、B树和B树的各方面性能进行比较。不涉及编程方面的实现。而关于于平衡二叉树在C中的实现&#xff0c;我的上一篇文章平衡…

【openLooKeng-1.10.0集群环境安装部署】

openLooKeng-1.10.0集群环境安装部署 一、摘要二、正文1. 环境说明2. 集群拓扑图3. 安装过程(以root用户安装)3.1 在Coordinator和Worker两个节点都需要安装jdk1.8+3.2 在Coordinator上安装配置openLooKeng3.3 在Worker节点上进行配置openLooKeng3.4 在Coordinator节点上先启…