Skip to content

Instantly share code, notes, and snippets.

@jonls
Last active March 20, 2023 21:06
Show Gist options
  • 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
@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