Skip to content

Instantly share code, notes, and snippets.

@tk0miya
Created March 13, 2023 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk0miya/a7e40ee2c7aac2da3f96d33e0ec463df to your computer and use it in GitHub Desktop.
Save tk0miya/a7e40ee2c7aac2da3f96d33e0ec463df to your computer and use it in GitHub Desktop.
# リテラルスタイルのアンカーを作る
#
# 使い方: :codehref:`blah blah blah <http://path.to/anywhere>`
#
from docutils import nodes
from sphinx.util.docutils import ReferenceRole
class CodeHref(ReferenceRole):
def run(self):
ref = nodes.reference(self.title, self.title, refuri=self.target)
return [nodes.literal('', '', ref)], []
def setup(app):
app.add_role('codehref', CodeHref())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment