A multi-format document converter written in Haskell, inspired by Pandoc. This project allows converting documents between different formats: Markdown, XML, and JSON.
- Description
- Features
- Installation
- Usage
- Supported Formats
- Examples
- Architecture
- Tests
- Development
- Error Handling
- Test Results
- Coding Style
- License
- Authors
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.
- 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
- Stack (Haskell build tool)
- GHC (Glasgow Haskell Compiler)
# Clone the project
git clone <repository-url>
cd mypandoc
# Compile the project
make all
# or directly with stack
stack build --copy-binsThe mypandoc executable will be generated in the current directory.
./mypandoc -i <input_file> -f <output_format> [-o <output_file>] [-e <input_format>]-i <file>: Input file to convert (required)-f <format>: Output format (required)markdownormd: Markdown formatxml: XML formatjson: JSON format
-o <file>: Output file (optional, prints to stdout if omitted)-e <format>: Input format (optional, automatically detected from extension)
- Headers (
#,##,###, etc.) - Paragraphs
- Bold (
**text**) - Italic (
*text*) - Bullet lists (
-or*) - Code blocks (
```) - Inline code (
`code`) - Links (
[text](url)) - Images (
)
Hierarchical structure with semantic elements corresponding to Markdown elements.
Structured representation of the document AST with all metadata preserved.
./mypandoc -i document.md -f xml -o document.xml./mypandoc -i document.xml -f json./mypandoc -i file.txt -e markdown -f json -o output.jsonThe test_files/ directory contains several examples:
syntaxe.md: Complete example with all supported elementssimple.xml: Basic XML documentall.md: Complex document with metadata
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
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]# Run unit tests
make tests_run
# or directly with stack
stack testThe project includes tests to verify:
- Correct parsing of each format
- Faithful conversion between formats
- Error handling
stack buildmake clean # Clean temporary files
make fclean # Clean everything and remove executable
make re # Clean and recompilemake all: Compile the projectmake clean: Clean temporary filesmake fclean: Remove all generated filesmake tests_run: Run testsmake re: Clean and recompile
The program returns the following error codes:
0: Success84: 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 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% |
| Fatal | Major | Minor | Info |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
This project is licensed under the GNU Public License version 3.0 - see the LICENSE file for details.
EPITECH Project 2025 - B-FUN-400-LYN-4-1-mypandoc