ftnext / sphinx-new-tab-link

Open external links in new tabs of the browser in Sphinx HTML documents
https://ftnext.github.io/sphinx-new-tab-link/guide.html
MIT License
9 stars 2 forks source link

Does not seem to work anymore with dirhtml builder #6

Closed FredM67 closed 8 months ago

FredM67 commented 9 months ago

I've added the extension in my config.py, but after build, I get <a class="reference external" href="https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9">Wikipédia</a> for my external link !

Source in rst file is

`Wikipédia <https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9>`_
ftnext commented 9 months ago

@FredM67 Thank you for using this extension. It worked fine in my environment. Please refer to the following steps.

Environment

pip install sphinx-new-tab-link

% python -V
Python 3.11.4

% pip list
Package                       Version
----------------------------- ---------
alabaster                     0.7.13
Babel                         2.13.0
certifi                       2023.7.22
charset-normalizer            3.3.0
docutils                      0.20.1
idna                          3.4
imagesize                     1.4.1
Jinja2                        3.1.2
MarkupSafe                    2.1.3
packaging                     23.2
pip                           23.2.1
Pygments                      2.16.1
requests                      2.31.0
setuptools                    68.2.2
snowballstemmer               2.2.0
Sphinx                        7.2.6
sphinx-new-tab-link           0.1.1
sphinxcontrib-applehelp       1.0.7
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
urllib3                       2.0.6

Quickstart

% sphinx-quickstart \
    --sep \
    -p issue6 \
    -a nikkie \
    -l fr \
    -r ''
.
├── build/
├── source/
│   ├── _static/
│   ├── _templates/
│   ├── conf.py
│   └── index.rst
├── Makefile
└── make.bat

Use sphinx-new-tab-link

source/conf.py

extensions = [
    "sphinx_new_tab_link",
]

source/index.rst

`Wikipédia <https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9>`_

Run make html

build/html/index.html

<a class="reference external" href="https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9" rel="noopener noreferrer" target="_blank">Wikipédia</a>

image

FredM67 commented 9 months ago

Well, that's quite "strange"... I've done all these steps ! Except I've much more/other extensions active ! I'll try on a local Ubuntu machine !

ftnext commented 9 months ago

Thanks for your reply.

Except I've much more/other extensions active !

If you could share the extensions from your conf.py, that might be a clue to the solution.

FredM67 commented 9 months ago

Sure... here's the repo in case you want to look more in details: https://github.com/FredM67/Mk2PVRouter In my config.py, I've these extensions:

extensions = [
    # githubpages just adds a .nojekyll file
    'sphinx.ext.githubpages',
    'sphinx.ext.autosummary',
    'sphinx.ext.todo',
    'sphinx_lesson',
    # 'sphinx.ext.mathjax',
    # 'sphinx-mathjax-offline',
    'sphinx.ext.imgmath',
    'sphinx_rtd_theme_ext_color_contrast',
    'sphinx_copybutton',
    'sphinx_simplepdf',
    'sphinxcontrib.drawio',
    'sphinx.ext.autosectionlabel',
    # 'hoverxref.extension',
    'sphinx_new_tab_link',
    'sphinx_last_updated_by_git',
]

I've put the external link at 2 places, just to be sure, it was not related to the "glossary" directive. Once in glossary.rst, once at the end of index.rst

ftnext commented 9 months ago

Thank you for sharing your repository. I'll investigate if this issue can be reproduced.

FredM67 commented 9 months ago

Thx a lot... on this repo, it's for sure 100% reproducible :(

ftnext commented 9 months ago

@FredM67 Interestingly, this issue did not reproduce in my environment. Please let me know if you notice anything about the following procedure.

$ git clone git@github.com:FredM67/Mk2PVRouter.git
$ cd full-Mk2PVRouter
$ python -m venv venv --upgrade-deps
$ source venv/bin/activate
(venv) $ pip install -r requirements.txt
(venv) $ make html

_build/html/index.html

<p><a class="reference external" href="https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9" rel="noopener noreferrer" target="_blank">Wikipédia</a></p>

_build/html/glossary.html

<p class="last"><a class="reference external" href="https://fr.wikipedia.org/wiki/Pince_amp%C3%A8rem%C3%A9trique" rel="noopener noreferrer" target="_blank">Wikipédia, Pince ampèremétrique</a></p>

<p class="last"><a class="reference external" href="https://fr.wikipedia.org/wiki/Photocoupleur" rel="noopener noreferrer" target="_blank">Wikipédia, Photocoupleur</a></p>

<p class="last"><a class="reference external" href="https://fr.wikipedia.org/wiki/Circuit_imprim%C3%A9" rel="noopener noreferrer" target="_blank">Wikipédia, Circuit imprimé</a></p>
Installed libraries ``` (venv) $ pip list Package Version ----------------------------------- --------- alabaster 0.7.13 appnope 0.1.3 asttokens 2.4.0 attrs 23.1.0 Babel 2.13.0 backcall 0.2.0 beautifulsoup4 4.12.2 Brotli 1.1.0 certifi 2023.7.22 cffi 1.16.0 charset-normalizer 3.3.0 click 8.1.7 colorama 0.4.6 comm 0.1.4 cssselect2 0.7.0 debugpy 1.8.0 decorator 5.1.1 docutils 0.18.1 executing 2.0.0 fastjsonschema 2.18.1 fonttools 4.43.0 html5lib 1.1 idna 3.4 imagesize 1.4.1 importlib-metadata 6.8.0 ipykernel 6.25.2 ipython 8.16.1 jedi 0.19.1 Jinja2 3.1.2 jsonschema 4.19.1 jsonschema-specifications 2023.7.1 jupyter-cache 0.6.1 jupyter_client 8.3.1 jupyter_core 5.3.2 libsass 0.22.0 livereload 2.6.3 markdown-it-py 2.2.0 MarkupSafe 2.1.3 matplotlib-inline 0.1.6 mdit-py-plugins 0.3.5 mdurl 0.1.2 myst-nb 0.17.2 myst-parser 0.18.1 nbclient 0.7.4 nbformat 5.9.2 nest-asyncio 1.5.8 packaging 23.2 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 Pillow 10.0.1 pip 23.2.1 platformdirs 3.11.0 prompt-toolkit 3.0.39 psutil 5.9.5 ptyprocess 0.7.0 pure-eval 0.2.2 pycparser 2.21 pydyf 0.8.0 Pygments 2.16.1 pyphen 0.14.0 python-dateutil 2.8.2 PyYAML 6.0.1 pyzmq 25.1.1 referencing 0.30.2 requests 2.31.0 rpds-py 0.10.4 setuptools 68.2.2 six 1.16.0 snowballstemmer 2.2.0 soupsieve 2.5 Sphinx 5.3.0 sphinx-autobuild 2021.3.14 sphinx-copybutton 0.5.2 sphinx-hoverxref 1.3.0 sphinx-last-updated-by-git 0.3.6 sphinx-lesson 0.8.15 sphinx-mathjax-offline 0.0.2 sphinx-minipres 0.2.1 sphinx-new-tab-link 0.1.1 sphinx-rtd-theme 1.3.0 sphinx-rtd-theme-ext-color-contrast 0.3.1 sphinx-simplepdf 1.6.0 sphinx-tabs 3.4.1 sphinx-togglebutton 0.3.2 sphinxcontrib-applehelp 1.0.7 sphinxcontrib-devhelp 1.0.5 sphinxcontrib-drawio 0.0.17 sphinxcontrib-htmlhelp 2.0.4 sphinxcontrib-jquery 4.1 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.6 sphinxcontrib-serializinghtml 1.1.9 SQLAlchemy 2.0.21 stack-data 0.6.3 tabulate 0.9.0 tinycss2 1.2.1 tornado 6.3.3 traitlets 5.11.2 typing_extensions 4.8.0 tzdata 2023.3 urllib3 2.0.6 wcwidth 0.2.8 weasyprint 60.1 webencodings 0.5.1 wheel 0.41.2 zipp 3.17.0 zopfli 0.2.3 ```
FredM67 commented 9 months ago

Well, until now, I didn't have time to check on a local Ubuntu machine. I'll do that this week-end, I've a Ubuntu virtual machine. I let you know about the results.

FredM67 commented 9 months ago

Well, I've tried on my virtual machine .... it's working fine ! So, it means, something is wrong in the GitHub environment ! But what ?!?

FredM67 commented 9 months ago

Is there a way to put some debug traces in your extension ?

FredM67 commented 9 months ago

I've found what's wrong. When compiling on github, I call make dirhtml which is for sure not recognized in your translator list ! Am I right?

ftnext commented 8 months ago

I see, you use make dirhtml https://github.com/FredM67/Mk2PVRouter/blob/4c7385e9155ca38097002a0d2509f4eed7127d89/.github/workflows/documentation.yaml#L89 and this extensions did not support the builder yet.

Thank you very much your pull request!

ftnext commented 8 months ago

Thanks for the pr. Try https://pypi.org/project/sphinx-new-tab-link/0.2.0/

FredM67 commented 8 months ago

Works like a charm !