Search code examples
anchorpandoc

Is there a way to make non headers anchor links using pandoc markup


I'm trying to make an anchor link, but only see references to making anchor links using headers.

# Header
Go and see the [Header](#header)

However I want to link a specific word in a list. Is there a way to give a single word an anchor?

#. This phrase should be the anchor
Go and see number ([I.11](#this-phrase-should-be-the-anchor)

Update

Still no luck with the original question. I think I might have to settle restructuring my documents with headers instead, which doesn't thrill me. I might have some documents that have deep subsections and html can't go beyond h6, but For the moment I will assume those are far and few inbetween.

The only solution I have found is a CSS that can modify the headers to include the alphanumerical numeration, which will make formatting much nicer than using lists since I have to do some funky hack for codes. Here is what that might potentially look like

    body {
        counter-reset: section;
    }

    h1 {
        counter-reset: subsection;
    }

    h2 {
        counter-reset: subsubsection;
    }

    h1:before {
        counter-increment: section;

        content: "" counter(section,upper-roman) ". ";
    }

    h2:before {
        counter-increment: subsection;
        content: counter(section,upper-alpha) " ";
    }
    /* So on and so forth according to individual need*/
<body>
  <h1> First section </h1>
      <h2>First Subsection</h2>
          <p> Enterprise to Kirk </p>
      <h2>Second Subsection</h2>
          <p> Come in Enterprise</p>
      <h2>Third Subsection</h2>
          <p> We are under attack.</p>
  <h1> Second section </h1>
       <h2>First Subsection</h2>
      <h2>Second Subsection</h2>
      <h2>Third Subsection</h2>
</body>

I also learned how to attach a css file with pandoc Add the --css filepath.css to the command line


Solution

  • You can assign id to all the elements with attributes in pandoc's internal AST (in newer pandoc versions this includes images and links).

    You can also always use divs or spans as well:

    This is [a span]{#foo}
    
    That can be [referenced with a link](#foo)