astrale-sharp/typstfmt
Fork: 25 Star: 255 (更新于 2024-12-04 19:10:16)
license: Apache-2.0
Language: Rust .
最后发布版本: 0.2.10 ( 2024-06-08 16:38:56)
Basic formatter for the Typst language with a future without a future 😄!
It's been a fun ride everyone but that's where I stop, feel free to fork etc.
last typst supported version is 0.10.
If I get the formatter fever again I'll probably try contributing to https://github.com/Enter-tainer/typstyle/ and you should check it out ;).
- Goals
- Features
- State
- Installing
- Contributing
- Architecture
- Testing and visualizing
- Thanks (chronological)
Goals
- Decent output under any circumstances, anything not decent should be reported as a bug!
- Fast, Small, configurable and embeddable library and binary!
- Good default (see roadmap)
Features
-
Good defaults.
-
Config file: run
typstfmt --make-default-config
to create a typstfmt.toml file that you can customize!The following lines show the contents of a simple
typstfmt.toml
file:indent_space = 2 max_line_length = 80 experimental_args_breaking_consecutive = false line_wrap = true
-
Disable the formatting by surrounding code with
// typstfmt::off
and// typstfmt::on
. (Experimental and broken)
State
It's not always pretty, it sometimes break the code in math mode, but it should be safe for code and markup.
Installing
cargo install --git https://github.com/astrale-sharp/typstfmt.git
Setting up a pre-commit hook
Optionally, you can setup a git hook to format your files at each commit:
echo "set -e
for f in \$(git ls-files --full-name -- '*.typ') ; do
typstfmt --check \$f --verbose
done" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
Now if you try to commit unformatted files, they will be caught and the commit will fail, telling you which file should be fixed.
Notes:
- You should probably avoid doing this at the moment, as typstfmt is not quite stable yet
- Be careful if you have another commit hook setup, as the command above will replace it entirely!
Contributing
- feel free to open issue or discuss! I don't have github notifications so also feel free to go ping me on the typst discord server (@Astrale).
- once discussed, you may open a PR, not before cause I'm a bit chaotic and this is wip so things change fast and I would hate it if you lost your time.
Architecture
Main logic
Since we're visiting a AST (which is a tree) we have a recursive function
visit(node: &LinkedNode, ctx: &mut Ctx)
that meets all the nodes in the tree.
It formats the children first (bottom up), then the parent decide what to do with their children.
Children have access to arbitrary context (they can know the kind of their parents, who are their siblings etc).
Roadmap
Once the test suite is large enough and the formatting is satisfying, create an abstraction to make the codebase easier to work with.
One person cannot come up with good formatting default. This will first be configurable and then with experience and opinions from the community, default will be tuned.
Testing and visualizing
Installing Insta
We use insta! If you don't have it installed take a look
here (hint: use cargo binstall
)
Using insta here
Can I see it in action?
To see how it currently formats all the snippets:
- run
cargo test
, a failing test indicates one of the snippets displayed in the next step is not formatted like this anymore. - run
show_all.sh
Is that all I have to help me test?
Tracing
Of course not! We have tracing enabled during tests!
If you're contributing tests you should add a test case under src/tests
for
instance: make_test!(call_func_empty, "#f()");
then running your tests: cargo test && cargo insta review
If the info log isn't enough, run DEBUG=true cargo test
. If you wish to pipe
to a file run NO_COLOR=true cargo test
you may also set the NOLOG
env
variable if you wish to disable logging entirely.
Fmttest (TO BE IMPLEMENTED)
On the fmttest branch, you can see the skeleton of a program that will automate finding which range, when formatted, was not valid anymore (broke the semantic of the code).
Thanks (chronological)
- @arnaudgolfouse, for the discussion, designs and the precious friendship.
- @laurmaedje, @reknih and the typst community for the good vibes, the interesting talks, the support and ofc, Typst.
- @jeffa5 for contributing ideas on the initial design
- @Andrew15-5, for the many suggestions, issues and feedback.
- @aghriss for a bug fix
- @taooceros for the alignment of math block
最近版本更新:(数据更新于 2024-09-21 19:11:34)
2024-06-08 16:38:56 0.2.10
2024-02-29 22:52:02 0.2.9
2023-12-06 17:00:46 0.2.7
2023-10-22 01:56:08 0.2.6
2023-09-21 22:03:35 0.2.5
2023-09-13 14:50:41 0.2.4
2023-09-12 16:01:32 0.2.3
2023-09-09 21:25:00 0.2.2
2023-08-31 17:36:39 0.2.1
2023-08-29 19:25:20 0.2.0
astrale-sharp/typstfmt同语言 Rust最近更新仓库
2024-12-22 08:48:41 lapce/lapce
2024-12-21 23:25:36 tw93/Pake
2024-12-19 19:31:32 dashpay/platform
2024-12-18 10:31:25 DioxusLabs/dioxus
2024-12-17 17:18:34 lanyeeee/jmcomic-downloader
2024-12-16 23:19:51 meilisearch/meilisearch