6. Example III: markdown to html

Below an example using the module Text::MultiMarkdown to convert MultiMarkdown syntax to (X)HTML.

We use a HERE document (DEMO) with the most important markdown syntax elements, the function 'markdown' for conversion and write the HTML-result into 'markdown.html': click here

use Text::MultiMarkdown qw(markdown);

# defining HERE document 

$text = <<DEMO;

# My Markdown Example

## Introduction
This is a simple example demonstrating various Markdown syntax elements.

## Text Formatting
- *Italic Text*: Use asterisks or underscores around the text, like *this*.
- **Bold Text**: Use double asterisks or underscores, like **this**.
- ~~Strikethrough Text~~: Use double tilde symbols, like ~~this~~.

## Paragraphs: blank line
I really like using Markdown.

I think I'll use it to format all of my documents from now on.

## Linebreaks: next line
I really like using Markdown.
I think I'll use it to format all of my documents from now on.

## Lists
### Unordered List
- Item 1
- Item 2
- Item 3

### Ordered List
1. First Item
2. Second Item
3. Third Item

### Nested List
- Fruit
  - Apple
  - Banana
  - Orange
- Vegetables
  1. Carrot
  2. Tomato
  3. Lettuce

## Links
- [OpenAI](https://openai.com): Link to OpenAI's website.
- [Google](https://google.com): Link to Google's website.

# Image and Image Link Example

#### Image with size parameters, pure html
Alt Text

#### Image Link with size parameters, pure html

Alt Text

## Blockquotes & Put a blank line before and after a blockquote 

> Markdown is a lightweight markup language with plain-text formatting syntax.

## Blockquotes multilines
> Be not afraid of greatness. Some are born great, some achieve greatness, and others have greatness thrust upon them.
>
> We know what we are, but know not what we may be.

## Blockquotes multilines & nested
> Sweet are the uses of adversity which, like the toad, ugly and venomous, wears yet a precious jewel in his head.
>
>> Our doubts are traitors and make us lose the good we oft might win by fearing to attempt.

## Blockquotes with Other Elements

> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
>  *Everything* is going according to **plan**.

## Code Blocks
```
sub greetings {
    $name = shift;
    print("Hello, $name!\n")
}    
greetings("Reinier");
```

## Tables
| Fruit  | Quantity | Price   |
|--------|----------|---------|
| Apple  | 5        | $2.50   |
| Banana | 8        | $1.80   |
| Orange | 3        | $3.00   |

## Horizontal Rule
___

## Footnotes
Here is a sentence with a footnote [^1].

[^1]: This is the footnote text.

DEMO

# conversion and saving the result into markdown.html 

$html = markdown($text);
 
$file = "markdown.html";
open(FH, '>', $file) or die "Could not open file '$file' $!";

print(FH "<!DOCTYPE html>\n<html>\n<body>\n\n". $html . "\n</body>\n</html>\n");

close(FH);