#语法高亮 #编辑器 #等宽字体 #Unicode字符 #静态站点生成器 #Web

ultron

一个专注于正确显示多宽字符的基于Web的文本编辑器

10个版本

0.2.6 2021年10月7日
0.2.5 2021年9月21日
0.1.2 2021年9月8日
0.1.0 2020年10月14日

#1466 in 文本处理

42 每月下载量

MIT许可证

2MB
27K SLoC

Perl 5K SLoC // 0.1% comments Rust 3K SLoC // 0.2% comments D 2.5K SLoC // 0.1% comments Objective-C++ 2.5K SLoC // 0.1% comments C++ 2.5K SLoC // 0.1% comments Python 1.5K SLoC // 0.6% comments JavaScript 1.5K SLoC // 0.5% comments Java 1K SLoC // 0.5% comments C# 822 SLoC // 0.7% comments Ruby 678 SLoC // 0.5% comments Scala 622 SLoC // 0.6% comments Shell 617 SLoC // 0.7% comments Go 605 SLoC // 0.8% comments Erlang 588 SLoC // 0.9% comments Clojure 513 SLoC // 0.7% comments Objective-C 503 SLoC // 0.5% comments OCaml 485 SLoC // 0.2% comments Lua 458 SLoC // 0.6% comments C 334 SLoC // 0.6% comments PHP 324 SLoC // 0.8% comments Groovy 293 SLoC // 0.2% comments ASP 290 SLoC // 0.7% comments TCL 211 SLoC // 0.4% comments Batch 127 SLoC // 0.8% comments R 81 SLoC // 0.8% comments Common Lisp 51 SLoC // 0.7% comments Haskell 43 SLoC // 0.7% comments SQL 27 SLoC // 0.7% comments Ruby HTML 23 SLoC Pascal 8 SLoC // 0.6% comments

Ultron

Ultron是一个完全用Rust编写的基于Web的等宽文本编辑器,具有语法高亮功能。

Screenshot

特性

  • 真正的等宽GUI,支持多宽字符,如CJK和Unicode框绘制。
  • 快速,打字延迟约为15ms,光标移动约为10ms。
  • 块模式
    • 允许您进行矩形选择
  • 虚拟编辑
    • 允许您在编辑器的任何地方输入,即使在没有行的区域

静态站点生成器的语法高亮器

Ultron附带ultron-ssgcrate,可用于静态站点生成器的语法高亮。


use ultron_ssg;

fn main() {
    let content = r#"
        fn main(){
            println!("hello from ultron-ssg");
        }
    "#
    let html =
        ultron_ssg::render_to_string(content, "rust", Some("gruvbox-dark"));
    std::fs::create_dir_all("out").expect("must create dir");
    std::fs::write("out/hello.html", html).expect("must write to file");
}

用例

我编写了这个代码编辑器,因为我有非常具体的用例

  • GUI编辑器的真实等宽,支持多宽字符,使得它们与其他行的字符在字符宽度上对齐。

GUI编辑器在处理CJK字符或任何超过1个字符宽的Unicode字符时,对等宽字体的处理并不好。

终端没有问题显示它们。GUI中的字体似乎会根据字符的排列紧密程度调整字符。这对于阅读很好,但不适用于Ascii图表。

解决方案是将每个字符包裹在一个<div>中,以强制它们在一个单元格中。宽字符将使用<div class"wide_{n}">,其中n是unicode_width。这个字符的样式将使用正常宽度的倍数来设置。

构建和运行编辑器

git clone https://github.com/ivanceras/ultron.git

cd ultron
./serve.sh

然后,导航到https://127.0.0.1:4002

演示

链接

Become a patron

依赖项

~15–26MB
~379K SLoC