https://github.com/jbytecode/markdownrenderer.jl
Custom Markdown Renderer for Julia
https://github.com/jbytecode/markdownrenderer.jl
Last synced: 26 days ago
JSON representation
Custom Markdown Renderer for Julia
- Host: GitHub
- URL: https://github.com/jbytecode/markdownrenderer.jl
- Owner: jbytecode
- License: mit
- Created: 2024-12-13T16:12:59.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-13T17:42:44.000Z (5 months ago)
- Last Synced: 2025-02-16T16:38:37.797Z (3 months ago)
- Language: Julia
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MarkdownRenderer.jl
Custom Markdown Renderer for Julia
## Installation
```julia
julia> ]
(@v1.11) pkg> add https://github.com/jbytecode/MarkdownRenderer.jl
```## Usage
```julia
using MarkdownRendererio = IOBuffer()
# or
# io = open("test.md", "w")
# io => stdout for console output
render(io, Header(1, "Test"))
render(io, Header(2, "Test"))
render(io, Header(3, "Test"))
render(io, Header(4, "Test"))
render(io, Header(5, "Test"))
render(io, Header(6, "Test"))
render(io, Paragraph("Test"))
render(io, CodeBlock("julia", "println(1)"))
render(io, Image("Description","test.png"))
render(io, Table(["a", "b"], [1 2; 3 4]))
render(io, Link("Description", "test.png"))
render(io, Quoted("Test"))
render(io, HorizontalRule())
render(io, OrderedList(["item1", "item2"]))
render(io, UnorderedList(["item1", "item2"]))
# close(io)
```The rendered output is written to `io` and can be collected with
```julia
md = String(take!(io))
"# Test\n## Test\n### Test\n#### Test\n##### Test\n###### Test\nTest\n```julia\nprintln(1)\n```\n\n| a | b |\n|--|--|\n| 1 | 2 |\n| 3 | 4 |\n[Description](test.png)\n> Test\n----\n1. item1\n2. item2\n- item1\n- item2\n"
```and it is rendered as
# Test
## Test
### Test
#### Test
##### Test
###### Test
Test
```julia
println(1)
```

| a | b |
|--|--|
| 1 | 2 |
| 3 | 4 |
[Description](test.png)
> Test
----
1. item1
2. item2
- item1
- item2## Using Pandoc to convert the output to PDF
```julia
# Create a random 3x3 matrix
m = rand(3,3)# Open a file in write mode
myfile = open("test.md", "w")# Render the header
render(myfile, MarkdownRenderer.Header(1, "Here is the random matrix"))# Render the matrix as a table
render(myfile, MarkdownRenderer.Table(["1", "2", "3"], m))# Render a link
render(myfile, MarkdownRenderer.Link("Github", "https://github.com"))# Close the file
close(myfile)# Convert to PDF
run(`pandoc -o test.pdf test.md`)
```