Skip to content

Commit

Permalink
perl script for Automate Conversion of US/UC/UCC from MD to HTML
Browse files Browse the repository at this point in the history
Based on [Issue #326](#326), I have made changes to the perl script from md2html.pl for automatic conversion from US/UC/UCC MD to HTML.

I created perl script for Automate Conversion of US/UC/UCC from MD to HTML.
  • Loading branch information
chachamimm authored Feb 18, 2025
1 parent 23bacc0 commit 638f3b8
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions CONTRIBUTIONS/md2html_YAML.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/perl

my $src = "";
my $id = "";
my $title = "";
my $section = "";
my $section_id = "";
my $is_list = 0;
my $topic = "";
my $current_level = 0;
my $prev_level = 0;

$src = $ARGV[0];
$id = $src;
$id =~ s/\.md$//;

open(IN, ${src}) || die "${src}: $!\n";
while (<IN>) {
chomp;
s/</&lt;/g;
s/>/&gt;/g;
s/\r$//;

while ($_ =~ /\[.*\]\(.*\)/g) {
$_ =~ s/\[(.*)\]\((.*)\)/<a href="$2">$1<\/a>/;
}

if (/^## Title: (.*)$/) {
$current_level = 2;
${title} = $1;
print "<section id=\"${id}\">\n";
print "<h2>${title}</h2>\n";
print "<dl>\n";
$is_list = 0;

} elsif (/^### (.*)$/) {
$current_level = 3;
${section} = $1;
${section} =~ s/:([\s]+|)$//;

${section_id} = $section;
${section_id} =~ s/\(s\)//;
${section_id} =~ tr/A-Z/a-z/;

${id} =~ tr/A-Z/a-z/;

if ($prev_level >= $current_level) {
print "<\/dd>\n";
}
print "<dt>${section}</dt>\n";
print "<dd>\n";
$prev_level = $current_level;
$is_list = 0;

} elsif (/^#### (.*)$/) {
print "<p>$_</p>\n";
$is_list = 0;

} elsif (/^(\-|\*) (.*)$/) {
${topic} = $2;
if ($is_list eq 0) {
print "<ul>\n";
}
print "<li>${topic}</li>\n";
$is_list = 1;

} else {
if (($is_list eq 1) && (/^$/)) {
print "</ul>\n";
$is_list = 0;
}
if (/^```/) {
} else {
print "$_\n";
}
}
}

print "<\/dd>\n";
print "<\/dl>\n";
print "<\/section>\n";
close(IN);

0 comments on commit 638f3b8

Please sign in to comment.