In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use pandoc to convert Markdown into formatted documents, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Basic transformation
First, install pandoc on your computer. Then, open the console terminal window and navigate to the directory that contains the files you want to convert.
Enter this command to create an ODT file (which can be opened using a word processor such as LibreOffice Writer or AbiWord):
Pandoc-t odt filename.md-o filename.odt
Remember to replace filename with the actual file name. If you need to create a file for another word processor (you know what I mean), replace the command line odt with docx. The following is what happened when this article was converted to an ODT file:
Basic conversion results with pandoc.
Although these conversion results are available, they are a bit boring. Let's see how to add more styles to the converted document.
With style conversion
Pandoc has a beautiful feature that allows you to specify style templates when converting tagged plain text files to word processor format. In this file, you can edit a small number of styles in the document, including styles that control paragraphs, article headings and subheadings, paragraph headings, descriptions, basic tables, and hyperlinks.
Let's see what we can do.
Create a template
To style a document, you can't just use any template. You need to generate what pandoc calls a reference template, which is the template used to convert a text file into a word processor document. To create this file, type the following in the terminal window:
Pandoc-o custom-reference.odt-- print-default-data-file reference.odt
This command creates a file named custom-reference.odt. If you are using another word processor, change "odt" to "docx" on the command line.
Open the template file in LibreOffice Writer, and then press F11 to open the style pane of LibreOffice Writer. Although the pandoc manual does not recommend making other changes to the file, I will change the page size and add headers and footers if necessary.
Use templat
So, how do you use the template you just created? There are two ways to do this.
The easiest way is to place the template in the .pandoc folder of the home directory, which must be created first if the folder does not exist. Pandoc uses this template file when converting documents. If you need more than one template, see the next section to learn how to choose from multiple templates.
Another way to use templates is to type the following conversion options on the command line:
Pandoc-t odt file-name.md-- reference-doc=path-to-your-file/reference.odt-o file-name.odt
If you want to know what the converted file looks like using a custom template, this is an example:
A document converted using a pandoc style template.
Select Templat
Many people only need one pandoc template, but some need more than one.
For example, in my daily work, I use several templates: one with a DRAFT watermark, one with a watermark for internal use, and another for the final version of the document. Each type of document requires a different template.
If you have similar requirements, you can create a file custom-reference.odt like a single template, rename the generated file to a name such as custom-reference-draft.odt, and then open it in LibreOffice Writer and modify the style. Repeat this process for each template you need.
Next, copy the file to the home directory. You can even put them in the .pandoc folder if you like.
To select a specific template during conversion, you need to run this command in the terminal:
Pandoc-t odt file-name.md-- reference-doc=path-to-your-file/custom-template.odt-o file-name.odt
Change custom-template.odt to your template file name.
Conclusion
In order not to remember a set of options that I don't use very often, I cobbled together some simple, very bad one-line scripts that encapsulated the options for each template. For example, I run the script todraft.sh to create a word processor document using a template with a DRAFT watermark. You might want to do the same.
The following is an example of a script that uses a template that contains a DRAFT watermark:
Pandoc-t odt $1.md-o $1.odt-the above is all the content of the article "how to use pandoc to convert Markdown into a formatted document". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.