diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-06-22 19:08:42 -0400 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2022-06-27 17:07:33 +0200 |
commit | ad0c70bac19e1ff6f4557c45ddf0fe5c87518481 (patch) | |
tree | 782ce77049ff9ea2593f7beb30cdb3af234f8af9 | |
parent | c2c9359d466e545799aebaa2b6c6e353f5f5c833 (diff) | |
download | meson-ad0c70bac19e1ff6f4557c45ddf0fe5c87518481.zip meson-ad0c70bac19e1ff6f4557c45ddf0fe5c87518481.tar.gz meson-ad0c70bac19e1ff6f4557c45ddf0fe5c87518481.tar.bz2 |
docs: make the refman linkification slightly prettier for codeblocks
If we link to
```meson
[[#function]]('posarg')
```
then the ideal linkification would operate on "function" in the
formatted text:
```
function('posarg')
```
Instead, it operated on "function()" in the formatted text:
```
function()('posarg')
```
Fix this by detecting the next character after the reference, and
skipping the usual "automatically append the () for you" stage if it
already has that opening parenthesis.
-rw-r--r-- | docs/extensions/refman_links.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/docs/extensions/refman_links.py b/docs/extensions/refman_links.py index 857d2cb..3aec368 100644 --- a/docs/extensions/refman_links.py +++ b/docs/extensions/refman_links.py @@ -52,9 +52,9 @@ class RefmanLinksExtension(Extension): with valid links to the correct URL. To reference objects / types use the [[@object]] syntax. ''' - link_regex = re.compile(r'\[\[#?@?([ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\.)*[ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\]\]', re.MULTILINE) + link_regex = re.compile(r'(\[\[#?@?([ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\.)*[ \n\t]*[a-zA-Z0-9_]+[ \n\t]*\]\])(.)?', re.MULTILINE) for m in link_regex.finditer(page.formatted_contents): - i = m.group() + i = m.group(1) obj_id: str = i[2:-2] obj_id = re.sub(r'[ \n\t]', '', obj_id) # Remove whitespaces @@ -77,12 +77,15 @@ class RefmanLinksExtension(Extension): text = obj_id if text.startswith('@'): text = text[1:] + elif in_code_block: + if m.group(3) != '(': + text = text + '()' else: text = text + '()' if not in_code_block: text = f'<code>{text}</code>' link = f'<a href="{self._data[obj_id]}"><ins>{text}</ins></a>' - page.formatted_contents = page.formatted_contents.replace(i, link) + page.formatted_contents = page.formatted_contents.replace(i, link, 1) def setup(self) -> None: super().setup() |