srid/emanote

Show anchor links to each headings on hover

srid opened this issue · 8 comments

srid commented

Note that this anchor can be overriden:

image

When rendered in HTML, it'd be good to have a # link as docusaurus shows on hover:
image

Past discussion:

Hello @srid , I'd like to work on this. Not sure what you had in mind, but do you think we could modify the noteDoc in renderLmlHtml using such a transformation?:

addSectionLinks :: Pandoc -> Pandoc
addSectionLinks = walk f
  where
    f (Header n attr@(idAttr, _, _) inlines) =
        let link = Link ("", ["anchor"], []) [Str "§"] ("#" <> idAttr, "")
         in Header (n + 1) attr ([link, Space] <> inlines)
    f x = x
srid commented

@TristanCacqueray

Sure, you can work on this. I was thinking more like doing that HTML layout in pandoc.tpl here:

<Header>
<h1 class="pb-2 mb-2 text-5xl font-bold text-center" />
<h2 class="mt-6 mb-4 text-4xl font-bold text-gray-700 border-b-2" />
<h3 class="mt-6 mb-2 text-3xl font-bold text-gray-700" />
<h4 class="mt-6 mb-2 text-2xl font-bold text-gray-700" />
<h5 class="mt-6 mb-2 text-xl font-bold text-gray-700" />
<h6 class="mt-6 mb-2 text-xl font-bold text-gray-700" />
</Header>

Possibly similar to how we do for footnotes:

<Note:Ref>
<sup class="px-0.5">
<a class="text-${theme}-600 hover:underline" href="${ema:note:url}#fn${footnote:idx}">
<footnote:idx />
</a>
</sup>
</Note:Ref>

This would allow the user to customize their apperance in .tpl without needing to fork emanote.

Doing this however might require some Haskell changes; I haven't taken a good look at that code yet.

Great, thanks for the footnote example. I guess we need a change in Heist.Extra.Splices.Pandoc to pass the heading id and content?

srid commented

I think you need to edit https://github.com/srid/heist-extra/blob/master/src/Heist/Extra/Splices/Pandoc/Render.hs

Checkout how other non-trivial nodes are rendered, like DefinitionList.

One possible shape:

<Header>
  <Header:Main>
     <h1 class="pb-2 mb-2 text-5xl font-bold text-center"> <inlines /> </h1>
     ...
  </Header:Main>
  <!-- custom HTML goes here, or above -->
  <a href="...">#${header:anchor}</a>
</Header>

Or something like that.

Ok, so I managed to get something working with:

  <Header>
    <Header:Main>
      <h2 id="${header:id}" class="mt-6 mb-4 text-4xl font-bold text-gray-700 border-b-2"> <inlines /> </h2>
    </Header:Main>
    <a href="#${header:id}">⛓</a>
  </Header>

Though I'm not familiar with heist. Should we make one splice (e.g. Header:Main1, Header:Main2, ...) per levels?
I don't understand how the default template renders one of the hN element correctly with:

  <Header>
    <h1 class="pb-2 mb-2 text-5xl font-bold text-center" />
    <h2 class="mt-6 mb-4 text-4xl font-bold text-gray-700 border-b-2" />
  </Header>

… but once I add the <inlines /> then it works differently, e.g. this render both h1 and h2:

  <Header>
    <Header:Main>
      <h1 class="pb-2 mb-2 text-5xl font-bold text-center"> <inlines /> </h1>
      <h2 id="${header:id}" class="mt-6 mb-4 text-4xl font-bold text-gray-700 border-b-2"> <inlines /> </h2>
    </Header:Main>
  </Header>

I must be doing something wrong in srid/heist-extra#6 , could you please have a look when you have a moment? Thanks in advance!

srid commented

Hey @TristanCacqueray - could you open a draft PR in emanote with what you have? I'll play with it.

(I might be late to respond due to https://nixos.asia/en/event/srid-nix-dev and other things)

Sure, good luck with your demo!

srid commented

Just took a brief look:

I don't understand how the default template renders one of the hN element correctly with:

Because of https://github.com/srid/heist-extra/blob/54ff970f733dd45b5509d1c4c298927b6241041b/src/Heist/Extra/Splices/Pandoc/Ctx.hs#L106-L110


I think perhaps this would be simpler and clear?

<Header>
  <Header:2>
    <h2 id="${header:id}" class="mt-6 mb-4 text-4xl font-bold text-gray-700 border-b-2">
      <inlines />
      <a href="#${header:id}"></a>
    </h2>
  </Header:2>
  <!-- ... Likewise, for 1, 3-7 -->
</Header>

We may be able to DRY-refactor the anchor HTML using <bind tag="..">, cf.

<bind tag="storkSearchButtonTopRight">
<div class="absolute -top-6 right-1 md:right-0 flex flex-row items-center justify-center">
<a title="Search (Ctrl+K)" class="cursor-pointer" onclick="window.emanote.stork.toggleSearch()">
<apply template="components/stork/stork-icon" />
</a>
</div>
</bind>
(not sure if it can take 'arguments').