Is there a way, either in YAML or within an R script/Rmd, to turn on the fenced_divs pandoc extension?
If possible, I would prefer being able to turn on fenced_divs without having to specify it inside each individual output format in the YAML block but rather once, globally.
The reason is that I want to have within-document links to items that are not headers using the same code for .docx and .html.
Thanks.
Related
I have a book project in RMarkdown, but since I do not use Knitr or other RMarkdown specific features I am considering switching to pure Pandoc to remove the R burden from the dependencies.
For what concerns PDF and ePub output it seems all straightforward to me, but I have some troubles with the HTML output. In fact Pandoc generates a single HTML file with the entire book.
With Bookdown I used the gitbook HTML output which generates a page for each section and each page have the complete TOC on the left sidebar and its footnotes and partial bibliography on the bottom.
To achieve this I thought to write a md file for each section and convert them one by one with Pandoc (for the HTML output, and merge them to one unique file for converting to PDF and ePub), but in this way I cannot have references across sections, have a full bibliography at the end and also easily create a TOC.
So my question is if there is an easy way (e.g. a Pandoc filter or a script) to generate an HTML book (similar to gitbook in behavior, the style doesn't matter) without installing R and Bookdown?
Pandoc follows the philosophy of only writing files that have explicitly be specified on the command line. This is why no such feature is not built in.
It would be possible to do what you want with the help of a custom writer. The basic would be doable in a few lines of Lua code, but it's likely that you'd have to implement all bookdown features yourself.
The best (IMHO) alternative is to use Quarto, a standalone tool built on top of pandoc, created in part by the authors of bookdown. That way you can remove R from your dependencies but retain the features of bookdown -- and more.
I've altered the epub template to display more information. It works fine, except when I specify images that refer to a local file. e.g. <img src = "my_file.png">. The code is there in the epub, but the image file isn't.
Pandoc does not parse the template as HTML, so it misses the <img> element when collecting media elements for inclusion in the EPUB. A quick and simple work-around is to list the missing images in some unused metadata field. E.g.,
---
missing-images: |
![](my_file.png)
---
Store the above in a file and pass it to pandoc via --metadata-file. This makes pandoc aware of the file, forcing its inclusion.
One could automate it by letting pandoc parse the template and extract the image information, e.g. with a pandoc Lua filter, but that's likely to be more trouble than it's worth.
I'm converting docx files using pandoc 1.16.0.2 and everything works great except right after each image, the size attributes are showing as text in teh
![](./media/media/image4.png){width="3.266949912510936in"
height="2.141852580927384in"}
So it shows the image fine in the md but also the size tag as plain text right behind/after/below each image. The command I'm using is:
pandoc --extract-media ./media2 -s word.docx markdown -o exm_word2.md
I've read the manual as best I can but don’t see any flags to use to control this. Also most searches are coming up where people want to have the attributes and control them.
Any suggestions to kill the size attributes or is my markdown app (MarkdownPad2 - v-2.5.x) reading this md wrong?
Use -w gfm as argument in the command line to omit the dimensional of Images.
You could write a filter to do this. You'll need to install panflute. Save this as remove_img_size.py:
import panflute as pf
def change_md_link(elem, doc):
if isinstance(elem, pf.Image):
elem.attributes.pop('width', None)
elem.attributes.pop('height', None)
return elem
if __name__ == "__main__":
pf.run_filter(change_md_link)
Then compile with
pandoc word.docx -F remove_img_size.py -o exm_word2.md
There are two ways to do this: either remove all image attributes with a Lua filter or choose an output format that doesn't support attributes on images.
Output format
The easiest (and most standard-compliant) method is to convert to commonmark. However, CommonMark allows raw HTML snippets, so pandoc tries to be helpful and creates an HTML <img> element for images with attributes. We can prevent that by disabling the raw_html format extension:
pandoc --to=commonmark-raw_html ...
If you intend to publish the document on GitHub, then GitHub Flavored Markdown (gfm) is a good choice.
pandoc --to=gfm-raw_html ...
For pandoc's Markdown, we have to also disable the link_attributes extension:
pandoc --to=markdown-raw_html-link_attributes ...
This last method is the only one that works with older (pre 2.0) pandoc version; all other suggestions here require newer versions.
Lua filter
The filter is straight-forward, it simply removes all attributes from all images
function Image (img)
img.attr = pandoc.Attr{}
return img
end
To apply the filter, we need to save the above into a file no-img-attr.lua and pass that file to pandoc with
pandoc --lua-filter=no-img-attr.lua ...
I want to have a template variable pre-processed in a markdown doc.
I tried converting the filename to file.html.md.eco but it just comes out as plain text - ie the markdown plugin doesn't seem to get applied.
The file just as html.md renders fine.
Is it needed to add the plugins to the docpad.coffee to make sure they're applied when using multiple passes?
the FAQ states how to use multiple processors
http://docpad.org/docs/faq
... Alternatively, we can get pretty inventive and do something like this: .html.md.eco which means process this with Eco, then Markdown and finally render it as HTML.
I have a collection of one thousand HTML files and need to somewhat trim them. I need to delete all the tags inside <body></body> area of those except for one, <div.pg>, to make them clean to be printed. the excess are navigation links which make the prints messy and make the pages occupy more paper. the contents are not the same so I can't find and replace the code excerpt but the tags are the same foe example there are 3 <table> tags to be deleted each with specific class. manipulate specific tags inside batch HTML files?
Any batch processing technique or software to do this job?
What an easy solution on windows?
I would use an xslt transform on each html page you have. Batch is not the tool to manipulate html files. You can use batch as a "manager" to pass the required file to the xsl transform. Also windows have a rudimentary msxml utility which you can download and install to your machine : http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=21714
That's how I would do it. I am sure there are more options.
If it is XHTML you could use XSLT to transform your HTML to "another" format. Look for example here: http://www.w3schools.com/xsl/ or here: http://help.hannonhill.com/discussions/how-do-i/269-strip-specific-html-tag-in-xslt