Double hash (#) in template - velocity

In an Apache Velocity template, double hashtag (i.e. ##) means comment, but I want to add ## literals into the template. How can I do that?
The reason is that I want to make a template for Github wiki, and the template includes h2's

After some research I found this:
#set ( $double_hash = '##' )
${double_hash}

I've even double the stuff in my jira release template that produce markdown...
#set ( $simple_hash = '#' )
#set ( $double_hash = '##' )
Thx for the hint !!

At least in velocity version 1.7 you can place 'unparsed content' in your template. Put it between #[[ and ]]#
Template example:
some text...
wont be parsed -> #[[${bla "#.#" #set{a="b" ###]]## <-wont be parsed
more text
Apache documentation can be found here

Related

In Docusaurus, is there can I preserve capitalization in anchors created from headings in docs?

I'm using Docusaurus to publish documentation for an open source library's API. The headings of my source markdown files correspond to the names of methods and properties for classes in the library. This all works fine.
However, the anchors that are created in the HTML are all lowercase. I want them to respect the capitalization used in the markdown file.
For example, this markdown header:
###.doSomething()
Generates the following HTML:
<h3>
<a aria-hidden="true" tabindex="-1" class="..." id="dosomething"></a>.
<code>.doSomething()</code>
<a class="..." href="#dosomething" title="...">#</a>
</h3>
As you can see, camelCase is transformed to lowercase. I would like to keep capitalization intact. Is it possible?
P.S. The markdown files are automatically generated from jsdoc comments. In jsdoc, links to a method or properties include capitalization.
TL;DR
Inside your project, navigate to the directory node_modules > github-slugger;
Open the index.js file;
Remove the line if (!maintainCase) string = string.toLowerCase()
The function will become something like this:
function slugger (string, maintainCase) {
if (typeof string !== 'string') return ''
// if (!maintainCase) string = string.toLowerCase() <-- remove this!
return string.trim()
.replace(specials, '')
.replace(emoji(), '')
.replace(whitespace, '-')
}
IMPORTANT!
If you update the docusaurus, you may need to apply this change again;
It may be necessary to edit the doc to see the changes, because of cache. Here I edited the doc file and it worked;
You must restart the docusaurus service after you make this change. And probably needs to clear the cache with npm cache clear --force;
Also, I think you should delete the folder .docusaurus to force the rebuild of all documents.
RESULT
The .md file:
---
id: intro
---
# Random title
### WriNTinG with CaSeS
test 1
### .doAnotherThink()
test 3
### .doCamelCaseWithSeveralLETTERS()
test 3
ROADMAP
I must say that this one was hard. First I tried to track down the anchor tags, then the description. Eventually I found about the github-slugger, and looked like that was the way.
But once I made the changes, nothing had happened to the document! So after hours trying, I gave up… Then, just for curiosity, I decide to see what the slug function did to the document, by adding a second header with the same name. And — luck! — it kept the original case.
It turns out that you can simply use explicit IDs to solve this issue: https://docusaurus.io/docs/next/markdown-features/headings#explicit-ids

Apache httpd server redirect url with anchor tag(fragment id) in it [duplicate]

I'm overhauling a website that someone else built for my organization. It was originally set up with "not so great" anchor links which included spaces. I have replaced those anchors with new ones that will work better.
Example:
One of the old anchors looked like this /course/#To Have which browsers would luckily convert to /course/#To%20Have. I changed that anchor to this: /course/#to-have.
I'm now wanting to make sure that any anchors that may have been shared on social media or that could be linked to from other websites still work; I was planning on doing this via redirect in the .htaccess file, such as this one:
Redirect 301 /course/#To%20Have /course/#to-have
After some research I've found that this is not possible due to the # in the URLs. And I also have not seen examples where an anchor was redirected to another anchor.
Is this possible?
As mentioned in my comment, this is not possible with .htaccess.
Reason being: the hash part (known as the fragment) is not actually sent to the server, and so Apache would not be able to pick it up. Servers may only pick up everything before that, which is described in the Syntax section of this article.
As an alternative, I would recommend that you use JavaScript to convert the fragment before scrolling to its location. You can do that by pulling in the value of [window.]location.hash (the part in square parenthises is optional as location is also available in the global scope) if it exists, as shown below:
if (window.location.hash) {
// Function to 'slugify' the fragment
// #see https://gist.github.com/mathewbyrne/1280286#gistcomment-1606270
var slugify = function(input) {
return input.toString().toLowerCase().trim()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-'); // Replace multiple - with single -
}
// Now get the hash and 'slugify' it
var hash = slugify(window.location.hash.split('#')[1]);
// Go to the new hash by setting it
window.location.hash = '#' + hash;
}

Adding a pagebreak by indesign scripting

I have a routine which reads an XML file and builds an ID document. How do I create a page break by adding to the current insertionPoint? I tried it with
story.insertionPoints.lastItem().contents += SpecialCharacters.pageBreak;
but those special characters seem to apply only to XML. What is the alternative? - I'm using ID CS5.
I got the answer elsewhere. The trick is to use the assignment instead of the concatenation operator:
story.insertionPoints.lastItem().contents = SpecialCharacters.pageBreak;
Looking at the InDesign JS API documentation, it's actually:
story.insertionPoints.lastItem().contents = SpecialCharacters.PAGE_BREAK;

How do I get the shortcode for an Instagram media item to later embed the picture?

I'd like to display Instagram photos matching particular tags on my site. I don't see a way to search for all tags over all time, so I am implementing a timer that periodically checks /tags/tag-name/media/recent for my desired tags. Then I am caching the .id attribute of any as-yet-unseen media, so I can still have access to that item if and when /tags/tag-name/media/recent no longer returns that item.
Now I am ready to embed the images on my site, but I think saving .id is mistaken. The second available embed endpoint - /p/shortcode/media - looks close. It issues a redirect to the image, which will suffice for my task, but it wants a 'shortcode', not an id.
How do I get this shortcode? There is no .shortcode attribute on the media objects returned from /tags/tag-name/media/recent. Should I use a regex to parse the .link attribute, assuming that the link will take the form http://instagr.am/p/shortcode/? Or is there a better technique to remember and later display images that match my desired tags?
Preferring regex solution over String.split, this is what I ended up doing:
//expecting http://instagr.am/p/BWl6P/
var linkrx = /\/p\/([^\/]+)\/$/;
// find /p/, then 1 or more non-slash as capture group 1, then / and EOL
if(igPic.link.match(linkrx) !== null){
var shortcode = igPic.link.match(linkrx)[1];
};
No other way, just use .split() from the link attribute. This will give you the shortcode:
link.split("/")[4]
/p/([^/]+)(/.)*$
this pattern match also links like:
https://instagram.com/p/6H_CiIrdKn/?taken-by=7imet4
https://instagram.com/p/6H_CiIrdKn
This will always return the last component of a path:
'http://instagr.am/p/D/'.replace(/\/$/i, '').split("/").pop()
So http://instagr.am/p/D/ becomes D
tl;dr
Remove any trailing slash (//$/i, a/b/c/ → a/b/c)
Split by / (a/b/c → [a,b,c])
Get the last item in the [a,b,c] array (.pop(), [a,b,c] → c)

Fetch excerpt from Wikipedia article?

I've been up and down the Wikipedia API, but I can't figure out if there's a nice way to fetch the excerpt of an article (usually the first paragraph). It would be nice to get the HTML formatting of that paragraph, too.
The only way I currently see of getting something that resembles a snippet is by performing a fulltext search (example), but that's not really what I want (too short).
Is there any other way to fetch the first paragraph of a Wikipedia article than barbarically parsing HTML/WikiText?
Use this link to get the unparsed intro in xml form
"http://en.wikipedia.org/w/api.php?format=xml&action=query&prop=extracts&exsentences=10&titles=Aati kalenja"
Earlier I could get the introduction of a list of topics/articles from a category in a single page by adding iframes with src like the above link.. But now chrome is throwing this error - "Refused to display document because display forbidden by X-Frame-Options." Any way through? Pls help..
I found no way of doing this through the API, so I resorted to parsing HTML, using PHP's DOM functions. This was pretty easy, something among the lines of:
$doc = new DOMDocument();
$doc->loadHTML($wikiPage);
$xpath = new DOMXpath($doc);
$nlPNodes = $xpath->query('//div[#id="bodyContent"]/p');
$nFirstP = $nlPNodes->item(0);
$sFirstP = $doc->saveXML($nFirstP);
echo $sFirstP; // echo the first paragraph of the wiki article, including <p></p>
As ARAVIND VR notes, on wikis running the MobileFrontend extension — which includes Wikipedia — you can easily get an excerpt of an article via the MediaWiki API by using the prop=extracts API query.
For example, this link will give you a short excerpt of the Stack Overflow article on Wikipedia in a JSON wrapper.
The various options to the query can be used to control the excerpt format (HTML or plain text), its maximum length (in characters and/or sentences, and optionally restricting it to the intro section of the article) and the formatting of section headings in the output. It's also possible to obtain intro extracts from more than one article in a single query.
It's possible to get only the "introduction" of the article using the API, with the parameter rvsection=0 as explained here.
Converting Wiki-text to HTML is a bit more difficult; I guess there are more complete/official methods, but this is what I ended up doing:
// remove templates (even nested)
do {
$c = preg_replace('/[{][{][^{}]+[}][}]\n?/', '', $c, -1, $count);
} while ($count > 0);
// remove HTML comments
$c = preg_replace('/<!--(?:[^-]|-[^-]|[[[^>])+-->\n?/', '', $c);
// remove links
$c = preg_replace('/[[][[](?:[^]|]+[|])?([^]]+)[]][]]/', '$1', $c);
$c = preg_replace('/[[]http[^ ]+ ([^]]+)[]]/', '$1', $c);
// remove footnotes
$c = preg_replace('#<ref(?:[^<]|<[^/])+</ref>#', '', $c);
// remove leading and trailing spaces
$c = trim($c);
// convert bold and italic
$c = preg_replace("/'''((?:[^']|'[^']|''[^'])+)'''/", $html ? '<b>$1</b>' : '$1', $c);
$c = preg_replace("/''((?:[^']|'[^'])+)''/", $html ? '<i>$1</i>' : '$1', $c);
// add newlines
if ($html) $c = preg_replace('/(\n)/', '<br/>$1', $c);