Repository navigation
Auto complete
Orange46707 Eery edited this page Jun 21, 2026
·
2 revisions
Auto-complete 模块是从 NetLeaf 主库分离出来的独立库,用于自动补全内联HTML/Vue代码中缺失的编码声明,以及自动引入Vue库。
版本: 与主库共用版本号
平台支持:
- ✅ Windows
- ✅ Linux
- ✅ macOS
自动检测HTML中是否缺少 <meta charset> 和 <meta name="viewport"> 标签,如果缺少则自动添加。
- 根据程序设置的统一编码格式补全charset
- 智能识别标签位置,在合适的地方插入
检测HTML中是否包含Vue代码但没有引入Vue库,如果是则自动添加CDN引用。
- 支持多种CDN:unpkg、cdnjs、jsdelivr、本地文件
- 支持指定Vue版本
- 智能检测:需要检测到至少2种Vue模式才会添加引用
支持多种启用/禁用方式:
- 整数:
1(启用),0(禁用) - 字符串:
"true","false","on","off","yes","no"(大小写不敏感)
charset和Vue功能可以单独启用或禁用:
nl_autocomplete_enable_feature(NL_AUTOCOMPLETE_FEATURE_CHARSET); // 启用charset
nl_autocomplete_disable_feature(NL_AUTOCOMPLETE_FEATURE_VUE); // 禁用Vue| 函数 | 说明 |
|---|---|
nl_autocomplete_init() |
初始化模块 |
nl_autocomplete_is_available() |
检查模块是否可用 |
nl_autocomplete_version() |
获取模块版本 |
| 函数 | 说明 |
|---|---|
nl_autocomplete_enable(int) |
启用/禁用模块(整数) |
nl_autocomplete_enable_ex(const char*) |
启用/禁用模块(字符串) |
nl_autocomplete_is_enabled() |
检查模块是否启用 |
| 函数 | 说明 |
|---|---|
nl_autocomplete_enable_feature(nl_autocomplete_feature_t) |
启用指定功能 |
nl_autocomplete_disable_feature(nl_autocomplete_feature_t) |
禁用指定功能 |
nl_autocomplete_enable_feature_ex(nl_autocomplete_feature_t, const char*) |
字符串方式启用/禁用 |
nl_autocomplete_is_feature_enabled(nl_autocomplete_feature_t) |
检查功能是否启用 |
| 函数 | 说明 |
|---|---|
nl_autocomplete_set_encoding(const char*) |
设置默认编码 |
nl_autocomplete_get_encoding() |
获取当前编码 |
| 函数 | 说明 |
|---|---|
nl_charset_complete_create() |
创建charset补全上下文 |
nl_charset_complete_process() |
处理HTML并补全charset |
nl_charset_complete_destroy() |
销毁上下文 |
nl_complete_charset() |
快速补全charset |
| 函数 | 说明 |
|---|---|
nl_vue_import_create() |
创建Vue引入上下文 |
nl_vue_import_process() |
处理HTML并添加Vue引用 |
nl_vue_import_process_version() |
指定版本处理 |
nl_vue_import_destroy() |
销毁上下文 |
nl_import_vue() |
快速添加Vue引用 |
nl_html_has_vue_code() |
检测是否包含Vue代码 |
nl_html_has_vue_import() |
检测是否已有Vue引用 |
| 函数 | 说明 |
|---|---|
nl_autocomplete_process_html() |
使用所有启用功能处理HTML |
#include "netleaf_autocomplete.h"
int main() {
// 初始化模块
nl_autocomplete_init();
// 设置统一编码格式
nl_autocomplete_set_encoding("UTF-8");
// 启用模块(支持字符串)
nl_autocomplete_enable_ex("true");
// 单独控制功能
nl_autocomplete_enable_feature(NL_AUTOCOMPLETE_FEATURE_CHARSET);
nl_autocomplete_disable_feature(NL_AUTOCOMPLETE_FEATURE_VUE);
// 处理HTML
const char* html = "<html><body>Hello</body></html>";
char* result = nl_autocomplete_process_html(html, strlen(html), NULL);
// 输出: <html><head><meta charset="UTF-8">...</head><body>Hello</body></html>
free(result);
return 0;
}模块会检测以下Vue代码模式:
new Vue(Vue.createAppcreateApp(ref(reactive(computed(watch(watchEffect(onMounted(onUpdated(onUnmounted(v-ifv-forv-showv-bindv-model-
{{和}} :class:style@click@submitvue-appid="app"
检测到至少2种模式才会认为是Vue代码。
模块会检测以下Vue引用模式:
vue.jsvue.min.jsvue.global.jsvue.runtime.jscdn.jsdelivr.net/npm/vueunpkg.com/vue@cdnjs.cloudflare.com/ajax/libs/vue/vuejs.org/
| 类型 | URL模板 |
|---|---|
NL_VUE_CDN_UNPKG |
https://unpkg.com/vue@{version}/dist/vue.global.js |
NL_VUE_CDN_CDNJS |
https://cdnjs.cloudflare.com/ajax/libs/vue/{version}/vue.min.js |
NL_VUE_CDN_JSDELIVR |
https://cdn.jsdelivr.net/npm/vue@{version}/dist/vue.global.js |
NL_VUE_CDN_LOCAL |
./vue.global.js |
BUILD_AUTOCOMPLETE=ON # 默认启用- 该模块是独立库,可以单独编译和加载
- 如果模块未加载,相关功能不可用,但不会影响主库运行
- 建议在程序启动时初始化模块
- 编码设置会影响所有charset补全操作
许可声明 / License Notice 本仓库基于 MIT 协议开源。如果您使用了本项目,请保留原作者署名并附带 LICENSE 文件
This repository is open-sourced under the MIT License. If you use this project, please retain the original author's attribution and include the LICENSE file.
- Auto-complete - 自动补全charset和Vue引入
- Auto-route - 自动路由建议
- ErrorPage - 自定义错误页面模板
- IPC - 进程间通讯服务
- LinkAgg - 同端口链路聚合
- Lang - 多语言错误消息
- Vue - Vue.js后端支持
- Extension - 扩展库开发指南
- TLS - TLS/SSL 加密扩展
- MQTT - MQTT v5.0 协议客户端
- MQTT-Server - MQTT v5.0 协议服务端(Broker)
作者: 508364
版本: 2.4.2
许可: MIT License