-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making posticle portable and other improvements #117
Comments
this sounds like a good idea! i do have a few questions, though:
|
I started working on this last night.
Yeah, that'd be the correct way to do it, I've switched to using something like an AST for the minute, although it's completely flat so there's not really a tree as such. When/if we need markdown syntax we will go full AST.
At the moment you're using something built into maud, correct? Obviously it doesn't make sense to include all of maud, however there is a html sanitizer library called ammonia that should fit our needs.
In the end this is the trait I settled on: pub trait Resolver {
fn resolve(&self, entity: Entity) -> Option<Entity>;
} It makes more sense to be using |
we're not using maud anymore. we do depend on i don't know how great maud_htmlescape is. ammonia works very well, but they're for two different purposes, in that maud_htmlescape just replaces things like i'm a bit confused about what your resolver trait is supposed to do there. it's taking an entity and... returning one? generally, we want to take a username/domain/hashtag/image/whatever and get a URL, right? |
Yeah, posticle should handle that since it's responsible for generating HTML in this scenario.
Sorry, yeah, needs documentation! The resolver allows you to link up mentions and hashtags by returning a different entity ( I've set things up this way for a couple of reasons so that you can blacklist/whitelist hashtags, mentioned users or entire mentioned domains by either not linking them, or by removing them entirely. The following resolver would remove all entities, and therefore all content: impl Resolver for ResolveNothing {
fn resolve(&self, entity: Entity) -> Option<Entity> {
None
}
} This resolver would link hashtags and mentions to the impl Resolver for ResolveNothing {
fn resolve(&self, entity: Entity) -> Option<Entity> {
match entity {
Entity::Hashtag(name) => Some(Entity::Link(
format!("#{}", name),
format!("https://example.com/tag/{}", name),
)),
Entity::Mention(username, domain) => {
if let Some(domain) = domain {
Some(Entity::Link(
format!("@{}@{}", username, domain),
format!("https://{}/user/{}", domain, username),
))
} else {
Some(Entity::Link(
format!("@{}", username),
format!("https://example.com/user/{}", username),
))
}
},
_ => Some(entity),
}
}
} |
ahhhhh, so this ties up nicely with the AST/internal representation of formatting, and is almost more like an |
After this bit of work is done I'd like to tackle basic Markdown support, the features I think are most important:
Links, and lists are actually quite complicated to implement so I'd like to keep it simple for the time being. Once that is done I'd like to split posticle into it's own crate so that I can then look into making a ruby package with helix, then make a PR for mastodon to use our implementation. Then finally I'd like to make a JavaScript version (wasm/transpiled?) that can be used on the frontend and do cool stuff like do a character count based on Text tokens only. |
wasm would be heckin awesome!! also yeah those are what i'd recommend for basic markdown, it's what i'd use the most anyway |
Sounds like a plan then! 🎉 |
for wasm i've seen stdweb recommended, which looks really nice |
Just a heads up, I'm delaying doing this until the new year. I've got a lot on my plate at the minute, including moving house and I promised someone I'd take a look at a PeerTube issue. Do ping me if there are Posticle bugs that need attention in the mean time! |
@measlytwerp don't worry, that's totally okay 💜 |
I'm thinking of how I can make posticle more portable and useful outside of the rustodon, since there are probably cases where this functionality would be useful to others, and besides that, it'd improve the quality of the code.
The first thing that needs work, as far as I can tell, are emoticons. For the utf-8 icon based emoticons there isn't anything additional that needs work, however we need an
EntityKind
for custom name based emoticons.Once that is done, I want to move the HTML generation into positcle, I've identified three cases where posticle syntax is used:
Measly Twerp :archlinux:
)For titles it doesn't make sense to support hashtags, mentions and URLs, but we would want to include emoticons. To make this possible I'd add a
EntityResolver
trait that rustodon can implement for the two cases.The
EntityResolver
would have the following methods that all return anOption<String>
to confirm that the entity is recognised and valid:resolve_emoticon(name: String)
: resolves to the image URLresolve_hashtag(name: String)
: resolves to the hashtag URLresolve_mention(name: String, domain: Option<String>)
: resolves to the mention URLresolve_url(url: String)
: resolves to the URL given (allows blacklisting of URLs for example)You'd then just pass in an instance of
EntityResolver
to the parser and it'd spit out the HTML.What do you think?
The text was updated successfully, but these errors were encountered: