1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-12-23 13:41:23 +00:00

Markdown formatting

This commit is contained in:
Felix Ableitner 2024-12-18 14:55:10 +01:00
parent 7acc38df70
commit 56a6ba9b8b
3 changed files with 302 additions and 23 deletions

298
Cargo.lock generated
View file

@ -125,6 +125,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys 0.59.0",
]
[[package]]
name = "any_spawner"
version = "0.2.0"
@ -529,6 +578,46 @@ dependencies = [
"inout",
]
[[package]]
name = "clap"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim 0.11.1",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.90",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "clokwerk"
version = "0.4.0"
@ -555,6 +644,12 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186dce98367766de751c42c4f03970fc60fc012296e706ccbb9d5df9b6c1e271"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@ -1093,7 +1188,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d3041965b7a63e70447ec818a46b1e5297f7fcae3058356d226c02750c4e6cb"
dependencies = [
"nu-ansi-term",
"nu-ansi-term 0.50.1",
]
[[package]]
@ -1346,6 +1441,50 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "fmtm"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67821986c4f702a48182ce7f6a6053edf3bb3914ae5233deca7f43fb7d0cad21"
dependencies = [
"anyhow",
"clap",
"fmtm_ytmimi_markdown_fmt",
"fmtt",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "fmtm_ytmimi_markdown_fmt"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa29f82bcbac43afa28064b265f4568cd243c5ea386e73d4a9ff3a7081905e95"
dependencies = [
"itertools 0.13.0",
"pulldown-cmark",
"textwrap",
"tracing",
"unicode-segmentation",
"unicode-width",
]
[[package]]
name = "fmtt"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8bf46ce300930c5057e54c2d538e079733abedc30eda1afd48770ed6b2cf9f0"
dependencies = [
"anyhow",
"clap",
"regex",
"serde",
"serde_json",
"tailcall",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -1843,6 +1982,7 @@ dependencies = [
"doku",
"enum_delegate",
"env_logger",
"fmtm",
"futures",
"getrandom",
"gloo-net",
@ -2098,6 +2238,12 @@ version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itertools"
version = "0.10.5"
@ -2593,6 +2739,15 @@ dependencies = [
"markdown-it",
]
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matchit"
version = "0.7.3"
@ -2753,6 +2908,16 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "nu-ansi-term"
version = "0.50.1"
@ -2920,6 +3085,12 @@ dependencies = [
"hashbrown 0.14.5",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking"
version = "2.2.1"
@ -3250,6 +3421,17 @@ dependencies = [
"psl-types",
]
[[package]]
name = "pulldown-cmark"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "679341d22c78c6c649893cbd6c3278dcbe9fc4faa62fea3a9296ae2b50c14625"
dependencies = [
"bitflags 2.6.0",
"memchr",
"unicase",
]
[[package]]
name = "quanta"
version = "0.12.4"
@ -3484,8 +3666,17 @@ checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
@ -3496,9 +3687,15 @@ checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.5"
@ -3962,6 +4159,15 @@ dependencies = [
"digest",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -4034,6 +4240,12 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "smawk"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
[[package]]
name = "socket2"
version = "0.5.8"
@ -4164,7 +4376,7 @@ dependencies = [
"fnv",
"once_cell",
"plist",
"regex-syntax",
"regex-syntax 0.8.5",
"serde",
"serde_derive",
"serde_json",
@ -4232,6 +4444,26 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417"
[[package]]
name = "tailcall"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "695cb8728beab065fe29d03ae105a23c7cdd6e8d9ed5fd717a0bbbd8c56ab0bb"
dependencies = [
"tailcall-impl",
]
[[package]]
name = "tailcall-impl"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10b7bf224f4cbce8706b34f6fd1db63bc9b1fa933a3b9e6eee2e78a660416e13"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "tempfile"
version = "3.14.0"
@ -4245,6 +4477,17 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "textwrap"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9"
dependencies = [
"smawk",
"unicode-linebreak",
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.69"
@ -4285,6 +4528,16 @@ dependencies = [
"syn 2.0.90",
]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "throw_error"
version = "0.2.0"
@ -4553,6 +4806,23 @@ dependencies = [
"once_cell",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
dependencies = [
"matchers",
"nu-ansi-term 0.46.0",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
]
[[package]]
name = "triomphe"
version = "0.1.11"
@ -4639,6 +4909,12 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "unicode-linebreak"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f"
[[package]]
name = "unicode-normalization"
version = "0.1.24"
@ -4654,6 +4930,12 @@ version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493"
[[package]]
name = "unicode-width"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-xid"
version = "0.2.6"
@ -4696,6 +4978,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "uuid"
version = "1.11.0"

View file

@ -106,6 +106,7 @@ anyhow = "1.0.94"
include_dir = "0.7.4"
mime_guess = "2.0.5"
clokwerk = "0.4.0"
fmtm = "0.0.3"
[dev-dependencies]
pretty_assertions = "1.4.1"

View file

@ -14,22 +14,9 @@ use crate::{
common::{
utils::{extract_domain, http_protocol_str},
validation::can_edit_article,
ApiConflict,
ApproveArticleForm,
ArticleView,
CreateArticleForm,
DbArticle,
DbEdit,
DbInstance,
DeleteConflictForm,
EditArticleForm,
EditVersion,
ForkArticleForm,
GetArticleForm,
ListArticlesForm,
LocalUserView,
ProtectArticleForm,
ResolveObject,
ApiConflict, ApproveArticleForm, ArticleView, CreateArticleForm, DbArticle, DbEdit,
DbInstance, DeleteConflictForm, EditArticleForm, EditVersion, ForkArticleForm,
GetArticleForm, ListArticlesForm, LocalUserView, ProtectArticleForm, ResolveObject,
SearchArticleForm,
},
};
@ -126,10 +113,13 @@ pub(in crate::backend::api) async fn edit_article(
return Err(anyhow!("Links to local instance don't work over federation").into());
}
// Markdown formatting
let new_text = fmtm::format(&edit_form.new_text, Some(80))?;
if edit_form.previous_version_id == original_article.latest_version {
// No intermediate changes, simply submit new version
submit_article_update(
edit_form.new_text.clone(),
new_text.clone(),
edit_form.summary.clone(),
edit_form.previous_version_id,
&original_article.article,
@ -143,7 +133,7 @@ pub(in crate::backend::api) async fn edit_article(
// version and generate a diff to find out what exactly has changed.
let edits = DbEdit::list_for_article(original_article.article.id, &data)?;
let ancestor = generate_article_version(&edits, &edit_form.previous_version_id)?;
let patch = create_patch(&ancestor, &edit_form.new_text);
let patch = create_patch(&ancestor, &new_text);
let previous_version = DbEdit::read(&edit_form.previous_version_id, &data)?;
let form = DbConflictForm {