Giter VIP home page Giter VIP logo

Comments (6)

hunyadi avatar hunyadi commented on September 17, 2024 1

This has been implemented in the latest commit pushed to master. Relative URLs to anchors within the same page (e.g. #Basic-features) and relative URLs to anchors in related pages (e.g. example.md#Basic-features) are now both supported. Note that unlike classic Markdown style (e.g. as in Visual Studio Code), Confluence does not lowercase heading text to make anchors but instead keeps all characters as is, except for whitespace replaced with a hyphen. For example, a heading such as Basic features produces an anchor ID such as Basic-features, not basic-features. You must use the Confluence style in your Markdown documents to ensure that links work as expected when the page is published.

from md2conf.

hunyadi avatar hunyadi commented on September 17, 2024

I have two main questions:

  • How do you assign a unique ID to a Markdown heading or how do you have a unique ID auto-generated from the heading text in order to later use that ID in an anchor?
  • How does Confluence assign IDs to Confluence headings?

Some concerns are character case, spaces, special characters, international characters, etc. We would need a robust mapping that can tackle all possible cases. If such an unambiguous mapping were defined, this feature would likely be relatively straightforward to implement.

from md2conf.

jloeser avatar jloeser commented on September 17, 2024

What do you mean by "how"? From what I see it adds to all headings (h1 to h6) an ID attribute which is basically the heading string with all whitespaces replaced by hypen '-'. They are then referenced with leading hash '#' (case sensitive).

Examples:

<h1 id="Welcome-with-Space" data-renderer-start-pos="18">Welcome with Space</h1>
<h1 id="Heading-with-Dash" data-renderer-start-pos="40">Heading-with-Dash</h1>
<h1 id="欢迎来到该网站" data-renderer-start-pos="59">欢迎来到该网站</h1>
<h6 id="myH6" data-renderer-start-pos="98">myH6</h6>
<h1 id="Vítejte-na-stránkách" data-renderer-start-pos="106">Vítejte na stránkách</h1>

Resulting HTML looks quite straight forward:

<a data-testid="link-with-safety" href="#Vítejte-na-stránkách" title="#Vítejte-na-stránkách" data-renderer-mark="true" class="css-tgpl01">Vítejte na stránkách</a>

Some concerns are character case, spaces, special characters, international characters, etc.

Yes, I had them too however it looks like this is quite robust (I tested with some translated Czech and Chinese Strings).

from md2conf.

jloeser avatar jloeser commented on September 17, 2024

Well, the second case didn't work for me:

$ tail -n +3 internal-link.md

Foo

# Test1

Bar

# Test2

See [link](#Test1)

See [link](internal-link.md#Test2)
$ python3 -m md2conf /home/jloeser/devel/git/atix/janloe/notes/confluence/internal-link.md -l debug
2023-08-22 17:09:21,198 - INFO - _synchronize_page [87] - Synchronizing page: /home/jloeser/devel/git/atix/janloe/notes/confluence/internal-link.md
2023-08-22 17:09:21,204 - DEBUG - build_extension [153] - Successfully imported extension module "markdown.extensions.tables".
2023-08-22 17:09:21,204 - DEBUG - registerExtensions [116] - Successfully loaded extension "markdown.extensions.tables.TableExtension".
2023-08-22 17:09:21,207 - DEBUG - build_extension [153] - Successfully imported extension module "markdown.extensions.fenced_code".
2023-08-22 17:09:21,207 - DEBUG - registerExtensions [116] - Successfully loaded extension "markdown.extensions.fenced_code.FencedCodeExtension".
2023-08-22 17:09:21,209 - DEBUG - build_extension [153] - Successfully imported extension module "pymdownx.tilde".
2023-08-22 17:09:21,210 - DEBUG - registerExtensions [116] - Successfully loaded extension "pymdownx.tilde.DeleteSubExtension".
2023-08-22 17:09:21,210 - DEBUG - registerExtensions [116] - Successfully loaded extension "markdown.extensions.sane_lists.SaneListExtension".
2023-08-22 17:09:21,212 - DEBUG - _transform_link [180] - found link #Test1 relative to /home/jloeser/devel/git/atix/janloe/notes/confluence/internal-link.md
2023-08-22 17:09:21,212 - DEBUG - _transform_link [190] - found local URL: #Test1
2023-08-22 17:09:21,212 - DEBUG - _transform_link [180] - found link internal-link.md#Test2 relative to /home/jloeser/devel/git/atix/janloe/notes/confluence/internal-link.md
Traceback (most recent call last):
  File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/__main__.py", line 85, in <module>
    Application(api, ConfluenceDocumentOptions(args.generated_by)).synchronize(
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/application.py", line 34, in synchronize
    self.synchronize_page(path)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/application.py", line 41, in synchronize_page
    self._synchronize_page(page_path, dict())
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/application.py", line 88, in _synchronize_page
    document = ConfluenceDocument(page_path, self.options, page_metadata)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/converter.py", line 418, in __init__
    converter.visit(self.root)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/converter.py", line 143, in visit
    self.visit(source)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/converter.py", line 139, in visit
    target = self.transform(source)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/converter.py", line 307, in transform
    return self._transform_link(child)
  File "/home/jloeser/devel/envs/md2conf-env/lib/python3.10/site-packages/md2conf/converter.py", line 205, in _transform_link
    raise DocumentError(f"unable to find matching page for URL: {url}")
md2conf.converter.DocumentError: unable to find matching page for URL: internal-link.md#Test2

Any ideas on the fly?

from md2conf.

hunyadi avatar hunyadi commented on September 17, 2024

You can only reference documents in relative links if you are synchronizing a directory tree. This is because the Markdown to Confluence converter only scans the file system and maintains a catalog of valid file names if it is processing a set of documents but not when it is processing a single document. However, you would typically use the short-hand notation #heading-1 to reference a heading in the same document, and not the redundant notation that includes the file name. Specifically, the more redundant syntax is not robust against renaming the file.

from md2conf.

jloeser avatar jloeser commented on September 17, 2024

Thanks for explanation, I can live with the short-had notation for referencing inside same document.

Specifically, the more redundant syntax is not robust against renaming the file.

True.

from md2conf.

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.