epydoc and reStructuredText change link name - restructuredtext

I'm using reStructuredText with epydoc. How can I have the text of an internal link different than the target of the link? I have:
:todo: Figure out the `Product.manufacturer` relationship in `Product`.
The Product link looks fine and links to the Product object. The Product.manufacturer link goes to the proper member variable, but instead of the text being Product.manufacturer, I'd like to just be manufacturer.
I know this can be done if I use epytext, but we'd like to stick with reStructuredText so that we can switch documentation generators later if we want to.

I'm not familiar with epydoc myself, but the normal reStructuredText way would be this:
`manufacturer <Product.manufacturer>`_
Or, with Sphinx,
:attribute:`manufacturer <Product.manufacturer>`
Considering that epydoc seems to have overridden the default role to provide links, it will be being left to it. However, this is the most likely to work:
:todo: Figure out the `manufacturer <Product.manufacturer>` relationship in `Product`.

Related

Semantically searching in CSS files

Imagine I have a huge CSS file with e.g. more than 40000 lines, like https://cdn.jsdelivr.net/npm/semantic-ui#2.4.2/dist/semantic.css
I want to explore this file and for example search for class definitions containing "hidden" in their name. How can this be done? The word "hidden" can also appear in the definition of the class, so a normal text search is not sufficient. So I am looking for a tool which is able to interpret the CSS file and then allows me to semantically search in it, understanding the difference between "hidden" in a class name and "hidden" in a class definition.
Any tips on this? Thanks!
Update: I am using Visual Studio Code, if there is a matching extension for it, that would be great. A separate tool would also be fine.
I’m not sure which text editor/IDE you are using but most IDE’s allow you to search for classes by name, in which case you could just use “hidden” as the input. In IntelliJ, the command for this is Ctrl+N. You’ll have to check your editor or IDE for the shortcut but a simple Google search should give you the answer.

How to click on a link based on text in a table using selenium

Hi All,
I have the following table with links that I need to select. In this specific example I need to select the DIY Payroll but sometimes this can change its position within the table. The current xpath is:
.//*[#id='catalog-category-div-1']/table/tbody/tr/td1/ul/li[4]/a
So I do a:
By.xpath(".//*[#id='catalog-category-div-1']/table/tbody/tr/td[1]/ul/li[4]/a").click()
But the problem is here is that it can change position where it can be in td[2] or td[3] and li[n'th postion]
Can I have selenium go through the table and click on it based on text. Will the By.linktext() work here ?
You can use the following codes these codes will handle the dynamic changes.
You can use linkText() method as follows:
driver.findElement(By.linkText("DIY Payroll")).click();
If you want to use xpath then you can use following code.
driver.findElement(By.xpath(.//a[contains(text(),'DIY Payroll')).click();
If you need any more clarification you are welcome :)
I would suggest that you try By.linkText() or By.partialLinkText(). It will locate an A tag that contains the desired text.
driver.findElement(By.linkText("DIY Payroll")).click();
A couple issues you might run into:
The link text may exist more than once on the page. In this case, find an element that's easy to find (e.g. by id) that is a parent of only the link you want and then search from that element.
driver.findElement(By.id("someId")).findElement(By.linkText("DIY Payroll")).click();
The A tag may contain extra spaces, other characters, be capitalized, etc. In these case, you'll just have to try using .partialLinkText() or trial and error.
In some cases I've seen a link that isn't an A tag or contains additional tags inside. In this case, you're going to have to find another method to locate the text like XPath.
You should use a CSS selector for this case:
Can you try:
By.CssSelector("a.browse-catalog-categories-link")
You can use XPath to do this. //a will select all 'a' tags. The part inside of the square brackets will select everything with text "DIY Payroll". Combined together you get the desired solution.
//a[contains(text(),'DIY Payroll')]

Can modules in Morea be marked as optional?

I'd like to add to my course materials, some additional modules which will be marked as optional.
By optional, I mean that they have content (mostly static, e.g., readings) and are probably not going to be covered directly during the course lectures.
However, I'd like them still to appear below the main modules, but somehow separated and marked differently as, well, optional.
I guess I could index them last and also add "(Optiona)" text, but just wondering if there is a better solution for presenting them, e.g. a separating line, a tag like the "coming soon" option, etc.
Thanks
The simple approach is to list these modules last (by using a high value for morea_sort_order) and then add an Optional label (by using morea_labels). Here's an example:
If you want to get fancier, then you could edit the master/src/modules/index.md file to customize the way the modules page is rendered. If you go this way, you could put a dividing line between the required and optional modules, add some CSS to change the border color or background of the optional modules, or anything else you want to do.

Abbreviation (abbr) element in reStructuredText

How to generate an <abbr> abbreviation element in ReST?
<abbr title="Hypertext Markup Language">HTML</abbr>
The documentation indicates that "The abbreviation element is not exposed in default restructured text. It can only be accessed through custom roles." I'm not sure how to create such a custom role, and the rest of the documentation is a tad obscure to me.
For Sphinx users, an abbreviation can be added using the :abbr: role. For example,
This :abbr:`SDP (Software Development Plan)` defines ...
results in the following HTML
<p>This <abbr title="Software Development Plan">SDP</abbr> defines …</p>
I have solved it for now by adding this at the bottom of the document:
.. |HTMLabbr| raw:: html
<abbr title="Hypertext Markup Language">HTML</abbr>
Then in the document I've used this "tag"/custom role like this:
This document is written in |HTMLabbr| and renders nicely in a modern browser.
For each abbreviation you would have to define a new custom role, I'm wondering if there is a way to have a "tag" that would take the value and the title as parameters instead of having to hard-code it like this.
Creating custom docutils rst role is not hard (compared to other ways how to extension docutils). See rst roles howto, which contains all the details along with a full implementation of example RFC role. I was able to create custom bugzilla referencing role based on this document.

Parsing page data into sidebar - wordpress

What would be the proper procedure for accessing the current page html data and picking up all of a certain tag and throwing them into the sidebar as links?
I'm not sure your proficiency with php, but I'll give you and overview of what you'd probably want to do.
First, you need the HTML. I'm assuming you're running this on a page (in a page.php file or single.php file, or similar), this means that you have access to the global variable $post, which contains the html of the page in it. To access it you can use the helper function get_the_content(), this returns the html being displayed.
Next you need to parse through this to get the h2 tags. A simple regex can handle this, something like <h2[^>]*>(.*)</h2>. It's important to remember that this regex is very picky, so format your html correctly, no multiline h2s.
So now you have the html, and have parsed it with a regex to get the h2s. Now you need to generate the list from the results, and prepend it to the top of the content of the page. There are a ton of ways to do this, the easiest being just running the code in the right spot in the template file.
Of course there are probably better ways of doing this, I'd recommend you look at say a FAQ plugin (if that's what this is for), or do the lists manually (as this system can be broken), or possibly use a custom post type; but for your question, that's how I'd do it.

Resources