hunyadi / md2conf

Publish Markdown files to Confluence wiki
MIT License
52 stars 27 forks source link

Local anchor links not working correctly in Confluence #64

Closed erauner12 closed 4 weeks ago

erauner12 commented 1 month ago

When converting Markdown documents with local anchor links to Confluence pages using md2conf, the generated links are not functioning as expected. The links are being created as web links instead of Confluence's advanced links, causing navigation issues within the page I think?

Steps to reproduce:

  1. Create a Markdown file with a table of contents and corresponding section headers.
  2. Include local anchor links in the table of contents (e.g., [Section Title](#section-title)).
  3. Convert the Markdown file
  4. Publish the converted content to a Confluence page.

Expected behavior: Clicking on a local anchor link in the table of contents should navigate to the corresponding section within the same Confluence page.

Actual behavior: Clicking on a local anchor link either refreshes the page or does not navigate to the intended section. The links are being created as "web links" instead of Confluence's advanced links

ex:

image

Workaround: After publishing the page to Confluence, manually editing each link and changing it to an "Advanced" link in the Confluence editor fixes the issue. This suggests that the problem lies in how md2conf is generating the links.

image
      - [Backend-Only Deployment](#backend-only-deployment)
...
      - [Arbitrary Order Change](#arbitrary-order-change)
#### Arbitrary Order Change
<text>
erauner12 commented 1 month ago

Interesting:

https://<redacted>/pages/viewpage.action?pageId=223753291#arbitrary-order-change

vs:

https://<redacted>/display/PROVNG/express_deployment_scenarios#express_deployment_scenarios-arbitrary-order-change

It seems when I change it to advanced, this is what changes if you copy the link address

image

edit: nevermind I was wrong on that.

Makes me wonder what actually changes when I changed that advanced link? I'm not sure how to look.

erauner12 commented 1 month ago

As nice as as github links are I think just regular old table of contents macro would do the trick too. hmm might try this

hunyadi commented 1 month ago

From what I saw in Confluence Storage Format (CSF), simple links are HTML anchor elements (<a href="...">), whereas advanced links are so-called structured-macro instances. md2conf already uses the structured-macro variant for generating anchor targets for headings. This is enabled with the command-line option --heading-anchors. This allows us to assign lowercase anchor names to headings (as in GitHub) as opposed to mixed-case anchor names (as in Confluence). Specifically, this has helped users with their Markdown table of contents. Perhaps you are missing --heading-anchors too?

erauner12 commented 1 month ago

Well actually I was using the --heading-anchors so it ws not making since to me why it was not properly re-directing when I clicked it?

    if grep -q "confluence-page-id:" "$file"; then
        echo "Updating existing page: $file"
        $PYTHON_PATH -m md2conf "$file" \
            --heading-anchors \
            -s "${CONFLUENCE_SPACE_KEY}" \
            -d "${CONFLUENCE_DOMAIN}" \
            -p "${CONFLUENCE_PATH}" \
            -a "${CONFLUENCE_API_KEY}" \
            --generated-by "This page was automatically generated" \
            --ignore-invalid-url \
            --render-mermaid \
            --loglevel debug
hunyadi commented 4 weeks ago

Local references within a Markdown document (i.e. URLs that consist of a fragment part only) are now expanded into Confluence advanced links:

<ac:link ac:anchor="anchor">
  <ac:link-body>
    ...
  </ac:link-body>
</ac:link>

This is activated with --heading-anchors. Links must use standard Markdown conversion rules to reference section headings (all lowercase).

Changes have been pushed to master with the commit text Expand references within document to Confluence advanced links.