-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
233 lines (197 loc) · 7.68 KB
/
index.html
File metadata and controls
233 lines (197 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VBA语法高亮</title>
<!-- 使用你的 mac.css 样式表 -->
<link href="prism.css" rel="stylesheet" />
<!-- <link href="mac.css" rel="stylesheet" /> -->
<script src="prism.js"></script>
<!-- 引入 html2canvas.js -->
<script src="html2canvas.js"></script>
<style>
/* 新增的 CSS 样式 */
.container {
display: flex;
justify-content: center;
/* 将容器内部的内容水平居中对齐 */
flex-wrap: wrap;
}
.containers {
display: flex;
justify-content: flex-start;
}
body {
/* 背景渐变 */
background-image: linear-gradient(to bottom right,
#91defe,
#000000,
#000000,
#000000,
#000000,
#f9bccc);
/* 将背景大小调整为cover,填充整个页面 */
background-size: cover;
/* 将背景位置设置为顶部 */
background-position: top;
/* 将背景固定在视口中 */
background-attachment: fixed;
/* 设置背景不重复 */
background-repeat: no-repeat;
/* 设置高度为100%,以填充整个视口 */
height: 100%;
/* 设置margin和padding为0,以消除默认的空白 */
margin: 0;
padding: 0;
}
.dot {
width: 14px;
height: 14px;
border-radius: 50%;
margin-top: -12px;
margin-bottom: 15px;
margin-right: 10px;
}
</style>
</head>
<h1 style="color: white; text-align: center;">VBA 代码高亮</h1>
<h3 style="color: white; text-align: center;">制作:与或非</h3>
<div class="container" >
<pre class="abc" style="padding-left: 30px;">
<div class="containers" style="margin-left: 40px;">
<div class="dot" style="margin-left: -35px; background-color: #FF3B30;"></div><div class="dot" style="background-color: #FFD60A;"></div><div
class="dot" style="background-color: #34C759;"></div>
</div><code style="outline: none; background-color: rgba(0, 0, 0, 0); " contenteditable="true" id="left-code" class="abc">'示例代码
Option Explicit
#Const DebugMode = True
Sub ExampleCode()
Dim myString As String
Const myConstant As Integer = 5
Dim myNumber As Integer
arr = Array("微信", "M","n", "j", "u", "n", 9, 5, 2, 7)
brr = [{"qq", 2, 4, 5, 1, 3, 5, 2, 4, 1}]
set rng = [A1 : A10]
num = 1 * 2 + 3 - 4 / 5.123 : num 2 = num mod 2
aDate = # 2024/4/9 # : myString = "Hello" : myNumber = 10
Rem 标记
debug.print IIf(qq = "245135241", True, False)
str = "测试" & _
"换行"
If myNumber > myConstant Then
MsgBox myString & " World!"
Else
MsgBox "Number is not greater than constant."
End If
End Sub
</code>
</pre>
<pre class="line-numbers">
<div class="containers">
<div class="dot" style="margin-left: -25px; background-color: #FF3B30;"></div><div class="dot" style="background-color: #FFD60A;"></div><div class="dot" style="background-color: #34C759;"></div>
</div><code class="language-VBA" id="right-code">'示例代码
Option Explicit
#Const DebugMode = True
Sub ExampleCode()
Dim myString As String
Const myConstant As Integer = 5
Dim myNumber As Integer
arr = Array("微信", "M","n", "j", "u", "n", 9, 5, 2, 7)
brr = [{"qq", 2, 4, 5, 1, 3, 5, 2, 4, 1}]
set rng = [A1 : A10]
num = 1 * 2 + 3 - 4 / 5.123 : num 2 = num mod 2
aDate = # 2024/4/9 # : myString = "Hello" : myNumber = 10
Rem 标记
debug.print IIf(qq = "245135241", True, False)
str = "测试" & _
"换行"
If myNumber > myConstant Then
MsgBox myString & " World!"
Else
MsgBox "Number is not greater than constant."
End If
End Sub
</code></pre>
</div>
<script>
// 绑定点击事件
document.addEventListener('DOMContentLoaded', function() {
// 选择按钮元素
var button = document.querySelector('.copy-to-clipboard-button');
// 添加点击事件监听器
button.addEventListener('click', function(event) {
// 获取右边窗口的内容
var rightContent = document.getElementById('right-code').parentElement;
// 删除 box-shadow 属性
var originalBoxShadow = rightContent.style.boxShadow;
rightContent.style.boxShadow = 'none';
// 使用 html2canvas 将右边窗口内容转换为图片
html2canvas(rightContent, {
backgroundColor: null, // 保留背景
logging: true, // 输出日志
allowTaint: true // 允许加载跨域的图片
}).then(function (canvas) {
// 将图片转换为 Blob 对象
canvas.toBlob(function (blob) {
// 将 Blob 对象添加到剪贴板
if (navigator.clipboard && navigator.clipboard.write) {
navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob
})
]).then(function () {
console.log('图像已成功复制到剪贴板!');
}, function (error) {
console.error('无法写入剪贴板。错误:', error);
}).finally(function () {
// 恢复原来的 box-shadow 属性
rightContent.style.boxShadow = originalBoxShadow;
});
} else {
console.error('不支持剪贴板API.');
}
});
}).catch(function (error) {
console.error('html2canvas操作过程中发生错误:', error);
// 恢复原来的 box-shadow 属性
rightContent.style.boxShadow = originalBoxShadow;
});
});
});
</script>
<script>
document.getElementById('left-code').addEventListener('input', function () {
// 获取左边窗口的内容
var leftContent = this.textContent;
// 更新右边窗口的内容
document.getElementById('right-code').textContent = leftContent;
// 刷新 Prism 样式
Prism.highlightElement(document.getElementById('right-code'));
});
//tab键
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('left-code').addEventListener('keydown', function (event) {
// 检查按下的键是否为 Tab 键
if (event.keyCode === 9) {
// 阻止默认行为,即不输入实际的 TAB 字符
event.preventDefault();
// 获取当前光标位置和文本内容
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var cursorPosition = range.startOffset;
var textNode = range.startContainer;
var text = textNode.textContent;
// 在当前光标位置插入四个空格
var newText = text.substring(0, cursorPosition) + " " + text.substring(cursorPosition);
// 更新元素的值和光标位置
textNode.textContent = newText;
range.setStart(textNode, cursorPosition + 4);
range.setEnd(textNode, cursorPosition + 4);
selection.removeAllRanges();
selection.addRange(range);
}
});
});
</script>
</body>
</html>