Skip to content
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

Overriding existing elements & adding new ones #3

Closed
ubenzer opened this issue Sep 20, 2014 · 2 comments
Closed

Overriding existing elements & adding new ones #3

ubenzer opened this issue Sep 20, 2014 · 2 comments

Comments

@ubenzer
Copy link

ubenzer commented Sep 20, 2014

Is it possible to change the way existing markup elements work?

For example I have a image tag like

![Alt text](@myPostId/myimg.png)

I attach a preprocessor to img markup, something like

function(data) { 
   data.url = "http://overridenurl/myimg.jpg"; 
   return data;
} 

to preprocess image urls.

Or is there a way to add new markup elements, such as

[youtube]http://youtube.com/somevideourl[/youtube]

?

@inca
Copy link
Owner

inca commented Sep 21, 2014

Rho supports image and links preprocessors out-of-the-box, just use ![Alt text][@post/img.png] or [Link text][@post] and then add these properties to the options:

new BlockCompiler({
  resolveLink: function(data) {
    // you can return either { url: '...', title: '...' } or just a string url
  },
  resolveImage: function(data) {
    // you can return either { url: '...', title: '...' } or just a string url
  }
}).toHtml(text);

As you can see, the code requires you to be synchronous (so, you can't fetch your post and read its title, for example). This is done to provide people with best performance possible.

As for the custom elements, yeah, it is supported, but requires you to learn a bit of internals (parser, parsing sequence, etc.) Unfortunately, the parser-emitter conventions are undocumented, but there's nothing too scary about them, if you read the code for BlockCompiler and InlineCompiler.

I can also recommend digging into another repository which takes advantage of custom elements for composing plain-text quizzes.

@ubenzer
Copy link
Author

ubenzer commented Sep 23, 2014

Thanks for the examples and explanation. I took a quick look and I think it will help me a lot! Thanks.

@ubenzer ubenzer closed this as completed Sep 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants