skyjake / lagrange

A Beautiful Gemini Client
https://gmi.skyjake.fi/lagrange/
BSD 2-Clause "Simplified" License
1.19k stars 62 forks source link

text/markdown support #28

Open Arteneko opened 3 years ago

Arteneko commented 3 years ago

It would be pretty cool to have native markdown support.

I took a look in the source-code and from what I've been able to gather (as a C noob, basically), you're only handling gemini-formatted content (src/gmdocument.c), and you're manually rendering it (probably for best performance, I imagine).

That means that markdown support would require a custom frontend over a markdown compiler, I guess, or "another src/gmdocument" parsing markdown.

Considering the living hell that markdown is, I can probably imagine making a frontend over an existing markdown compiler, but I can probably guess that there are lots of thorny issues on the rendering side, e.g. tables, images, and such.

This would be no small feat, and while I originally created this issue with intent to propose help, now that I'm writing this sentence I kinda already feel overwhelmed by the required work.

My question is then: Was I correct in my assumption on how lagrange's gemini document rendering works? If not, would you agree to take a bit of time explaining how the content handling / rendering is done?

And no matter what, would markdown support be an objective for a future major upgrade in your opinion?

skyjake commented 3 years ago

Was I correct in my assumption on how lagrange's gemini document rendering works?

What you're saying is pretty much correct. GmDocument has been specifically written for text/gemini and text/plain, and introducing Markdown needs some non-trivial work.

Since there is no and will be no HTML renderer in Lagrange, the "full" Markdown cannot be supported in any case, but some sort of pragmatic "Gemini-flavored Markdown" would be doable. Certain elements like tables would probably have to be rendered as preformatted blocks. GmDocument would need to be modified to allow having a separate "visual text string" for each GmRun in addition to the source text, so it could apply inline formatting like bold/italic/etc. without breaking the text selection etc. code elsewhere. The text renderer would need some additional escape sequences to change the font inside a string. Hyperlinks would need some special handling, perhaps converting them all to the footnote style that Markdown supports. On the whole I would assume that GmDocument could be used without major modifications, though, since this Markdown preprocessing would be happening in separate class.

would markdown support be an objective for a future major upgrade in your opinion?

I've had Markdown support in my longer-term todo list since the beginning, but it hasn't been a priority because of how little it is actually being used (GUS shows only 44 hits, if the MIME types can be trusted).

Personally I would enjoy using Lagrange as a Markdown viewer, so I have a feeling I'll get around to working on this eventually.

lua-rocks commented 3 years ago

It seems to me that you underestimate the importance of supporting markdown. Let me give you an example. I'm currently working on a lua documentation tool which parse source files and build standalone wiki in markdown format. This wiki can be browsed locally using web-browser extension or uploaded to github which will automatically convert it to html files. So, if I want to add gemini support to my tool, I need to write additional module to support its format. Maybe this is not really hard work but I just don't like this idea! Why do we need many different formats for the same thing? There is a lot markdown-based websites like blogs and if their owners want to move from http to gemini, they have to find (or make themself) some converter, but why?

Parlazo commented 2 years ago

i apply to this list too i wish markdown support, in gemini protocol documentation they say gemini servers can serve markdown and some servers like agate can serve markdown and lagrange is cool but does not support markdown ... this is a problem... i also know some other people who ask for markdown and they then turn back on https and create minimalistic sites here like gemini but because its hard to find markdown support on gemini they go back to https, i my self also use markdown generated in obsidian.md and to reformat all into gmi is a problem like bold or italic or links please support markdown

skyjake commented 2 years ago

Naturally there is also opposition to this idea: gemini://skyjake.fi/gemlog/2021-10_re-mark-it-down.gmi

I'm a fan of Markdown myself. But I think the key aspect here is to accept that there isn't one canonical visual rendering of a Markdown document. Therefore, it's important to be able to see both the "real" document (i.e., the raw source version) and the rendered interpretation of it. This can be accomplished with #359.

To alleviate concerns regarding undermining of Gemtext's position as the primary content format, Markdown documents should default to the raw source view.

skyjake commented 2 years ago

@lua-rocks:

Why do we need many different formats for the same thing? There is a lot markdown-based websites like blogs and if their owners want to move from http to gemini, they have to find (or make themself) some converter, but why?

One argument could be that someone will need to do the conversion or otherwise you're just looking at a plain text page in the Gemini client — not all Gemini clients will be able to display Markdown on their own. Doing this serverside saves everybody some trouble, and the content owner can oversee the process to ensure that the end result is good.

This is an interesting tension point: there's plenty of Markdown content out there, e.g., blogs and documentation as you say, that could be great to have available via Gemini. However, Gemtext (and plain text) being the only guaranteed content format in clients casts doubt whether that is feasible in practice. We should try to build toward a level playing field instead of favoring certain clients.

lua-rocks commented 2 years ago

@skyjake I am not at liberty to argue with you. Ultimately, this is your project and you decide in what direction to go. Just from my point of view, the markdown browser (via any protocol, including locally) was just as or even more useful to people than the whole gemini-protocol with all its formats and features. But this is just my opinion, it is not meant to be the only truth :)

skyjake commented 2 years ago

v1.8 has a simple Markdown-to-Gemtext converter for viewing local files (via file:// URLs). It is quite incomplete at the moment, so pretty experimental still.

jpfox commented 2 years ago

It would be a very good idea to render markdown text, and even in gopher protocol when a file has a .md or .markdown extension. I am radioamateur and gopher is a cool protocol to publish content over radio in Packet Radio with a small overhead, communication are often at 9600 bauds ! Gemini would be nice, but it is encrypted with TLS, and it is forbidden to crypt radio communication on amateur bands. Many publishers write contents in markdown as input of their site/blog, it is easy to generate a gopher site in parallel. Rendering md would be awesome and I'm sure Lagrange would become the best tool for Packet Radio network

skyjake commented 2 years ago

Version 1.13 has an opt-in feature that enables automatically converting Markdown into a Gemtext document. This naturally leaves out most of the features of Markdown, except for horizontal rules that are now supported in Markdown documents.