poljar / weechat-matrix-rs

Rust rewrite of the python weechat-matrix script.
Other
360 stars 25 forks source link

Parsing of the custom Matrix HTML subset. #5

Open poljar opened 4 years ago

poljar commented 4 years ago

Some event types can have a formatted body, this body contains a HTML formatted message.

The formatting includes colors, quotes, links, code snippets, etc...

To properly handle this we need to implement a parser and formatter.

Care should be taken when implementing this so that advanced features like hiding/showing of code snippets is possible.

vbrandl commented 4 years ago

Is the subset of HTML that is used in Matrix documented anywhere?

poljar commented 4 years ago

It's basically a restricted version of HTML, documented here.

cubetastic33 commented 4 years ago

Is it necessary to implement a parser from scratch, or can existing parsers like html5ever be used?

poljar commented 4 years ago

Of course not, I actually looked a bit into this and I think kuchiki, which builds on top of html5ever, provides what we need, if not a custom tree sink for html5ever might be needed. In any case, no parser from scratch is needed.

use kuchiki::traits::*;

fn main() {
    let html = r"
        <h1>Example</h1>
        <p class='foo'>Hello, world!</p>
        <p class='foo'>I love HTML</p>
    ";

    let document = kuchiki::parse_html().one(html);

    for element in document.traverse() {
        println!("{:?}", element);
    }
}
louipc commented 4 years ago

Seems like this would be good as a seperate project and upstreamed for other clients to use as well.

yalla commented 2 years ago

Somehow related, but not really part of rendering incoming messages: How would I enter multi-lined code snippets such as:

\```<shift+enter>
foo<shift+enter>
bar<shift+enter>
```<enter>

I guess this is more something which needs to be tackled in weechat, rather than here, right?

poljar commented 2 years ago

There's a script for this: https://weechat.org/scripts/source/multiline.pl.html/

Farzat07 commented 2 years ago

There are plugins for that, such as weechat-edit

I maintain a fork of that which you might want to check

On 22/06/10 02:25am, Alexander W. Janssen wrote:

Somehow related, but not really part of rendering incoming messages: How would I enter multi-lined code snippets such as:


\```<shift+enter>
foo<shift+enter>
bar<shift+enter>
```<enter>

I guess this is more something which needs to be tackled in weechat, rather than her, right?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/poljar/weechat-matrix-rs/issues/5#issuecomment-1152161885
You are receiving this because you are subscribed to this thread.

Message ID: ***@***.***>