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

Markup for definitions #19

Closed
dbuenzli opened this issue Sep 20, 2016 · 17 comments
Closed

Markup for definitions #19

dbuenzli opened this issue Sep 20, 2016 · 17 comments
Labels

Comments

@dbuenzli
Copy link
Contributor

Note the following is about definitions not code fences.

The markup for definitions could be more semantic and the layout should be improved as it can be pretty bad on long definitions since it may wrap anywhere, something a sensitive OCaml programmer would never do.

First these things would be good to have:

  1. The whole definition should be wrapped by a <code> tag.
  2. The identifier being defined should be classified via a <span>.
  3. The constructors of variants should be classified via a <span> the same way they are classified in textual code spans.

Regarding the layout there are at least two solutions that can be tried.

a) <pre> can be used instead of <div class="def"> and all the formatting is done manually (this is the way ocamldoc proceeds), the disadvantage is that it will not be responsive to the page width.

b) <div class = "def"> is kept but we try to control the line breaking algorithm by only using spaces at the places where we would like to break (e.g. before |, after ->) and using non breaking spaces U+00A0 where we don't want to break. I should then be able to make an indent via css' text-indent.

I have a slight preference to try what b) can give us.

@dbuenzli
Copy link
Contributor Author

The constructors of variants should be classified via a the same way they are classified in textual code spans.

In fact they are not at all in odoc I was looking at an ocamldoc generated page.

@dbuenzli
Copy link
Contributor Author

Also word-joiners (U+2060) should be introduced between the ? and the identifier of optional labels.

@trefis
Copy link
Contributor

trefis commented Oct 17, 2016

Do you have examples of classification?

@dbuenzli
Copy link
Contributor Author

dbuenzli commented Oct 17, 2016

val get : key -> 'a t -> 'a

<span class="keyword">val</span> <span class="value-id">span</span> : <span "type-id">key</span>&nbsp;-> <span "type-var">'a</span>&nbsp;<span "type-id">t</span>&nbsp;-> <span class="type-var">'a</span>

@trefis
Copy link
Contributor

trefis commented Oct 20, 2016

I did some work on that, it's most likely not perfect yet but I think you can already have a look.

@dbuenzli
Copy link
Contributor Author

It seems identifier (value and type) are not tagged, also you should avoid putting spaces inside the spans (e.g. in val keyword or in ->). Linked identifiers should also be spanned and finally it would be nice not to tag -> as keyword but type-op.

For example:

<span class="keyword">val </span>list : 
<span class="type-var">'a</span> <a href="index.html#/testable.typ">testable</a>
<span class="keyword"> -&gt; </span>
<span class="type-var">'a</span> list <a href="index.html#/testable.typ">testable</a>

should rather be:

<span class="keyword">val</span> <span class="value-id">list</span> : 
<span class="type-var">'a</span> <span class="type-id"><a href="index.html#/testable.typ">testable</a></span> 
<span class="type-op">-&gt;</span>
<span class="type-var">'a</span> <span class="type-id">list</span> <span class="type-id><a href="index.html#/testable.typ">testable</a></span>

@dbuenzli dbuenzli removed the important label Jan 6, 2017
trefis added a commit to ocaml-doc/doc-ock-html that referenced this issue May 27, 2017
@dbuenzli
Copy link
Contributor Author

@trefis ocaml-doc/doc-ock-html@18ac839 doesn't work: it breaks cut and paste in certain cases (in this case c&p from chrome to emacs on osx).

Basically we should not try to solve this at the character level.

It seems that the forward is to properly span each unbreakable block as suggested above. We should then be able to solve this at the css level (e.g. here are a few suggestions).

@trefis
Copy link
Contributor

trefis commented Jun 12, 2017

Sadness... Thanks for the report.

@dbuenzli
Copy link
Contributor Author

dbuenzli commented Mar 6, 2019

@trefis notes sometimes definitions remain quite unreadable since the break points remain unpredictable. Along with improving the span classification (e.g. -> still lack a proper class or keyword class) it would be good to <span> parentheses aswell, in conjunction with span { display: inline-block } this makes definitions break at more natural points. Here's an example with a span added for the first argument:

https://jsfiddle.net/0ue5o2t1/

@dbuenzli
Copy link
Contributor Author

dbuenzli commented Mar 6, 2019

This also works quite well to treat polymorphic types like 'a list as unbreakable tokens by simply surrounding them by a span. I added List.fold_right2 as an example: https://jsfiddle.net/oj63r92m/

@jonludlam
Copy link
Member

I wonder if there's any way we can use the work going in on ocamlformat to help here? @Julow
might be able to confirm/deny?

@trefis
Copy link
Contributor

trefis commented May 23, 2019

To me, it seems both not obvious and overkill.

@dbuenzli
Copy link
Contributor Author

I wonder if there's any way we can use the work going in on ocamlformat to help here?

Unlikely, ocamlformat works with a fixed width, on the web your width is not fixed. What I propose in the jsfiddle should work quite well with browser layout engines.

@jonludlam
Copy link
Member

Ok, thanks.

Julow pushed a commit to Julow/odoc that referenced this issue Apr 14, 2020
@Drup
Copy link
Contributor

Drup commented Apr 29, 2020

As far as I can tell, all of this has been done and/or is regularly improved. The document representation also has support to improve this further. I propose to close this one and move to more focused issues.

@aantron
Copy link
Contributor

aantron commented Apr 29, 2020

I believe none of the points in the original comment have been done. We do have span around ->, though. If you'd like to consider the details of definitions, I suggest opening the more focused issues, and we'll close this one afterwards.

@github-actions github-actions bot added the stale label May 30, 2020
@dbuenzli
Copy link
Contributor Author

Since #615 the arrows -> are properly classified and were made non breakable, I can hear the screams of joys.

Other than that I concur with @Drup's last comment. The markup for definitions still needs more work w.r.t. break points but in its current state and with respect to all the changes that have occured since it was opened I no longer find this issue to be useful to work with.

jonludlam pushed a commit to jonludlam/odoc-parser-cleaned that referenced this issue Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants