Skip to content

Instantly share code, notes, and snippets.

@jonls
Last active March 20, 2023 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonls/b910afc46473b02597c4 to your computer and use it in GitHub Desktop.
Save jonls/b910afc46473b02597c4 to your computer and use it in GitHub Desktop.
DOI role for Sphinx
@ev-br
Copy link

ev-br commented Oct 2, 2016

Hi @jonls, thanks for the gist!
I just wanted to draw your attention to scipy/scipy#6650 which proposes to add DOI roles to SciPy documentation. I took liberty to copy-paste your gist, interpreting your BSD license note literally --- is it OK with you? Also, I'm happy to change the author info on the copy-paste commit (scipy/scipy@1ee4203), so that you're fully credited in our git logs.

@mikofski
Copy link

mikofski commented Feb 1, 2017

how does this differ from using the builtin extlink extension and defining the following in conf.py:

extlinks = {
    'doi': ('https://dx.doi.org/%s', 'doi:'),
}

@jonls
Copy link
Author

jonls commented Apr 25, 2017

@ev-br 👍 I'm glad it was useful.

@mikofski I think using extlinks in that way would be identical.

@endolith
Copy link

endolith commented Mar 20, 2023

@mikofski That seems like a much better solution. Also requires adding

extensions = [
    'sphinx.ext.extlinks',
…

It produces this though:

WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'.

Oh I get it. You need to change it to

extlinks = {
    'doi': ('https://dx.doi.org/%s', 'doi:%s'),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment