I know how to create an external hyperlink with customized text.
`My cool link <http://www.asdf.com>`_
But I want to link to an internal reference.
.. _foo:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
So I'd like to do something like
`My cool internal link <foo>`_
But this doesn't work.
Solution:
`My cool internal link <foo_>`_
Use 2 underscores on text and 1 undescore on link target, example:
`My cool internal link <foo_>`__
... somewhere lower ...
.. _foo:
This staff is referenced by "My cool internal link"
When I use one underscore instead of 2, rst2pdf throws an error.
If John's solution doesn't work for you:
`My cool internal link<foo>`
You just needed to remove the space after your custom title, and before the angle brackets, and use the :ref: directive:
This works:
:ref:`My cool internal link with no space before bracket<foo>`
This doesn't:
:ref:`My cool internal link with space <foo>`
When using reStructuredText with Sphinx, cross-reference other locations in the documentation with the ref role:
:ref:`link text <link-target>`
The custom link text is optional if the referenced object defines a title or caption, as is the case for documents, sections, figures, etc. The target's title will then be used as the link text, but the angle brackets must be left out: :ref:`link-target` . The link text is mandatory when referencing paragraphs or images, as they don't have titles/captions associated with them.
The link target has to be defined somewhere in the documentation, possibly in other documents, i.e. .rst files. For sections, the extension Autosectionlabel would do this automatically and the section's title then becomes the target, and thus also link text. In all other cases, internal hyperlink targets must be declared manually, for example like so:
.. _paragraph-to-be-linked-to:
This paragraph will be referenced from elsewhere in the documentation
with :ref:`that paragraph <paragraph-to-be-linked-to>`.
Note the leading underscore in the target definition. It can be thought of as a right-pointing arrow, here pointing inward, toward the link target. We may also link to specific positions inside (long) paragraphs with inline internal targets:
We want to point to _`this position` inside the paragraph
with :ref:`that paragraph <this position>` from elsewhere.
When using reStructuredText with Docutils alone, the ref role is not available, as it is a syntax extension added by Sphinx. Instead, we need the following syntax to create hyperlinks:
`link text <link-target_>`_
Note the two trailing underscores, one after the link target and another after the full hyperlink. Here the imaginary arrows point outward.
Docutils only processes standalone files. It is used by Sphinx as a back-end to parse individual reStructuredText source files. In Sphinx documentation, the latter syntax will therefore only work for internal links within the same document, but not across documents, i.e. a hyperlink defined in one .rst file referring to a target in another file.
Instead of the ref role, one may find the any role provided by Sphinx even more convenient. It will additionally find link targets automatically created by extensions, such as for source code objects documented with Autodoc. When declared as the default role in conf.py, with default_role = 'any', we could then write `link text <link-target>` or even just `link-target` to create internal hyperlinks. Except for the absence of trailing underscores, the former looks much like the syntax for single-document reStructuredText as recognized by Docutils, but is processed by Sphinx in a cross-document manner.
Related
I have a text file containing a bunch of text, referenced with Zotero citekeys, i.e.
lorem ipsum [#greatPaper2022] and so on
bla bla
to copy-paste into an existing bookdown chapter.
How can I trigger the completion of the .bib file based on those citekeys?
In RStudio's Visual mode, I know that I can insert an item from Zotero, and the .bib file gets updated directly, but what if the citekeys are already in the text like this?
(Alternatively, triggering the completion from outside RStudio would be fine as well.)
I'm writing some text that will be converted to HTML, as a long single page.
Can't figure out how to make links to sections as in HTML using #some-id, so that a user when clicking it will go up or down the web page to
<h2 id="some-id">Section A</h2>
<p>Lot's of lines</p>
Go to section
What you're referring to is called an "internal cross reference".
The markup for an internal cross reference is:
<<id,caption>>
where id is an element on the page that has an identifier, typically a title, and caption is optional text that should appear in the link.
You can link to titles that have auto-generated ids, but the formation of the ids could vary based on the attributes idprefix and (for Asciidoctor) idseparator. The default is to make the title text lowercase, prefix with an underscore, and replace spaces and other punctuation with underscores. The id for the title "Let's make a game!" would be _lets_make_a_game.
It is often better for you to specify your own id that will remain stable even if you edit the text of a title. You can do so with:
[[id,label]]
where id is the identifier you want to specify, and label is the optional, default label that may be used for the cross reference (if the cross reference itself doesn't specify a caption).
If the element that your cross reference points to is a title, you can omit the caption and the label, and the link will use the title's text as its own text.
For Asciidoc, see: http://asciidoc.org/userguide.html#_internal_cross_references
For Asciidoctor, see: https://asciidoctor.org/docs/user-manual/#internal-cross-references
Usage Example:
This is how we assign an ID:
== Debug Running Pods [[debug_running_pods]]
Refer to an ID:
<<debug_running_pods>>
Another option is to use the link: macro. Here's an example from one of my Asciidoctor docs:
link:#_explore_the_public_directory[17.4. Explore the `public` directory]
Info about this is in https://asciidoctor.org/docs/user-manual/#url. Here's an excerpt from the relevant part:
When a URL does not start with one of the common schemes, or the URL is not surrounded by word boundaries, you must use the link macro.
Is it possible to create an intra-document link with sphinx, such that the displayed text is independent of the link and destination?
Currently, I make intra-document links like so:
.. _Label_For_Section:
===============
Name Of Section
===============
The link :ref:`Label_For_Section` is rendered as "Name Of Section".
The link Label_For_Section_ is rendered as "Label_For_Section".
What I want is a way to have a link, where the destination text, link label, and displayed link text can all be different strings. Eg a link to a section called "A" with a label .. _B: which is rendered as "C"
Note
I noticed that other kinds of links (eg external hyperlinks) are similarly constrained, and I figure the solutions may look similar, however I am looking specifically for a solution for intra-document links.
See Cross-referencing arbitrary locations, specifically the ref role.
:ref:`Link title <label-name>`
I want to create a full-text search index for HTML content (to be more specific: EPUB chapters in XHTML format). Like this:
...
<p>Lorem ipsum <b>dolor</b> sit amet, consectetur adipiscing elit.</p>
...
The problem is that I need somehow the matched text's position (like xpath) with search results, because i need to position the reader software to the right place.
I need a functionality like highlight feature, but instead of highlighted text, give the where-to-highlight position of matches.
So if i search for "dolor" it gives back something like this:
matches:[
...
{"match":"dolor", "xpath":"//*[#id="lipsum"]/p[1]/b"}
...
]
The standard scenario (what i found everywhere) like strip html chars with filter, then tokenize, etc, not applies here, because it loses the position information in the first step.
Any suggestions? Is that even possible with Solr or ElasticSearch? Thanks!
Your question is about xpath as result of highlighting for a xhtml-Dokument.
I do not know about a running solution in solr or elasticsearch. There is something very similar in the eXtensible Text Framework(´XTF´) which is build on (an old version of) Lucene.
In XTF you can get the highlighting as tags in the original xml-File. So it should be easy the write an xsl-Transformation to generate the corresponding xpaths.
Main idea in short would be to split the EPUB-book in overlapping chunks and store the xml-structure as special characters in the indexed and stored field. With highlighting information you can then reconvert the original xml-structure to find your xpaths.
I have a Restructured Text document which several hierarchical sections, such as:
Main title
##########
Text under the main title.
Sub-section
===========
Text under the sub-section.
This works great, I get the correct HTML formatting when I compile it using Sphinx.
My question is: how can I go up a hierarchy level so I can add more text after a few sub-sections?
For example:
Main title
##########
Text under the main title.
Sub-section
===========
Text under the sub-section.
In my CSS, sub-section is indented.
I want this paragraph to be rendered as part of the Main title section,
not the sub-section.
I'm basically looking for a way to go up a level in the hierarchy.
Is this possible?
Thanks!
It's not possible to go "up" the hierarchy without starting a new section at the level you desire. Document section structure doesn't work that way. Changes in section level must be preceded by corresponding section titles. Using indentation to signal a section-like structure should only be used in a limited local scope.
What you're describing isn't a subsection, it's a topic. Docutils has a directive for that:
.. topic:: title
Topic text.
May include multiple body elements (paragraphs, lists, etc.).
There is also a "sidebar" directive for a similar structure, but typically for a parallel topic that's off to the side. The "rubric" directive may also be of interest.
See http://docutils.sourceforge.net/docs/ref/rst/directives.html for details.