How to add border to code blocks in generated beamer pdf from Markdown using Pandoc - border

I've found how to add line numbers by writing,
```{.c .numberLines}
int x = 1;
int y = x;
```
But wonder how to add a border to the code blocks.

The "easiest" way to do this is to modify the default.beamer template and pass the --listings variable to pandoc during pdf creation. Take a look at the information for frames in the listings documentation: http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/listings/listings.pdf

Related

Auto Generate TOC for Article with Less than Four Headings

In the documentation https://www.mediawiki.org/wiki/Help:Formatting it states that an article will have a TOC generated if there are 4 or more headings. We would like a TOC to be generated even if there is less than 4 headings. Is this value customisable ?
Our workaround at present is to add FORCETOC to every page, but we would prefer it if this wasn't needed.
Thanks in Advance
You need to use a parser hook and change the parser's TOC settings. It's not elegant but doable. E.g. the ForceTocOnEveryPage extension does something like this:
$wgHooks['InternalParseBeforeLinks'][] = function ( &$parser, &$text ) {
return $text . '__FORCETOC__';
};
Changing the ToC heading count is not (currently) possible, as the 4 is hardcoded. It wouldn't be a huge change to make it configurable though.

How to add 2 numbers display the result in HTML without Javascript

As the question, I'm coding such as (value x) * (value y) to directly display the result in HTML in software.
But the software doesn't support the script tag. can we simply use HTML tag achieve function.
In the software I have the subtotal example $55.25, but I want it shows $$65.00 (calculate by $55.25 / 0.85)
enter image description here
HTML cannot do math - it is a markup/layout language. Whatever logic you are using that is creating the items to add to the template will need to also do the math and send the result to the template.

Issues with parsing HTML with ragel

In my project I need to extract links from HTML document.
For this purpose I've prepared ragel HTML grammar, primarily based on this work:
https://github.com/brianpane/jitify-core/blob/master/src/core/jitify_html_lexer.rl
(mentioned here: http://ragel-users.complang.narkive.com/qhjr33zj/ragel-grammars-for-html-css-and-javascript )
Almost all works well (thanks for the great tool!), except one issue I can't overcome to date:
If I specify this text as an input:
bbbb <a href="first_link.aspx"> cccc<a href="/second_link.aspx">
my parser can correctly extract first link, but not the second one.
The difference between them is that there is a space between 'bbbb' and '<a', but no spaces between 'cccc' and '<a'.
In general, if any text, except spaces, exists before '<a' tag it makes parses consider it as content, and parser do not recognize tag opening.
Please find in this repo: https://github.com/amdei/ragel_html_sample intentionally simplified sample with grammar, aiming to work as C program ( ngx_url_html_portion.rl ).
There is also input file input-nbsp.html , which expected to contain input for the application.
In order to play with it, make .c-file from grammar:
ragel ngx_url_html_portion.rl
then compile resulting .c-file and run programm.
Input file should be in the same directory.
Will be sincerely grateful for any clue.
The issue with the defined FSM is that it includes into 'content' all characters until the space. You should exclude HTML tag opening '<' from the rule. Here is the diff for illustration:
$ git diff
diff --git a/ngx_url_html_portion.rl b/ngx_url_html_portion.rl
index ccef0ca..1f8dcf0 100644
--- a/ngx_url_html_portion.rl
+++ b/ngx_url_html_portion.rl
## -145,7 +145,7 ## void copy2hrefbuf(par_t* par, u_char* p){
);
content = (
- any - (space )
+ any - (space ) - '<'
)+;
html_space = (

Syntaxhighlighter shows up in single line

I have a scenario where-in I fetch some text from the database which is formatted using HTML as below:
public static void main(String args[ ]) { <br> int x =10;}
I'm using syntax highlighter to do some highlighting. The String above will be fetched from the database, and rendered in the html page using the pre tag as shown below:
<p><pre class="brush: java;">#exam.description</pre></p>
Where exam.description will contain the HTML formatted source code that is shown above. The resultant HTML rendered is as shown below in the screenshot!
How to ensue that the HTML tags inside the source code are respected as HTML tags? I checked the configuration options for the Syntax Highlighter and there seems to be none that I could use to escape the HTML! Any suggestions?
Your question doesn't make much sense, maybe you should rephrase it, in any case:
<p><pre class="brush: java;">Line 1\nLine 2\nLine 3\n</pre></p>
Will return the data in multiple lines, and
<p><pre class="brush: java;">Line 1<br>\nLine 2\nLine 3\n</pre></p>
Will also return multiple lines and add an extra line between Line 1 and Line 2.
So in any case, your code should work UNLESS you are escaping the data returned from the function (java function), and the < and > (or just one of them) are escaped

How can I replace and multiply dimensions of img tags in Perl or Ruby?

I have a folder full of html files created for a Kindle ebook. The images are coded with width and height, as per the Kindle guidelines:
<img width="328" height="234" src="images/224p_fmt.jpeg" alt="224p.tif"/>
What I need to create/find is a script that will process all the image tags, multiply the width an height attributes by a specified amount (coded into the script) and write them back into the html files.
So, for the above example, say I want to multiply by 1.5, and wind up with
<img width="492" height="351" src="images/224p_fmt.jpeg" alt="224p.tif"/>
Scripts like this are not my forte, so help appreciated. I especially am unclear on how to write a script that I can run on file(s) from the command line and just input/output html.
I assume the meat of the code would be something like
s/<img width="([0-9]+)" height="([0-9]+)" src="(.*?)" alt=".*"/>/'<img width="'.$1*1.5.'" height="'.$2*1.5.'" src="'.$3.'" alt=""/>'/eg;
Which I realize is incorrect (the multiplication part) which is why help appreciated.
You've already got the main regex figured out, just need to tweak it and decide a language. Using regexes on html is not optimal, but since this is somewhat straightforward, its probably ok.
perl -pi.bak -we 's/<img width="([0-9]+)" height="([0-9]+)"/q(<img width=") .
$1*1.5 . q(" height=") . $2*1.5 . q(")/eg;' yourfile.html
Note the use of the alternate quoting q(...), since using single quotes on the command line will conflict with the shell quoting.
There's no need to touch any parts you're not changing, unless you feel the need to make a stricter match. If you do, you can add a look-ahead assertion:
(?=\s*src=".*?"\s*alt=".*?"\/>)
This part will remain unchanged by the substitution.
In Python I'd do it like this.
import sys, re
source = sys.stdin.read()
def multi(by):
def handler(m):
updated = int(m.group(2)) * by
return m.group(1) + str(updated)
return handler
print re.sub(r'((?:width|height)=["\'])(\d+)', multi(1.5), source)
Then you can handle input and output on the command like using < and >.
$ python resize.py < index.html > new_file.html
I would look into using the nokogiri gem to parse the HTML, search for image tags, extract the width and height attributes and then output the changed document so you can save it.
More information at the nokogiri tutorial page.
You're right, it can be done with a small Ruby script. It can look like this :
source = '<img width="328" height="234" src="images/224p_fmt.jpeg" alt="224p.tif"/>'
datas = source.scan(/<img width="([0-9]+)" height="([0-9]+)" src="(.*?)" alt=".*">/).flatten!
source.gsub!(data[0], (data[0].to_i * 1.5).to_s)
source.gsub!(data[1], (data[1].to_i * 1.5).to_s)
Of course, it's a quick and dirty script, far from perfect and it has some drawback.