【rust】 基于rust编写wasm,实现markdown转换为html文本

server/2024/10/16 0:16:40/

文章目录

    • 背景
    • 转换预览
    • 核心代码
    • 前置依赖
      • html" title=rust>rustup换源
    • cargo本地路径修改(可选)
      • cargo换源中科大
    • html" title=wasm>wasm-pack安装

背景

尝试用html" title=rust>rust编写一款markdown转html的插件,通过html" title=wasm>wasm给html使用,不得不说体积挺小,约200K, 比go的html" title=wasm>wasm起步2MB看着舒服点。

  • 不过go的配置和换源比较方便。
  • html" title=rust>rust需要给html" title=rust>rustup, cargo换源, 安装链接器

使用 html" title=wasm>wasm-pack build --target web打包可生成js和html" title=wasm>wasm如下(ts可以直接删):
4核的服务器上build总共8秒, 要是去掉html" title=wasm>wasm-opt估计1秒多搞定,比go还快了。
在这里插入图片描述

转换预览

在这里插入图片描述

核心代码

html" title=rust>rust">use html" title=wasm>wasm_bindgen::prelude::*;
use pulldown_cmark::{Parser, html};#[html" title=wasm>wasm_bindgen]
pub fn markdown_to_html(markdown: &str) -> String {let mut html_output = String::new();let parser = Parser::new(markdown);html::push_html(&mut html_output, parser);html_output
}

前置依赖

html" title=rust>rustup_27">html" title=rust>rustup换源

export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/html" title=rust>rustup"

cargo本地路径修改(可选)

export RUSTUP_HOME= H O M E / o p t / r u s t / r u s t u p e x p o r t C A R G O H O M E = HOME/opt/html" title=rust>rust/html" title=rust>rustup export CARGO_HOME= html">HOME/opt/rust/rustupexportCARGOHOME=HOME/opt/html" title=rust>rust/cargo

cargo换源中科大

tee > ~/.cargo/config << EOF
[source.crates-io]
replace-with = 'rsproxy'[source.rsproxy]  
registry = "https://rsproxy.cn/crates.io-index"
EOF

html" title=wasm>wasmpack_47">html" title=wasm>wasm-pack安装

html" title=wasm>wasm-pack build的时候会调用html" title=wasm>wasm-opt文件, 自动从gayhub下载, 当然有可能下载不下来,原因你懂的。

cargo install html" title=wasm>wasm-pack

http://www.ppmy.cn/server/124899.html

相关文章

Java五子棋

目录 一&#xff1a;案例要求&#xff1a; 二&#xff1a;代码&#xff1a; 三&#xff1a;结果&#xff1a; 一&#xff1a;案例要求&#xff1a; 实现一个控制台下五子棋的程序。用一个二维数组模拟一个15*15路的五子棋棋盘&#xff0c;把每个元素赋值位“┼”可以画出棋…

利用瓶盖酒瓶换酒(算法)

* 例题讲解&#xff1a;例题1:阿里钉钉22届暑期实习 * 现有x瓶啤酒&#xff0c;每3个空瓶子换一瓶啤酒&#xff0c;每7个瓶盖子也可以换一瓶啤 * 酒&#xff0c;问最后可以喝多少瓶啤酒。 解题&#xff08;Java&#xff09; package 算法.规律题;import java.util.Scanner;/*…

H.264编解码工具 - NVIDIA CUDA

一、简介 NVIDIA CUDA编解码是一项采用NVIDIA图形处理器(GPU)来加速视频编码和解码的技术。CUDA(Compute Unified Device Architecture)是一种并行计算平台和编程模型,允许开发者使用GPU来进行通用计算。 优点: 加速编解码速度:CUDA编解码利用GPU的并行处理能力,可以…

第L2周:机器学习|线性回归模型 LinearRegression:2. 多元线性回归模型

本文为365天深度学习训练营 中的学习记录博客原作者&#xff1a;K同学啊 任务&#xff1a; ●1. 学习本文的多元线形回归模型。 ●2. 参考文本预测花瓣宽度的方法&#xff0c;选用其他三个变量来预测花瓣长度。 一、多元线性回归 简单线性回归&#xff1a;影响 Y 的因素唯一&…

先进制造aps专题二十六 基于强化学习的人工智能ai生产排程aps模型简介

基于强化学习的人工智能ai生产排程模型简介 人工智能ai能不能做生产排程&#xff1f; 答案是肯定的。 ai的算法分两类&#xff0c;一类是学习&#xff0c;一类是搜索。 而生产排程问题&#xff0c;它是一个搜索问题&#xff0c;本质上&#xff0c;它和下围棋是一样的 我们…

sql中的regexp与like区别

sql中的regexp与like区别 1、REGEXP2、LIKE3、区别与选择 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; 1、REGEXP 用途&#xff1a;高级字符串匹配&#xff0c;使用正则表达式。特点&#xff1a;灵活性强&#xff0c;能进行复杂模式匹配…

简单PCL库读文件(linux vscode编译)

#include <pcl/io/pcd_io.h> #include <pcl/point_types.h> #include <pcl/common/common.h> #include <iostream>int main(int argc, char** argv) {if (argc ! 2) {std::cerr << "请指定 PCD 文件路径" << std::endl;return -…

JavaCV 实现视频链接截取封面工具

引入必要依赖 <!--JavaCV--> <dependency><groupId>org.bytedeco</groupId><artifactId>javacv-platform</artifactId><version>1.5.7</version> </dependency> <dependency><groupId>cn.hutool</groupI…