hunyadi / md2conf

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

Local anchor links not working correctly in Confluence #64

Open erauner12 opened 17 hours ago

erauner12 commented 17 hours 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 17 hours 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 16 hours 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 12 hours 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 7 hours 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