Skip to content

Commit a4ca9e0

Browse files
committed
Merge branches 'main' and 'main' of https://github.com/wsxiaolin/plweb2
2 parents 10ab875 + 468f7fb commit a4ca9e0

6 files changed

Lines changed: 20 additions & 570 deletions

File tree

README-zh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
## **注意事项**
3232
- 如果添加新页面,请记得在 `src/router/index.ts` 中添加路由。
33-
- **富文本渲染将来会被 wasm 版本替换**,不要向当前版本添加新功能。
3433
- 不要直接使用 localStorage 或 sessionStorage,应使用 @storage/index,并在其中注册键值。
3534
- 不要直接使用 fetch,应使用 @services/api/。
3635
- *不要直接通过路径导入静态文件*,应使用 @services/utils 中的 `getPath` 函数。

src/services/pltxt2htm/advancedParser.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@ import hljs from "highlight.js";
44
import dompurify from "dompurify";
55
// import renderMathInElement from "katex/contrib/auto-render/auto-render.js";
66

7-
async function advancedParser(text: string, host: string): Promise<string> {
7+
async function advancedParser(text: string, host: string, project: string, visitor: string,
8+
author : string, coauthors: string): Promise<string> {
89
const wasmInstance = await getWasmInstance();
910
const instanceAny: any = wasmInstance;
1011
if (!instanceAny.__advanced_parser_fn) {
1112
instanceAny.__advanced_parser_fn = wasmInstance.cwrap(
1213
"fixedadv_parser",
1314
"number",
14-
["string", "string"],
15+
["string", "string", "string", "string", "string", "string"]
1516
);
1617
}
1718
let deallocate = await getDeallocator();
1819
let char8_t_const_ptr = (
19-
instanceAny.__advanced_parser_fn as (t: string, h: string) => number
20-
)(text, host);
20+
instanceAny.__advanced_parser_fn as (_1: string, _2: string, _3: string, _4: string, _5: string, _6: string) => number
21+
)(text, host,
22+
project, visitor, author, coauthors
23+
);
2124
let result = wasmInstance.UTF8ToString(char8_t_const_ptr);
2225
deallocate(char8_t_const_ptr);
2326
return result;
2427
}
2528

26-
async function parse(source: string) {
29+
async function parse(source: string, project: string, visitor_name: string, visitor_id: string, author_name: string, author_id: string, coauthors: string[]) {
2730
console.log(source);
28-
const rawHtml = await advancedParser(source, import.meta.env.VITE_ROOT_URL);
31+
// TODO i18n support for 'None'
32+
const rawHtml = await advancedParser(source, import.meta.env.VITE_ROOT_URL, project, `<span class='RUser' data-user='${visitor_id}'>${dompurify.sanitize(visitor_name)}</span>`,
33+
`<span class='RUser' data-user='${author_id}'>${dompurify.sanitize(author_name)}</span>`, coauthors.length ? coauthors.join(",") : "None");
2934
console.log(rawHtml);
3035
if (!rawHtml) return "";
3136
const tempDiv = document.createElement("div");

src/services/pltxt2htm/deallocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export async function getDeallocator(): Promise<(ptr: number) => void> {
44
const wasmInstance = await getWasmInstance();
55
const instanceAny: any = wasmInstance;
66
if (!instanceAny.__deallocate_fn) {
7-
instanceAny.__deallocate_fn = wasmInstance.cwrap("deallocate", null, [
7+
instanceAny.__deallocate_fn = wasmInstance.cwrap("free", null, [
88
"number",
99
]);
1010
}

0 commit comments

Comments
 (0)