cosy 0.1.0

A parser for Cosense/Scrapbox markup syntax that produces a typed AST
docs.rs failed to build cosy-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: cosy-0.1.1

cosy

Crates.io Documentation CI License: MIT

A parser for Cosense (formerly Scrapbox) markup syntax that produces a typed AST.

Installation

[dependencies]
cosy = "0.1"

To enable JSON serialization of the AST via serde:

[dependencies]
cosy = { version = "0.1", features = ["serde"] }

Usage

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:?}");
        }
    }
}

Custom syntax extensions

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.

URL handling

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;

Supported syntax

Block-level

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)

Inline

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)

License

MIT — see LICENSE.