Custom id in Sphinx documentation generator - python-sphinx

How to create a custom Id for headlines in Sphinx (Jinja)?
Sphinx defines Id same with the headline text by default, but I want to define a different Id
If you write this in text file :
Headline text
=============
After converting it to HTML file by Sphinx, it looks like this:
<span id="headline-text"></span><h2>Headline text<a class="headerlink" href="#headline-text" title="Permalink to this headline">¶</a></h2>
But I don't want this Id and I want to define my own custom Id for this tag
If text isn't English, the default value is 's-id{number}', which number sets by Sphinx.
Now I want to write something in another language and I'm looking for a way to change it.
After many searches, I came up with a way like the following, but the problem is that when I look at the HTML source, I see that it still has its own ID next to mine like following:
.. _my-custom-id:
مثال سرتیتر
============
And after converting to HTML:
<span id="s-id1"></span><span id="my-custom-id"></span><span id="id1"></span><h1>مثال سرتیتر<a class="headerlink" href="#my-custom-id" title="Permalink to this headline">¶</a></h1>
As you can see, this method still doesn't work and Sphinx still defines its default ID.
What is the solution?

Related

Tiddlywiki5 - pass field value to tiddler

I have a few folders of PDF files that are all related to the same subject, for instance the PDFs for Adventures in Middle-earth RPG. I like to create a tiddlywiki to use as an index to the files. I will then set up a tidder as a menu then set up tiddlers that embed an iframe to open the PDF right inside the main document.
I used the wonderful technique from here: https://stackoverflow.com/a/40561642/10221
I now set a field named "pdf" on the tiddler for each PDF to store the filename to open like this:
\define build-link()
<iframe name="" src=".\$(pdf)$" width="600" height="600" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no"></iframe>
\end
<$set name=pdf value={{!!pdf}}>
<<build-link>>
</$set>
My question, is there a way that I could create a generic tiddler that I use for all the books and then pass the pdf field value into the tiddler when I open it? I'm hoping for something like [[TidderName[pdf=CoreBook.pdf]]]
That would save me from having to create a whole bunch of tiddlers, one for each book, which are almost identical. It would also let me pass in things like the page number to open since the browser lets you append things like #page=5 to advance to a specific page. Then I could do things like [[Character Creation|TidderName[pdf=CoreBook.pdf,page=27]]]
Or maybe I'm just thinking about this totally wrong. I've been using Tiddlywiki for years but I'm certainly not an advanced user.

Adding title to reference section of Pandoc HTML output

I looked through the Pandoc HTML template and I wasn't able to find an option to include a header to the reference section when using pandoc-citeproc. Currently the output looks like the following:
<div class="references">
<p>Some References</p>
</div>
How would it be possible to insert a <h3>Reference</h3> block directly above it? Neither the template nor the documentation mention a $reference$ variable. This is the relevant section of the HTML template:
$body$
$for(include-after)$
$include-after$
$endfor$
I would want to add something like this:
$body$
<h3>References</h3>
$references$
$for(include-after)$
$include-after$
$endfor$
As it says here, the way to do this is to end your document with a level-1 header with the name of the references section. If you use --number-sections and don't want the references section numbered, you can include {.unnumbered} or just {-} after the title.

How to add an image to asciidoc book cover page?

I would like to create a pdf book using asciidoc. The title page should include the title, subtitle and an image. So far I could not find any documentation on how to achive this.
Intuivly I would do something like
My book title
=============
:author: myself
:toc:
image:images/titelimage.png[width=400]
but this just adds image:images/titelimage.png[width=400] as a subtitle. What I would like to have is something like
My book title
<titleimage>
subtitle
Is there a way to do this in ascciidoc? If not, what do I need to do to get this?
If you're using asciidoctor-pdf you can define an attribute for the logo. It will place the image above the document title.
:title-logo-image: images/titelimage.png
See an example pdf here and the raw adoc.
If anyone is still looking for this answer, this is the correct way to do it (using asciidoctor-pdf):
= Book title
Authors
:front-cover-image: image::./images/title_page.png[]
This gives you the image by itself as the first page followed by a page that shows the title, authors, revision etc.
If you want the image on the same page as the title and author, you need to use :title-logo-image: instead.
If you want a PDF using the docbook 4.x output you should:
Generate a docinfo file with an image for the front page. This is an XML file looking like the following example. It is discussed at http://www.methods.co.nz/asciidoc/userguide.html#X87
Example:
<mediaobject>
<imageobject>
<imagedata align="center" depth="400" fileref="../images/tiger.png" />
</imageobject>
</mediaobject>
<subtitle>Subtitle of this book</subtitle>
Then, customize your DocBook stylesheets to include the media element for the title page (by default the stylesheets do not include this). http://www.sagehill.net/docbookxsl/TitlePagePrint.html
DocBook 5 includes a cover element in its stylesheets.
This:
= The Book's Title
:author: First Last
:email: first.last#company.com
:toc:
:toc-placement: preamble
:doctype: book
image:./images/title_page.jpg[]
Produces:
My book title
first.last#company.com - first.last#company.com
Image
Table of Contents
...
you just need to add a empty line between the toc and the images: instruction. That's how asciidoc kinda separates blocs.

How to add an additional article info on sidebar in Joomla 1.5?

I want a sidebar on article page, with additional info. Is there such a solution for Joomla 1.5.
I mean that I add an article and the info is pulled from my text between the tags e.g.
{info_for-sidebar}
Lorem ipsum....
{/info_for-sidebar}
And this info shows in sidebar for current article with actual info.
Is this possible?
Setting up something like what you are asking for require some sort of workarounds.
First, lets agree that what you are calling a "sidebar" is nothing but a content... You enter that content as a part of your article.
So, to achieve what you are asking for I would recommend you use what is called CCK - Content Construction Kit - extension for Joomla using Form2Content. There's a free light edition that would be enough.
Form2Content let you setup a content type. You define what fields you want for each content. Then you create a template that will use the info you are going to enter on the fields to built an article layout.
So let's say you are going to create 3 fields like this :
1- Intro text
2- Full text
3- Sidebar
You are going to create a template as we said. each content type will have 2 templates an intro text template and a full text template
The full text template shall be like this :
<div class="content-container">
<div class="content-sidebar">{$SIDEBAR}</div>
<div class="content-fulltext">{$FULLTEXT}</div>
<br clear="both" />
</div>
The {$SIDEBAR} and {$FULLTEXT} are the text you entered in the form and Form2Content will use it to create a regular content with layout.
If you don't want to use another extension or that solution looks too complicated, you could use a javascript solution. For example you could create an HTML module in Joomla and assign its to the sidebar. On this module switch the view to HTML code and enter this:
<div class="content-sidebar"></div>
When you enter an article, switch the view to HTML code and enter the text you want to show on the sidebar and add a class to the paragraph or the div like this :
<p class="special-content">Lorem ipsum dolor<p>
Then use jQuery to append this special text to the sidebar like this :
jQuery(".content-sidebar").append(".special-content");
Note: Joomla does not load jQuery by default, you have to add it on your template or use a plugin.

Blogger template: Style blog post based on label

I'm trying to change the style of a blog post (for instance change the title color), based on the labels associated to the post.
I'm a bit new to the templating, so I though I would be going to add a class with the label in the title <h3> element, and then add my CSS rules.
So I found this which would generate a proper list of labels separated by a space:
<b:loop values='data:post.labels' var='label'><data:label.name/> </b:loop>
However, it seems the validator does not let me add this inside the class attribute as follow:
<h3 class='post-title entry-title <b:loop values="data:post.labels" var="label"><data:label.name/> </b:loop>'>
From there, I found half the solution. Apparently, I should use expr:class instead of class as follow:
<h3 expr:class='"post-title entry-title " + data:list_of_labels'>
So now:
- How can I build this variable data:list_of_labels? (basically how to set a variable)
- Is there a full description of the template syntax somewhere?
- Is there another way to go around this?
Thanks,
JB
This should do it. Using XML entities allows you bypass the XML validation and move the Blogger functions to where you need them. Longer explanation here: http://www.karlhorky.com/2012/06/add-blogger-labels-to-post-as-css.html
<div class="post<b:if cond="data:post.labels"><b:loop values="data:post.labels" var="label"> <data:label.name></data:label.name></b:loop></b:if>">
<data:post.body>
</div>
There is no way to set variables in the blogger data xml, however you can set variables using javascript.
There are many pages on the blogger data xml. Google is your friend. For example this one.
You are on the right track: do a loop, use javascript to check for the combinations you want, change the style properties or load a css file dynamically.

Resources