开启辅助访问     
收藏本站

站内搜索

搜索

Minecraft(我的世界)苦力怕论坛

[其他] 星空晶体的BBcode预览器的第一个版本

 发表于 2024-6-30 19:51:05 来自手机|显示全部楼层|阅读模式 IP:山东省
本帖最后由 星空晶体 于 2024-6-30 19:56 编辑

网址:https://yiyi14514.github.io/BBcode_beta1

由于是第一个版本,支持的BBcode标签较少,目前支持标签:
color backcolor size
url img
b s u i hr
(之后尽力会添加表格标签和其他)



事例代码:
  1. [b]苦力怕论坛感谢有你[/b]
  2. [s]114514[/s]
  3. [i]哈哈哈[/i]
  4. [u]gsggshs[/u]
  5. [url=https://klpbbs.com]苦力怕论坛[/url]
  6. [size=8]1[/size]
  7. [color=blue]Creeper?[/color]
  8. [backcolor=blue]Aw man![/backcolor]
  9. [img]https://tikolu.net/i/ahnlw[/img]
复制代码

图片展示:
Screenshot_20240630_194317_com.microsoft.emmx.jpg
Screenshot_20240630_194324_com.microsoft.emmx.jpg
实际效果:
苦力怕论坛感谢有你
114514
哈哈哈
gsggshs
苦力怕论坛
1
Creeper?
Aw man!




后记:此预览器的核心是JS正则表达式,这东西在我半学会前就像看天书一样,我看了教程也不知所措,都是试错的(
史山源码:
  1. <!DCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  5.         <title>BBcode预览器</title>
  6.         <style>
  7.       body{
  8.         margin: 0;
  9.         padding: 0;
  10.         background-image: url('https://tikolu.net/i/ahnlw');
  11.         height: 100%; /* 背景图垂直和水平均居中 */
  12.         background-position: center;
  13.         background-repeat: no-repeat;
  14.         background-size: cover;
  15.         background-attachment: fixed;
  16.         font-size: 12px;
  17.         font-family: 'Microsoft YaHei', sans-serif;
  18.       }
  19.       #qianyan {
  20.         color: black;
  21.         background-color: white;
  22.       
  23.         border: 2px solid orange;
  24.         margin-top: 20px;
  25.         border-radius: 10px;
  26.         background-color: rgba(255, 255, 255, 0);
  27.       }
  28.       #qianyan .biaoti {
  29.         
  30.         text-align: center;
  31.         color: white;
  32.         text-shadow: 0 0 3px rgba(0, 0, 0, 0.8); /* 添加一个轻微的阴影以增强效果 */
  33.         
  34.       }
  35.       #qianyan .wen {
  36.         
  37.         color: white;
  38.       }
  39.       #zhengshi {
  40.         color: black;
  41.         background-color: white;
  42.         
  43.         border: 2px solid orange;
  44.         margin-top: 20px;
  45.         border-radius: 10px;
  46.         background-color: rgba(255, 255, 255, 0);
  47.         overflow: hidden; /* 添加这个属性来防止内容溢出 */
  48. }

  49.       #yulan {
  50.         margin-left: 20px;
  51.         width: calc(100% - 40px); /* 使用calc函数动态计算宽度 */
  52.         height: 260px;
  53.       
  54.         border-radius: 10px;
  55.         background-color: rgba(255, 255, 255, 0);
  56.         color: white;
  57.         overflow: hidden;
  58. }

  59.       #zhengshi .biaoti {
  60.         text-align: center;
  61.         
  62.         color: white;
  63.         text-shadow: 0 0 3px rgba(0, 0, 0, 0.8); /* 添加一个轻微的阴影以增强效果 */
  64.       }
  65.       #zhengshi .anniu {
  66.         width: 200px; /* 设置按钮的宽度 */
  67.         height: 50px; /* 设置按钮的高度 */
  68.         padding: 10px; /* 设置内边距 */
  69.         
  70.         border: 1px solid white; /* 设置边框样式和颜色 */
  71.         border-radius: 25px; /* 设置边框角的半径 */
  72.         background-color: rgba(255, 255, 255, 0);;
  73.         margin-left: 80px; /* 设置按钮距离左侧80像素 */  
  74.         margin-top: 20px;      
  75.         color: white;
  76.       }
  77.        #zhengshi .biaoti1 {
  78.         
  79.         text-align: center;
  80.         color: white;
  81.         text-shadow: 0 0 3px rgba(0, 0, 0, 0.8); /* 添加一个轻微的阴影以增强效果 */
  82.        }
  83.       #output {
  84.     background-color: rgba(255, 255, 255, 0); /* 半透明背景 */
  85.     border: 1px solid white; /* 边框 */
  86.     margin-top: 10px;
  87.     padding: 10px;
  88.     border-radius: 10px;
  89.     width: 94%;
  90.    
  91.     overflow-wrap: break-word; /* 允许长单词或URL换行 */
  92.     word-wrap: break-word; /* 兼容旧浏览器 */
  93.     white-space: pre-wrap; /* 保留空白,但允许适当换行 */
  94.     overflow-y: auto;
  95. }

  96. #output1 {
  97.     font-size: 20px;
  98.     margin: 0; /* 移除默认的margin */
  99.     white-space: pre-wrap; /* 保留空白,但允许适当换行 */
  100. }

  101.     </style>
  102.         <script>
  103.       function jiexi() {
  104.   var shuchu = document.getElementById("yulan").value;
  105.   yulan = shuchu
  106.     .replace(/\[color=([^\]]+)\](.*?)\[\/color\]/gi, function(match, color, content) {
  107.       return '<span style="color: ' + color + '">' + content + '</span>';
  108.     })
  109.     .replace(/\[backcolor=([^\]]+)\](.*?)\[\/backcolor\]/gi, function(match, backcolor, content) {
  110.       return '<span style="background-color: ' + backcolor + '">' + content + '</span>';
  111.     })
  112.     .replace(/\[size=(\d+)\](.*?)\[\/size\]/gi, function(match, size, content) {
  113.       var fontSize;
  114.       switch (size) {
  115.         case '1':
  116.           fontSize = '12px';
  117.           break;
  118.         case '2':
  119.           fontSize = '16px';
  120.           break;
  121.         case '3':
  122.           fontSize = '20px';
  123.           break;
  124.         case '4':
  125.           fontSize = '24px';
  126.           break;
  127.         case '5':
  128.           fontSize = '28px';
  129.           break;
  130.         case '6':
  131.           fontSize = '32px';
  132.           break;
  133.         case '7':
  134.           fontSize = '36px';
  135.           break;
  136.         case '8':
  137.           fontSize = '40px';
  138.           break;
  139.         default:
  140.           fontSize = '20px';
  141.           break;
  142.       }
  143.       return '<span style="font-size: ' + fontSize + '">' + content + '</span>';
  144.     })
  145.     .replace(/\[url=([^\]]+)\](.*?)\[\/url\]/gi, function(match, url, content) {
  146.       return '<a href="' + url + '" target="_blank">' + content + '</a>';
  147.     })
  148.     .replace(/\[b\]/g, "<strong>")
  149.     .replace(/\[\/b\]/g, "</strong>")
  150.     .replace(/\[s\]/g, "<s>")
  151.     .replace(/\[\/s\]/g, "</s>")
  152.     .replace(/\[u\]/g, "<u>")
  153.     .replace(/\[\/u\]/g, "</u>")
  154.     .replace(/\[i\]/g, "<i>")
  155.     .replace(/\[\/i\]/g, "</i>")
  156.     .replace(/\[img\](.*?)\[\/img\]/g, "<img src="$1" style="max-width: 100%; height: auto;">")
  157.     .replace(/\[\hr\]/g, "<hr>");
  158.   document.getElementById("output1").innerHTML = yulan;
  159. }


  160.     </script>
  161.     </head>
  162.     <body>
  163.         <div id="qianyan">
  164.             <h1 class="biaoti">在 使 用 之 前</h1>
  165.             <p class="wen"><strong>BBcode</strong>是一种简单、易学的<strong>标记语言。</strong>主要用于论坛、在线社区和公告板等平台的文本格式化。它基于HTML,但相比之下更为简单,易于学习和使用。BBcode通过使用特殊的标签来对文本进行格式化,这些标签在显示时会转换为HTML代码,从而实现在网页上的格式化效果。BBcode的语法类似于Html,但是是[]不是&lt;&gt;。此工具可快速预览BBcode代码,让用户可查看排版并修复不足的排版。</p>
  166.         </div>
  167.         <div id="zhengshi">
  168.             <h1 class="biaoti">开 始 使 用</h1> <br> <textarea id="yulan" placeholder="请在这里输入你的BBcode代码"></textarea> <button class="anniu" onclick="jiexi()">点击预览</button> <br>
  169.             <h1 class="biaoti1">↓下面预览↓</h1>
  170.             <div id="output">
  171.                 <pre id="output1"></pre>
  172.             </div>
  173.         </div> <br>
  174.     </body>
  175. </html>
复制代码

支持一下吧
苦力怕论坛,感谢有您~
 发表于 2024-6-30 20:00:13 来自手机|显示全部楼层 IP:河北省
昨天在写这篇文章的时候就是md转HTML,HTML再转bbs的时候别提多麻烦了,文章发了又发就为了看看效果,要是早有你这个就好了
2#2024-6-30 20:00:13回复收起回复
苦力怕论坛,感谢有您~
回复支持

使用道具举报

 发表于 2024-6-30 20:00:39 来自手机|显示全部楼层 IP:广东省
建议把背景图去掉或者淡化,否则有些看不清
3#2024-6-30 20:00:39收起回复
星空晶体2024-6-30 20:01IP:山东省
回复
明白,下个版本改了
苦力怕论坛,感谢有您~
回复支持

使用道具举报

 发表于 2024-7-1 14:35:01|显示全部楼层 IP:安徽省
太棒了,终于不需要在论坛闲聊版内开回复贴测试bbcode代码了!!!
4#2024-7-1 14:35:01收起回复
星空晶体2024-7-1 19:01IP:山东省
回复
只是第一个版本,且可能有bug,表格列表等等bbcode标签都没有添加
FlashDragon回复星空晶体2024-7-1 19:31IP:安徽省
回复
期待更新~
苦力怕论坛,感谢有您~
回复支持

使用道具举报

本版积分规则

本站
关于我们
联系我们
坛史纲要
官方
哔哩哔哩
技术博客
下载
网易版
安卓版
JAVA
反馈
意见建议
教程中心
更多
捐助本站
QQ群
QQ群

QQ群

访问手机版

访问手机版

手机版|小黑屋|系统状态|klpbbs.com

粤公网安备 44200002445329号 | 由 木韩网络 提供云服务 | GMT+8, 2024-9-1 07:52

声明:本站与Mojang以及微软公司没有从属关系

Powered by Discuz! X3.4 粤ICP备2023071842号