A parser for Cosense (formerly Scrapbox) markup syntax that produces a typed AST.
[dependencies]
cosy = "0.1"To enable JSON serialization of the AST via serde:
[dependencies]
cosy = { version = "0.1", features = ["serde"] }use cosy::ast::{BlockContent, Node};
let doc = cosy::parse("Hello [* world]! See [https://example.com].", &()).unwrap();
for block in &doc {
if let BlockContent::Line(nodes) = &block.content {
for node in nodes {
println!("{node:?}");
}
}
}Implement CosyParserExtension to inject your own bracket syntax:
use cosy::CosyParserExtension;
#[derive(Debug, PartialEq)]
enum MySyntax { Highlight(String) }
struct MyExt;
impl CosyParserExtension for MyExt {
type Output = MySyntax;
fn parse_bracket(&self, content: &str) -> Option<MySyntax> {
content.strip_prefix("! ").map(|s| MySyntax::Highlight(s.to_string()))
}
}
let doc = cosy::parse("[! important]", &MyExt).unwrap();See examples/speech_bubble_extension.rs for a full example.
Labeled links ([label https://...]) carry a parsed url::Url in
Link::WithLabel.href. cosy re-exports the Url type at its crate root for convenience:
use cosy::Url;| Syntax | Description |
|---|---|
| (indented lines) | Nested bullet list |
code:filename |
Code block |
table:name |
Table |
> text |
Quote |
? query |
Helpfeel search query |
$ command % command |
Command-line notation (bash / csh) |
| Syntax | Description |
|---|---|
[Page Name] |
Internal page link |
[/project/page] |
Cross-project link |
[https://...] |
External URL |
[URL Label] |
Labeled link |
[image.png] |
Image (detected by MIME type) |
[img link] |
Linked image |
[name.icon] [name.icon*3] |
User icon |
`code` |
Inline code |
[$ expr] |
Math (LaTeX) |
[* bold] [/ italic] [- strike] |
Decoration |
[[text]] |
Strong (large bold) text |
[[image.png]] |
Strong (large) image |
[[https://...]] |
Strong (large) link |
[[name.icon]] |
Strong (large) icon |
#tag |
Hashtag |
[N35.xx,E139.xx] [N35.xx,E139.xx,Z14] |
Geographic coordinate (map embed) |
MIT — see LICENSE.