pyvec / naucse.python.cz

Website with learning materials / Stránka s učebními materiály
https://naucse.python.cz
Other
321 stars 117 forks source link

Always rewrite relative links within content #341

Closed encukou closed 5 years ago

encukou commented 6 years ago

My current thinking is that, as far as possible, Markdown relative links should work in GitHub preview, but use url_for when rendered.

hroncok commented 6 years ago

See also https://github.com/pyvec/naucse.python.cz/pull/100

encukou commented 6 years ago

And from there:

If we would like to convert all the links, it would probably be easier to do it once we have the resulting HTML, regardless of how it was generated. I.e. put it to (the end of) Page.render_html().

I'm warming up to the idea, as we might want to parse the HTML anyway for security (tag whitelisting).

hroncok commented 6 years ago

I believe @mikicz is doing something like that.

mikicz commented 6 years ago

In a previous version of my thesis implementation that was true, I was parsing all the rendered HTML to get URLs that should be frozen. However, since we last talked, I scratched that and I'm only parsing the HTML that's returned from forks to check for allowed/disallowed elements and styles. (I figured out a way to get relative URLs while also getting them registered in the freezer and how to implement the url_for logger in forks to get all the generated URLs in forks)

encukou commented 5 years ago

Naucse now forbids relative links – content "doesn't know" how it's displayed; all URLs are generated in naucse. Instead, content can use the naucse:// URL scheme. (Docs are lacking, ask for details if interested.)

Making links like ../../category/lesson/ work as in GitHub preview is for naucse_render, which has a rewrite_relative_url function. It's far from perfect, but I don't think perfecting it is important enough to track here.