Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
astrale-sharp committed Jan 17, 2024
1 parent 79790a0 commit 061f6a6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 84 deletions.
143 changes: 60 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
Basic formatter for the Typst language with a future!
# Typstfmt

Powerful formatter for the Typst language with a future!

- [Typstfmt](#typstfmt)
- [Goals](#goals)
- [Roadmap and State](#roadmap-and-state)
- [Features](#features)
- [State](#state)
- [Installing](#installing)
- [Setting up a pre-commit hook](#setting-up-a-pre-commit-hook)
- [Contributing](#contributing)
- [Architecture](#architecture)
- [Main logic](#main-logic)
- [Roadmap](#roadmap)
- [Testing and visualizing](#testing-and-visualizing)
- [Installing Insta](#installing-insta)
- [Using insta here](#using-insta-here)
- [Can I see it in action?](#can-i-see-it-in-action)
- [Is that all I have to help me test?](#is-that-all-i-have-to-help-me-test)
- [Tracing](#tracing)
- [Fmttest (TO BE IMPLEMENTED)](#fmttest-to-be-implemented)
- [Architecture](#architecture)
- [Setting up a pre-commit hook](#setting-up-a-pre-commit-hook)
- [Showcase](#showcase)
- [Thanks (chronological)](#thanks-chronological)

# Goals
Expand All @@ -25,26 +21,63 @@ Basic formatter for the Typst language with a future!
- Fast, Small, configurable and embeddable library and binary!
- Good default (see [roadmap](#roadmap))

# Roadmap and State

This project is at the end of it's first big refactoring (on the refactor branch).
This was needed in order to fix long standing bug like nest raw blocks formatting and such.

- The groundwork is almost done and we have example of visit functions,
the priority is to perfect our visits functions to get awesome results and see if the current design is sufficient.
- help wanted to reintroduce the features.
- Maybe dump our config files and just read typst.toml


# Features

- Good defaults.
- Config file: run `typstfmt --make-default-config` to create a typstfmt.toml
file that you can customize!
- Tries different strategy and strives for an optimal result.
- Disable the formatting by surrounding code with `// typstfmt::off` and `//
typstfmt::on`. (Experimental and broken)

# State
typstfmt::on`.
- Config file: run `typstfmt --make-default-config` to create a typstfmt.toml
file that you can customize! Support for global configuration as well.

It's not always pretty, it sometimes break the code in math mode, but it should
be safe for code and markup.

# Installing

```sh
cargo install --git https://github.com/astrale-sharp/typstfmt.git
```

## Setting up a pre-commit hook

# 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.
- I would encourage you to take a look at the existing code and ask questions, or try to
remove todos.
A lot of the old features can probably be easily adapted.

## Using insta here

We use insta! If you don't have it installed take a look
[here](https://insta.rs/docs/cli/) (hint: use [`cargo
binstall`](https://github.com/cargo-bins/cargo-binstall))


`cargo insta test && cargo insta review`


## Architecture

1. We modify the Ast to get a Format Tree containing only relevant info.
2. We apply a preserve pass on the tree to mark nodes that should be preserved
3. We visit the tree with a &mut Writer, we have the capacity to rewind time if things didn't go well
4. We format from top to bottom with (todo) optional back and forth between a parent and it's child for maximum style


# Setting up a pre-commit hook

You can set up a git [hook](https://pre-commit.com).

Expand Down Expand Up @@ -74,79 +107,23 @@ pre-commit autoupdate

And your set up is done!

# 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](https://insta.rs/docs/cli/) (hint: use [`cargo
binstall`](https://github.com/cargo-bins/cargo-binstall))


## Using insta here

### Can I see it in action?
# Showcase

To see how it currently formats all the snippets:

- run `cargo test`, a failing test indicates one of the snippets displayed in
- run `cargo test --workspace`, 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
- @Dherse for the support and testing.
- The Typst community for the good vibes, the
interesting talks, the support and ofc, Typst.
- @jeffa5 for contributing ideas on the initial design
- @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 alignement of math block
- @aghriss for a bug fix.
- @taooceros for the alignement of math block.
1 change: 0 additions & 1 deletion lib/README.md

This file was deleted.

0 comments on commit 061f6a6

Please sign in to comment.