Set root path for relative links while converting with Pandoc - pandoc

I have a markdown file which I want to convert into html file using pandoc.
It has some relative links in the form [text](relative_path.MD)
After conversion I want this links to lead to https://github.com/username/project/blob/master/relative_path.MD
In other words I want to set https://github.com/username/project/blob/master/ as a root for relative paths. Can I do this in some simple way?
I found that I can write arbitrary Lua filters, but surely I am not the first person trying to achieve this and there is some built-in method allowing to do this without writing own link parsing code?

Just came across this filter:
https://musteresel.github.io/posts/2018/01/pandoc-project-relative-links.html
It's in Haskell rather than Lua so won't be as efficient as a lua filter.
No idea if it works!

Related

PanDoc - How to insert variables in header in docx with pandoc_title_block extension?

I would like to generate a DOCX with a variables inside header based on the texts inserted in the md file as variables, such as the title of the document, the version and the date of publication.
Through the yaml_metadata_block extension and the creation of custom fields in the reference.docx file I was able but I would like not to use form fields.
I understand (but I could be wrong) that with the extension pandoc_title_block this can be done but I don't understand how it works and I don't find examples on the net that I can study.
is what I said correct?
if so, could a simple example be shared that you can study and understand?
thank you

How does file convertors work in general like word to pdf, XML to json, word to txt etc

I've used many types of file convertor like word to pdf, XML to json, word to txt etc.
How do they work in backend? Is there some specific guidelines each of them follow? Are there some similarity in the way they are implemented.
I tried searching it but most of the articles take me to the web app that can convert the doc, but none of them gives clarity on how it's done.
All of them work by parsing the first document into a data structure. Then generate a document in the other format from that data structure using recursion.
Parsing itself is a giant topic that people take courses on in computer science. But long story short, it proceeds by breaking the document into tokens, and then fitting the tokens into a parse tree using one of a standard set of methods. They have all sorts of fancy names like Recursive Descent and LALR(1). That's where most of the theory you'd want to learn is.
For example if you're writing a JSON to XML converter, you'd first need to parse that JSON. A JSON Parser shows how you could write that, from scratch, using recursive descent. Once written you just need to write a recursive function that takes each data type and does something appropriate with it to generate text in the format that you want.
Incidentally you can also write a "document converter" that converts from a document format to the same document format. Why would someone want to do that? The two most common use cases are to prettify or minify code. Despite the fact that only one format is being dealt with, the principles of how you do it are exactly the same.

Rename latexmath macro in asciidoc

Is there a way I can rename or alias latexmath in an AsciiDoc document?
In an ideal world, I'd like to set up an AsciiDoc such that $...$ is interpreted as LaTeX math, and
$$...$$ is interpreted as a block equation. In general, I'm just trying to reduce the number of characters involved in defining a math block since
where $c$ is the speed of light and $m_0$ is the rest mass
is significantly more readable (to someone who's used LaTeX for years) than
where latexmath:[$c$] is the speed of light and latexmath:[$m_0$] is the rest mass
The use case I have is that I'm writing technical documentation for upload to a GitLab repository. I'd like to be able to exploit GitLab's ability to automatically render AsciiDoc format files. However, these documents are math heavy, so I find the large numbers of latexmath:[...] blocks hard to read while editing.
latexmath is the name of the macro that handles parsing the LaTeX markup. If you don't specify latexmath, asciidoctor doesn't know to pass control to an alternate parser.
You could achieve what you're after by writing a pre-processing step that identifies contiguous blocks of LaTeX markup and wraps that markup in latexmath:[...]. The updated markup can then be processed by Asciidoctor like normal (assuming that your LaTeX markup identification is accurate). How you go about implementing that is up to you.
Another way, assuming you have some Ruby skills, would be to modify the extension that implements the latexmath macro such that it was called, say, L. Then your markup would be the more concise:
where L:[$c$] is the speed of light and L:[$m_0$] is the rest mass

How can I automatically update all of the filenames for my middlman blog posts after rewriting the titles?

I have a whole load of blog posts in middleman and have just worked on improving the titles, which are written in the frontmatter section at the top of the markdown file. However, the filenames are all still set to the old titles, and retyping them is a pain. Is there a quick way to either regenerate all the filenames from the current title, or get middleman to ignore the filename at build time and create a new filename for the generated HTML based on the current title?
I am not aware of any built-in option that does what you need.
You would have to use your favorite language to build something quick and dirty that does that for you. In pseudocode:
Iterate over all blog files and for each file:
Read the file's contents and extract the new and nice title from the front matter using a regular expression
Rename the file according to your desired naming scheme. You could include the original date (if present), make titles URL friendly etc.
Whether that would be more efficient than manually renaming all files it depends of course on the number of blog posts as well as you programming experience!

Rainmeter: How to concatenate strings

I am getting data from a broken RSS feed that gives me wrong link. I wanted to fix this link so I made this code:
<link.*>(.*)&.*tid(.*)</link>
and the link could be like:
www.somedomain.com/?value=50&burrrdurrrr;tid=120
But the real working link is in this form:
www.somedomain.com/?value=50&tid=120
The thing that I'm asking is if my measure thing looks like this:
[FeedURL]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Feed]
StringIndex=2 ;now I only get www.somedomain.com/?value=50
Substitute=#SubstituteFeed#
How am I supposed to concatenate the strings together to complete the url?
I'm guessing rather than &burrrdurrrr;, the link has &, which is how you have to write & in an HTML or XML file.
If that's the case, you just need to set the DecodeCharacterReference option, as described in this handy-looking tutorial. Another option mentioned there is Substitute, which would be able to strip it out even if it really was &burrrdurrrr;.
None of this is a particularly sensible way of dealing with HTML or XML - a much better approach would be a plugin which actually parsed the document structure and let you reference nodes using XPath or CSS rules - but you work with what you've got, I guess. (I've never heard of this "Rainmeter" before, despite its claim to be "the best known and most popular desktop customization program for Windows"; maybe because nobody else calls their program that, instead almost universally using the word "widget"?)

Resources