Skip to content

Commit 39d2659

Browse files
authored
Refactoring and new language support
- Automatically generate language options - Add support for Kotlin
2 parents 4ff2225 + 000a38e commit 39d2659

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+528
-499
lines changed

.babelrc

+21-12
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,49 @@
44
"prismjs",
55
{
66
"languages": [
7+
// Programming Languages
78
"c",
89
"cpp",
910
"csharp",
1011
"go",
1112
"java",
13+
"kotlin",
14+
"perl",
1215
"python",
16+
"ruby",
1317
"rust",
1418
"swift",
15-
"perl",
16-
"ruby",
17-
"html",
19+
// Web Development
1820
"css",
21+
"html",
1922
"javascript",
20-
"typescript",
2123
"php",
24+
"typescript",
25+
// Scripting Language
2226
"bash",
23-
"powershell",
2427
"batch",
2528
"lua",
26-
"xml",
29+
"powershell",
30+
// Markup Language
2731
"json",
28-
"yaml",
29-
"markdown",
3032
"latex",
31-
"makefile",
33+
"markdown",
34+
"xml",
35+
"yaml",
36+
// Configuration Language
3237
"cmake",
3338
"docker",
39+
"makefile",
40+
// Database
3441
"sql",
35-
"nasm",
42+
// Assembly Language
3643
"llvm",
37-
"verilog",
44+
"nasm",
45+
// Others
3846
"diff",
47+
"glsl",
3948
"matlab",
40-
"glsl"
49+
"verilog"
4150
],
4251
"plugins": [
4352
"line-numbers",

.github/workflows/static.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ jobs:
3333
run: |
3434
npm install
3535
36+
- name: Install Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.x"
40+
3641
- name: Add Secret Files
3742
env:
3843
NOTIFICATION: ${{ secrets.NOTIFICATION }}
3944
STATISTICS: ${{ secrets.STATISTICS }}
4045
SUPPORT: ${{ secrets.SUPPORT }}
4146
run: |
4247
python scripts/pre_deploy.py
43-
44-
- name: Install Python
45-
uses: actions/setup-python@v5
46-
with:
47-
python-version: "3.x"
4848
4949
- name: Build Project
5050
run: |

README.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Copyright © Tony's Studio 2023 - 2025
44

55
---
66

7+
[![Build](https://github.com/Lord-Turmoil/CodePaste/actions/workflows/static.yml/badge.svg?branch=main)](https://github.com/Lord-Turmoil/CodePaste/actions/workflows/static.yml)
8+
79
## Description
810

9-
This tool provides you the ability to create highlighted code for Microsoft Office, mainly for Word and PowerPoint. You can use it to create a beautiful code block in your document or presentation.
11+
This tool provides you the ability to create highlighted code block for Microsoft Office, mainly for Word and PowerPoint. You can use it to create a beautiful code block in your document or presentation.
1012

1113
### Try it now!
1214

@@ -17,38 +19,53 @@ This tool provides you the ability to create highlighted code for Microsoft Offi
1719

1820
## Development
1921

20-
If you find Code Paste useful and want to host it on your website, this section will be useful.
21-
22-
> **NOTICE:** I'm glad some of you have already hosted Code Paste on you own server, but forgot to remove the analytics scripts and my COS links. It's partly due to my bad project structure, so I refactored it to separate these configurations. Besides, **I would appreciate it if you mention my repository in your website**.🙏
23-
24-
Feel free to contribute to this project. You can report bugs, suggest new features, or even submit a pull request. 😊
22+
If you find Code Paste useful and want to host it on your own, this section will be useful. By the way, feel free to contribute to this project. You can report bugs, suggest new features, or even submit a pull request. 😊
2523

2624
### Quick Start
2725

28-
Code Paste is written in native HTML, CSS and JavaScript with npm and Webpack. Also with posthtml for the `<module>` tag. To start development, clone the repo first, then install required packages.
26+
Code Paste is written in native HTML, CSS and JavaScript. To start development, clone the repo first, then install required packages.
2927

3028
```bash
3129
npm install
32-
npm run init # initialize placeholder
30+
npm run init # initialize placeholder files
3331
```
3432

3533
Then, you can run the project. There are three options for this.
3634

3735
```bash
3836
npm run build # build for production
39-
npm run dev # build for development
40-
npm run watch # build for development and watch for changes
37+
npm run dev # build for development and watch for changes
4138
```
4239

4340
> To preview the project locally, I recommend using [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) plugin for Visual Studio Code. Just open `dist/index.html` after your local server is on.
4441
42+
### Code Samples
43+
44+
Code Paste provides sample code for each supported language. The supported languages are listed in `languages/lang.yml`, grouped by their categories. All the code samples are placed under `languages/samples/` directory.
45+
46+
> [!NOTE]
47+
>
48+
> The display order of the language options in the final webpage is exactly the same as that in `lang.yml`.
49+
50+
Managing language options in HTML and JavaScript is tedious, so there is a script to automatically generate related code. You should run this command after modifying the language list or adding new samples. This will generate `src/js/samples.js` and `src/views/components/languages.html`.
51+
52+
```bash
53+
npm run sample
54+
```
55+
56+
To add a new language, first add it to `languages/lang.yml`. In the suitable category, add a new list item in the format of `key value`, where `key` is the language id of [Prism.js](https://prismjs.com/#supported-languages), and the `value` is the display name of the language in the select box. Then, create a new file `{key}.txt` under `languages/samples/` and write your sample code in it. Finally, add this language to `.babelrc` so that it can be correctly loaded.
57+
58+
> [!WARNING]
59+
>
60+
> `npm run dev` will not watch for changes under `languages/` directory. So you have to manually update it.
61+
4562
### Customization
4663

47-
Since I removed sensitive information from the project, you need to run `npm run init` to create placeholder files even if you don't need them. They are under `src/views/components/`, where you can find a `.gitignore` that ignores them.
64+
Since I removed sensitive information from the project, you need to run `npm run init` to create placeholder files even if you don't need them. These files are placed under `src/views/components/`.
4865

4966
**Analytics**
5067

51-
In file `statistics.html`, and place all your scripts into it. If you don't need them, just leave this file empty. The file should look like this.
68+
In file `statistics.html`, and place all your scripts into it. If you don't need them, just leave this file empty. Here is an example for this file.
5269

5370
```html
5471
<!-- Clarity -->
@@ -59,7 +76,7 @@ In file `statistics.html`, and place all your scripts into it. If you don't need
5976
y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);
6077
})(window, document, "clarity", "script", "***key***");
6178
</script>
62-
<!-- Baidu Statistics -->
79+
<!-- Baidu Analytics -->
6380
<script>
6481
var _hmt = _hmt || [];
6582
(function () {

languages/lang.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Programming Languages:
2+
- c C
3+
- cpp C++
4+
- csharp C#
5+
- go Go
6+
- java Java
7+
- kotlin Kotlin
8+
- perl Perl
9+
- python Python
10+
- ruby Ruby
11+
- rust Rust
12+
- swift Swift
13+
Web Development:
14+
- css CSS
15+
- html HTML
16+
- javascript JavaScript
17+
- php PHP
18+
- typescript TypeScript
19+
Scripting Language:
20+
- bash Bash
21+
- batch Batch
22+
- lua Lua
23+
- powershell PowerShell
24+
Markup Language:
25+
- json JSON
26+
- latex LaTeX
27+
- markdown Markdown
28+
- xml XML
29+
- yaml YAML
30+
Configuration Language:
31+
- cmake CMake
32+
- docker Docker
33+
- makefile Makefile
34+
Database:
35+
- sql SQL
36+
Assembly Language:
37+
- llvm LLVM
38+
- nasm NASM
39+
Others:
40+
- diff Diff
41+
- glsl GLSL
42+
- matlab MATLAB
43+
- verilog Verilog

languages/samples/bash.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
name="John"
4+
age=30
5+
6+
if [ $age -lt 18 ]; then
7+
echo "$name is a minor."
8+
else
9+
echo "$name is an adult."
10+
fi

languages/samples/batch.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@echo off
2+
3+
set name=John
4+
set age=30
5+
6+
if %age% lss 18 (
7+
echo %name% is a minor.
8+
) else (
9+
echo %name% is an adult.
10+
)

languages/samples/c.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int num = 10;
5+
int* ptr = &num;
6+
7+
printf("The value of num is %d\n", num);
8+
printf("The value of ptr is %p\n", ptr);
9+
printf("The value that ptr points to is %d\n", *ptr);
10+
11+
return 0;
12+
}

languages/samples/cmake.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.26)
2+
project(MIoC)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
# Add all source files
7+
file(GLOB_RECURSE SRC_LIST CONFIGURE_DEPENDS src/*.cpp)
8+
9+
# Add final target.
10+
add_executable(${CMAKE_PROJECT_NAME} ${SRC_LIST})
11+
12+
# dependency
13+
add_subdirectory(mioc)
14+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE mioc)

languages/samples/cpp.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
3+
int main() {
4+
std::cout << "Hello, there!" << std::endl;
5+
std::cout << "General Grievous!" << std::endl;
6+
7+
return 0;
8+
}

languages/samples/csharp.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Startup
2+
{
3+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4+
{
5+
app.UseRouting();
6+
app.UseCors(CorsOptions.CorsPolicyName);
7+
app.UseEndpoints(endpoints => {
8+
endpoints.MapControllers();
9+
endpoints.MapSwagger();
10+
});
11+
}
12+
}

languages/samples/css.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.action-wrapper .action {
2+
width: 50px;
3+
height: 50px;
4+
display: flex;
5+
justify-content: center;
6+
border-radius: 50%;
7+
align-self: center;
8+
cursor: pointer;
9+
transition: 0.3s;
10+
}

languages/samples/diff.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Jedi Order
2+
+ Sith Empire
3+
- Kamino
4+
- Alderaan
5+
+ Mandalore

languages/samples/docker.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PatBoot Dockerfile
2+
3+
FROM openjdk:17-jdk-slim
4+
5+
ARG VERSION
6+
7+
COPY target/PatBoot-${VERSION}.jar /application.jar
8+
9+
EXPOSE 8080
10+
11+
CMD ["java", "-jar", "/application.jar"]

languages/samples/glsl.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 450 core
2+
3+
layout(location = 0) out vec4 o_Color;
4+
5+
struct VertexOutput
6+
{
7+
vec4 Color;
8+
};
9+
10+
layout (location = 0) in VertexOutput Input;
11+
12+
void main()
13+
{
14+
o_Color = Input.Color;
15+
}

languages/samples/go.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func add(a int, b int) int {
6+
return a + b
7+
}
8+
9+
func main() {
10+
sum := add(3, 4)
11+
fmt.Println("Sum:", sum)
12+
}

languages/samples/html.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Hello, world!</title>
6+
</head>
7+
<body>
8+
<h1>Hello, world!</h1>
9+
</body>
10+
</html>

languages/samples/java.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
int a = 5;
4+
int b = 10;
5+
int sum = add(a, b);
6+
System.out.println("Sum: " + sum);
7+
}
8+
9+
public static int add(int a, int b) {
10+
return a + b;
11+
}
12+
}

languages/samples/javascript.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function fibonacci(n) {
2+
let a = 0, b = 1;
3+
while (a < n) {
4+
console.log(a);
5+
[a, b] = [b, a + b];
6+
}
7+
}

languages/samples/json.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "John Doe",
3+
"age": 30,
4+
"email": "[email protected]",
5+
"address": {
6+
"street": "123 Main St",
7+
"city": "Anytown",
8+
"state": "CA",
9+
"zip": "12345"
10+
}
11+
}

0 commit comments

Comments
 (0)