Git Product home page Git Product logo

Comments (14)

jakobkogler avatar jakobkogler commented on May 20, 2024

In general I would be nice to be able to link to different sections of the article easily.

In my Segment Tree article I made such references by creating a name for each relevant section:

### <a name="implementation"></a>Implementation

and then link to it using the syntax:

[Implementation](data_structures/segment_tree.html#implementation)

But that seems pretty dirty and you really have to link the full file path, something like [Implementation](#implementation) doesn't work.

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

Hm-m-m...

doesn't work.

I think this means not "doesn't work" but, "leads to wrong (main) page"? I'm trying to test this now - it seems to be due to using "base" in the html-template.

If so, I'll try to see for workaround in the morning...

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

I hope this is fixed (I added the code which adds page relative address to anchor links after processing markdown)...

I've tried to change anchor in the "Segment Tree Article" to see if it works. Feel free to tell if I'm wrong. Also I have noted there is syntax for naming headers:

### Implementation ### {#implem}

...

[go to Implementation](#implem)

from cp-algorithms.

tcNickolas avatar tcNickolas commented on May 20, 2024

Neat syntax! The anchor in segment tree works, when I have time I'll look through other articles to add anchored links to places which refer to a specific part of the article.

@RodionGork Two questions about this:

  1. What is the proper syntax to refer to anchor link from a different article (to a different page)? I assume [link name](data_structures/segment_tree.html#implementation) as with other cross-page links?

  2. I suspect that on e-maxx.ru the table of contents is generated automatically. How hard is it to add such a feature to our pages? It would be nice to do something like this: gather all headers in the page, generate anchor links for them (for example, from the header text - we could have autogenerated links #implementation, #algorithm, #practice-problems etc.) and put these links together in a table of contents at the beginning of the article.

from cp-algorithms.

jakobkogler avatar jakobkogler commented on May 20, 2024
  1. Yes, that works.
  2. I also want that feature. Btw, on e-maxx.ru the anchors are #0, #1, ..., but obviously I would prefer unique, short, appreciated title names.

from cp-algorithms.

jakobkogler avatar jakobkogler commented on May 20, 2024

Changed the label, because the main point of this issue is about generating a table of context for each article.

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

Well, perhaps we can really make this autogenerated (when expanding templates from markdown)... Like gathering all the 2-nd and 3-rd level titles and inserting the table under the 1-st level title... Or in the place specially marked? Will this be good?

Or yet another approach - we can do this in javascript also (I believe it may be simpler).

from cp-algorithms.

tcNickolas avatar tcNickolas commented on May 20, 2024

Gathering all the 2-nd and 3-rd level titles and inserting the resulting table under the 1-st level title sounds like a plan. We just need to make sure anchor links are autogenerated properly if the 2-nd or 3-rd level title has a manual anchor link written for it in Markdown.

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

I've just attempted to implement this. Though on javascript side (e.g. after user loads it in browser, small table of content should be inserted at once) - mainly because I've found it painful to manage html elements on the server side.

It looks like working for me, though I found it necessary to add special tag to header on the main page (as here table of contents looks ridiculous). The same should be done wherever it is not needed:

<h1 data-toc="off">E-Maxx Algorithms in English</h1>

instead of simply

# E-Maxx Algorithms in English

Please have a look and tell whether it works and how it may need be improved...

We just need to make sure anchor links are autogenerated properly if the 2-nd or 3-rd level title has a manual anchor link written for it in Markdown.

I hope they would be replaced by autogenerated ones :) Though we still shall need to remove tables of contents where they are already...

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

Ah, damn... I now got what you've meant. It is wrong to substitute them with autogenerated anchors, for it breaks other links. I'll fix this bit later.

UPD now should be better. thanks for this hint! Tested on "segment tree" article...

from cp-algorithms.

jakobkogler avatar jakobkogler commented on May 20, 2024

Looks good.

from cp-algorithms.

tcNickolas avatar tcNickolas commented on May 20, 2024

A few improvement suggestions:

  • Right now the font size of the table of contents is the same size as the font in the main part of the article; I would make it a little smaller to make is visually more distinct from the main text.
  • Use different unordered list markers for 2nd and 3rd level titles to make them more distinct from each other (same as e-maxx.ru does).
  • It would be really nice to use more descriptive names for autogenerated anchors, in case people want to link to them from other articles or from external sites. Something like split the title into words, convert them to lowercase, concatenate them with dashes as separators?

from cp-algorithms.

RodionGork avatar RodionGork commented on May 20, 2024

I've made style changes as you proposed. Not sure we really want making text as small as at original e-maxx, for the sake of people who may use phone or tablet to view the site (it seems we have almost 20% of them now). (browser may need to update cached css to reflect this)

As for descriptive names :) The matter seems a bit more tricky... And I'm a bit hesitant and lazy to rush on such improvement right now:

  • article may have several identical subheaders
  • anchors will change when title wording/spelling is changed
  • it would be better to generate them on server-side (if any link exists to them from anywhere besides table of contents) so no crawler may think it is a broken link

So it would be better for now to mark chosen subheaders with short and descriptive anchors manually...

from cp-algorithms.

tcNickolas avatar tcNickolas commented on May 20, 2024

I like how the table of contents looks, not too small and not too large, just right :-)

Anchors will also change with the current approach - if, say, a header is removed or added before the header to which a link leads. It would be nice to do something unified about it, but the current approach will work for now.

from cp-algorithms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.