Pandoc is a command - line tool that can convert documents between different formats. It supports a wide range of input and output formats, including Markdown, HTML, LaTeX, PDF, and more. The basic idea behind Pandoc is to take an input file in one format, parse it, and then generate an output file in another format.
HTML is a markup language used to structure content on the web. It uses tags to define different elements such as headings, paragraphs, images, and links. For example, the <h1>
tag is used for the main heading of a page, and the <p>
tag is used for paragraphs.
CSS is a style sheet language used to describe the presentation of an HTML document. It allows you to control the layout, colors, fonts, and other visual aspects of a web page. CSS can be applied directly to HTML elements using inline styles, embedded within the HTML document using the <style>
tag, or linked as an external file.
To convert a Markdown file (e.g., input.md
) to an HTML file using Pandoc, you can use the following command in the terminal:
pandoc input.md -o output.html
Here, input.md
is the input Markdown file, and output.html
is the output HTML file.
A basic HTML document has the following structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF - 8">
<meta name="viewport" content="width=device-width, initial - scale=1.0">
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to my page</h1>
<p>This is a paragraph of text.</p>
</body>
</html>
The <!DOCTYPE html>
declaration tells the browser that the document is an HTML5 document. The <html>
tag is the root element of the document. The <head>
section contains metadata about the document, such as the character encoding and the page title. The <body>
section contains the visible content of the page.
There are three ways to apply CSS to HTML:
<p style="color: red;">This is a red paragraph.</p>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
p {
color: blue;
}
</style>
</head>
<body>
<p>This is a blue paragraph.</p>
</body>
</html>
styles.css
:p {
color: green;
}
Then, link it to the HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This is a green paragraph.</p>
</body>
</html>
Markdown is a lightweight markup language that is easy to write and read. Pandoc can convert Markdown to HTML with additional features such as table of contents and syntax highlighting. To generate an HTML file with a table of contents from a Markdown file, use the following command:
pandoc input.md -s -o output.html --toc
The -s
option creates a standalone HTML file, and --toc
generates a table of contents.
CSS classes allow you to apply the same style to multiple HTML elements. First, define a class in your CSS file:
.highlight {
background - color: yellow;
}
Then, apply the class to an HTML element:
<p class="highlight">This paragraph has a yellow background.</p>
template.html
) and use it with the following command:pandoc input.md -o output.html --template=template.html
<article>
for self - contained content, and <section>
for thematic grouping. This improves accessibility and search engine optimization.Pandoc, HTML, and CSS are essential tools for document conversion and web development. By understanding their fundamental concepts, usage methods, common practices, and best practices, you can create high - quality documents and web pages efficiently. Pandoc simplifies the process of converting between different formats, while HTML and CSS work together to structure and style the content.