Skip to content
NerzouillePublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

117 Commits

Folders and files

Repository files navigation

MyPandoc

A multi-format document converter written in Haskell, inspired by Pandoc. This project allows converting documents between different formats: Markdown, XML, and JSON.

πŸ“‹ Table of Contents

πŸ“– Description

MyPandoc is a document conversion tool that transforms files between different markup formats. It supports reading and writing documents in Markdown, XML, and JSON, while preserving the structure and semantics of the content.

✨ Features

  • Multi-format conversion: Markdown ↔ XML ↔ JSON
  • Automatic input format detection: Based on file extension
  • Support for basic elements:
    • Paragraphs and plain text
    • Headers with hierarchical levels
    • Formatting: bold, italic, underline
    • Bullet lists with levels
    • Code blocks with language
    • Inline code
    • Links and images
    • Quotes
  • Document metadata: Title, authors, date
  • Flexible output: To file or stdout

πŸ”§ Installation

Prerequisites

  • Stack (Haskell build tool)
  • GHC (Glasgow Haskell Compiler)

Compilation

# Clone the project
git clone <repository-url>
cd mypandoc

# Compile the project
make all
# or directly with stack
stack build --copy-bins

The mypandoc executable will be generated in the current directory.

πŸš€ Usage

Basic syntax

./mypandoc -i <input_file> -f <output_format> [-o <output_file>] [-e <input_format>]

Options

  • -i <file>: Input file to convert (required)
  • -f <format>: Output format (required)
    • markdown or md: Markdown format
    • xml: XML format
    • json: JSON format
  • -o <file>: Output file (optional, prints to stdout if omitted)
  • -e <format>: Input format (optional, automatically detected from extension)

πŸ“ Supported Formats

Markdown

  • Headers (#, ##, ###, etc.)
  • Paragraphs
  • Bold (**text**)
  • Italic (*text*)
  • Bullet lists (- or *)
  • Code blocks (```)
  • Inline code (`code`)
  • Links ([text](url))
  • Images (![alt](url))

XML

Hierarchical structure with semantic elements corresponding to Markdown elements.

JSON

Structured representation of the document AST with all metadata preserved.

πŸ’‘ Examples

Markdown to XML conversion

./mypandoc -i document.md -f xml -o document.xml

XML to JSON conversion (to stdout)

./mypandoc -i document.xml -f json

Conversion with explicit input format

./mypandoc -i file.txt -e markdown -f json -o output.json

Example files

The test_files/ directory contains several examples:

  • syntaxe.md: Complete example with all supported elements
  • simple.xml: Basic XML document
  • all.md: Complex document with metadata

πŸ—οΈ Architecture

The project is organized into Haskell modules:

src/
β”œβ”€β”€ Core/
β”‚   β”œβ”€β”€ Ast.hs          # AST (Abstract Syntax Tree) definition
β”‚   └── Library.hs      # Utility functions and core parser
β”œβ”€β”€ Parser/
β”‚   β”œβ”€β”€ Parsing.hs      # Main parser
β”‚   β”œβ”€β”€ Markdown.hs     # Markdown parser
β”‚   β”œβ”€β”€ XML.hs          # XML parser
β”‚   └── Json.hs         # JSON parser
β”œβ”€β”€ Render/
β”‚   β”œβ”€β”€ Rendering.hs    # Main renderer
β”‚   β”œβ”€β”€ Markdown.hs     # Markdown rendering
β”‚   β”œβ”€β”€ XML.hs          # XML rendering
β”‚   β”œβ”€β”€ Json.hs         # JSON rendering
β”‚   └── Utils.hs        # Rendering utilities
└── Conf.hs             # Configuration and argument management

AST (Abstract Syntax Tree)

The project uses a unified AST to represent all documents:

data Document = Document Header [Block]
data Header = Header { title :: [Inline], authors :: Maybe [Inline], date :: Maybe String }
data Block = Para [Inline] | Section Int (Maybe [Inline]) [Block] | CodeBlock String String | BulletList Int [[Block]]
data Inline = Str String | Bold [Inline] | Italic [Inline] | Underline [Inline] | CodeInline String | Link [Inline] String | Image [Inline] String | Quote [Inline]

πŸ§ͺ Tests

# Run unit tests
make tests_run

# or directly with stack
stack test

The project includes tests to verify:

  • Correct parsing of each format
  • Faithful conversion between formats
  • Error handling

πŸ› οΈ Development

Development compilation

stack build

Cleanup

make clean      # Clean temporary files
make fclean     # Clean everything and remove executable
make re         # Clean and recompile

Make command structure

  • make all: Compile the project
  • make clean: Clean temporary files
  • make fclean: Remove all generated files
  • make tests_run: Run tests
  • make re: Clean and recompile

πŸ› Error Handling

The program returns the following error codes:

  • 0: Success
  • 84: Argument error, file not found, or parsing error

Common errors:

  • Missing or invalid arguments
  • Input file not found
  • Unsupported format
  • Source document parsing error

πŸ“Š Test Results

Test Category Score Percentage
Basic Document 6/6 100%
Hard Test 2/4 50%
Json β†’ Document β†’ Markdown 12/12 100%
Markdown β†’ Document β†’ Json 12/12 100%
Options 5/5 100%
Robustness 9/9 100%
Simple Document 6/6 100%
Xml β†’ Document β†’ Markdown 12/12 100%
Total 64/66 97%

🎨 Coding Style

Fatal Major Minor Info
0 0 0 0

πŸ“„ License

This project is licensed under the GNU Public License version 3.0 - see the LICENSE file for details.

πŸ‘₯ Authors

EPITECH Project 2025 - B-FUN-400-LYN-4-1-mypandoc

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages