ford icon indicating copy to clipboard operation
ford copied to clipboard

FORD links in code blocks get expanded

Open ZedThree opened this issue 4 years ago • 3 comments

FORD links like [[module:subroutine]] in a triple-backtick code block get parsed as links rather than raw text.

MVCE:

foo.f90:

subroutine foo
end subroutine foo

config.md:

---
src_dir: .
output_dir: ./docs
---

```text
This should not be a link [[foo]]
```

Produces the following line in docs/index.html:

<div class="codehilite"><pre><span></span><code>This should not be a link <a href="./proc/foo.html">foo</a>

ZedThree avatar May 20 '20 14:05 ZedThree

I think with the current implementation this is basically inevitable, and it would be very difficult to fix.

Instead, this could be implemented using the markdown Extension API. This might also have a speed advantage, especially if sub_notes and sub_macros were implemented in a similar fashion.

ZedThree avatar Jun 04 '20 16:06 ZedThree

I'm currently running into this issue when including TOML, especially with array of tables, in documents processed by FORD.

I would be interested in helping with a fix on this issue in FORD.

awvwgk avatar Nov 04 '20 20:11 awvwgk

The wikilinks extension has a build_url option that takes a callable which almost works. Unfortunately, we need to know the project object to be able to build the URL and we don't have that until after we set the extensions in the markdown md object.

One solution, which feels a little hacky, would be to use a class like:

class LinkBuilder:
   def set_project(self, project):
       self.project = project

   def __call__(self, label, base, end):
       # implementation basically follows current sub_links
       # but returns the URL and not the link tag

We could then use an instance of this as the build_url argument:

    proj_data["link_builder"] = LinkBuilder()
    md_ext = [
        ..., 
        WikiLinkExtension(build_url=proj_data["link_builder"]),
    ]
    md = markdown.Markdown(extensions=md_ext, output_format="html5", extension_configs={})

and then in Project we do settings["link_builder"].set_project(self)

ZedThree avatar Sep 10 '21 11:09 ZedThree