markdown2beamer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +9 -0
- data/README.md +24 -0
- data/bin/markdown2beamer +14 -0
- data/lib/markdown2beamer.rb +133 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91ef901c785c5baba088cd3a3c77226b81d4daaf4c0e4f1163eab04713705068
|
4
|
+
data.tar.gz: 271350e586e51d1a76f55573345152092bf14bd382b4954fc78f679b2b30a7ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ac0e5de40a37d5b64b92104b300d5d0f63d11e7ddab6958ece9d8cb3bf76aa195f872fc26c5f3bcab721f3ac8226c52e52100093e3a78f222cd1d1aaec73e36
|
7
|
+
data.tar.gz: f444082fa8a24fc5806cf00085a74a360dab161d518db0db3b3997d31c264cb33d4b4278be6d780213cb5ef925a94f97e32f212e71e1fc1df458c0c91342247b
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 firefly-cpp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# markdown2beamer
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
- **Markdown to Beamer Conversion**: Converts standard Markdown headers, lists, tables, images, bold, and italic text to Beamer presentation format.
|
6
|
+
- **Supports Headers**: Transforms Markdown headers (`#`, `##`, etc.) into Beamer slides with appropriate font sizes.
|
7
|
+
- **List Conversion**: Supports both unordered (`*`, `-`) and ordered lists (`1.`).
|
8
|
+
- **Table Conversion**: Converts Markdown tables into Beamer-style tabular format.
|
9
|
+
- **Image Embedding**: Embeds images with captions into the Beamer presentation.
|
10
|
+
- **Text Formatting**: Supports bold (`**bold**`) and italic (`*italic*`) text.
|
11
|
+
|
12
|
+
## 📦 Installation
|
13
|
+
|
14
|
+
```sh
|
15
|
+
$ gem install markdown2beamer
|
16
|
+
```
|
17
|
+
|
18
|
+
## 🔑 License
|
19
|
+
|
20
|
+
This package is distributed under the MIT License. This license can be found online at <http://www.opensource.org/licenses/MIT>.
|
21
|
+
|
22
|
+
## Disclaimer
|
23
|
+
|
24
|
+
This framework is provided as-is, and there are no guarantees that it fits your purposes or that it is bug-free. Use it at your own risk!
|
data/bin/markdown2beamer
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "markdown2beamer"
|
4
|
+
|
5
|
+
if ARGV.length != 2
|
6
|
+
puts "Usage: markdown2beamer input.md output.tex"
|
7
|
+
exit 1
|
8
|
+
else
|
9
|
+
input_file = ARGV[0]
|
10
|
+
output_file = ARGV[1]
|
11
|
+
|
12
|
+
converter = MarkdownToBeamer::Converter.new(input_file, output_file)
|
13
|
+
converter.convert
|
14
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module MarkdownToBeamer
|
2
|
+
class Converter
|
3
|
+
def initialize(input_file, output_file)
|
4
|
+
@input_file = input_file
|
5
|
+
@output_file = output_file
|
6
|
+
end
|
7
|
+
|
8
|
+
def convert
|
9
|
+
content = File.read(@input_file)
|
10
|
+
latex_content = convert_to_beamer(content)
|
11
|
+
File.write(@output_file, wrap_in_beamer(latex_content))
|
12
|
+
puts "Conversion complete! Beamer presentation saved to #{@output_file}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def convert_to_beamer(content)
|
18
|
+
content = process_content(content)
|
19
|
+
content = convert_bold_and_italics(content)
|
20
|
+
content = convert_lists(content)
|
21
|
+
content = convert_images(content)
|
22
|
+
content = convert_tables(content)
|
23
|
+
content
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_content(content)
|
27
|
+
lines = content.split("\n")
|
28
|
+
processed_lines = []
|
29
|
+
in_frame = false
|
30
|
+
|
31
|
+
lines.each_with_index do |line, index|
|
32
|
+
header_match = line.match(/^(#+) (.*)$/)
|
33
|
+
if header_match
|
34
|
+
if in_frame
|
35
|
+
processed_lines << "\\end{frame}"
|
36
|
+
in_frame = false
|
37
|
+
end
|
38
|
+
|
39
|
+
header_level = header_match[1].length
|
40
|
+
header_text = header_match[2]
|
41
|
+
font_size = case header_level
|
42
|
+
when 1 then "\\huge"
|
43
|
+
when 2 then "\\Large"
|
44
|
+
when 3 then "\\large"
|
45
|
+
when 4 then "\\normalsize"
|
46
|
+
else "\\small"
|
47
|
+
end
|
48
|
+
|
49
|
+
processed_lines << "\\begin{frame}"
|
50
|
+
processed_lines << "\\frametitle{#{font_size} #{header_text}}"
|
51
|
+
in_frame = true
|
52
|
+
else
|
53
|
+
processed_lines << line
|
54
|
+
end
|
55
|
+
|
56
|
+
if index == lines.length - 1 && in_frame
|
57
|
+
processed_lines << "\\end{frame}"
|
58
|
+
in_frame = false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
processed_lines.join("\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_bold_and_italics(content)
|
66
|
+
content.gsub(/\*\*(.*?)\*\*/, '\\textbf{\1}')
|
67
|
+
.gsub(/\*(.*?)\*/, '\\textit{\1}')
|
68
|
+
end
|
69
|
+
|
70
|
+
def convert_lists(content)
|
71
|
+
content = convert_unordered_list(content)
|
72
|
+
convert_ordered_list(content)
|
73
|
+
end
|
74
|
+
|
75
|
+
def convert_unordered_list(content)
|
76
|
+
content.gsub(/((^\s*[\*\-\+]\s+.*\n)+)/) do |match|
|
77
|
+
items = match.strip.split("\n").map { |item| item.gsub(/^\s*[\*\-\+]\s+/, '\\item ') }
|
78
|
+
"\\begin{itemize}\n#{items.join("\n")}\n\\end{itemize}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def convert_ordered_list(content)
|
83
|
+
content.gsub(/((^\s*\d+\.\s+.*\n)+)/) do |match|
|
84
|
+
items = match.strip.split("\n").map { |item| item.gsub(/^\s*\d+\.\s+/, '\\item ') }
|
85
|
+
"\\begin{enumerate}\n#{items.join("\n")}\n\\end{enumerate}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def convert_tables(content)
|
90
|
+
content.gsub(/^\|(.*)\|\n\|([ \-:|]+)\|\n((\|(.*)\|\n)+)/) do |match|
|
91
|
+
rows = match.strip.split("\n")
|
92
|
+
header = rows[0].split('|').map(&:strip).reject(&:empty?)
|
93
|
+
num_columns = header.size
|
94
|
+
align = "|#{'c|' * num_columns}"
|
95
|
+
|
96
|
+
body = rows[2..-1].map do |row|
|
97
|
+
cells = row.split('|').map(&:strip).reject(&:empty?).join(' & ')
|
98
|
+
"#{cells} \\\\"
|
99
|
+
end.join("\n\\hline\n")
|
100
|
+
|
101
|
+
header_line = header.join(' & ') + ' \\\\'
|
102
|
+
"\\begin{table}\n\\centering\n\\begin{tabular}{#{align}}\n\\hline\n#{header_line}\n\\hline\n#{body}\n\\hline\n\\end{tabular}\n\\caption{Table Caption}\n\\end{table}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def convert_images(content)
|
107
|
+
content.gsub(/\!\[(.*?)\]\((.*?)\)/) do
|
108
|
+
alt_text = $1
|
109
|
+
image_path = $2
|
110
|
+
"\\begin{figure}\n\\centering\n\\includegraphics[width=\\textwidth]{#{image_path}}\n\\caption{#{alt_text}}\n\\end{figure}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def wrap_in_beamer(content)
|
115
|
+
<<~LATEX
|
116
|
+
\\documentclass{beamer}
|
117
|
+
\\usepackage{graphicx}
|
118
|
+
\\usepackage{jourcl}
|
119
|
+
\\title{Presentation}
|
120
|
+
\\author{Iztok}
|
121
|
+
\\date{\\today}
|
122
|
+
|
123
|
+
\\begin{document}
|
124
|
+
|
125
|
+
\\frame{\\titlepage}
|
126
|
+
|
127
|
+
#{content}
|
128
|
+
|
129
|
+
\\end{document}
|
130
|
+
LATEX
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: markdown2beamer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- firefly-cpp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- iztok@iztok-jr-fister.eu
|
16
|
+
executables:
|
17
|
+
- markdown2beamer
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- bin/markdown2beamer
|
24
|
+
- lib/markdown2beamer.rb
|
25
|
+
homepage: https://codeberg.org/firefly-cpp/markdown2beamer
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata:
|
29
|
+
homepage_uri: https://codeberg.org/firefly-cpp/markdown2beamer
|
30
|
+
source_code_uri: https://codeberg.org/firefly-cpp/markdown2beamer
|
31
|
+
changelog_uri: https://codeberg.org/firefly-cpp/markdown2beamer
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.5.16
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Convert markdown to beamer
|
51
|
+
test_files: []
|