From 638f3b8aa76b291b384c4ef02ba8902ca9a12beb Mon Sep 17 00:00:00 2001 From: Tomoaki Mizushima <31090417+chachamimm@users.noreply.github.com> Date: Tue, 18 Feb 2025 20:47:13 +0900 Subject: [PATCH] perl script for Automate Conversion of US/UC/UCC from MD to HTML Based on [Issue #326](https://github.com/w3c/wot-usecases/issues/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. --- CONTRIBUTIONS/md2html_YAML.pl | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 CONTRIBUTIONS/md2html_YAML.pl diff --git a/CONTRIBUTIONS/md2html_YAML.pl b/CONTRIBUTIONS/md2html_YAML.pl new file mode 100644 index 00000000..111649f4 --- /dev/null +++ b/CONTRIBUTIONS/md2html_YAML.pl @@ -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 () { + chomp; + s//>/g; + s/\r$//; + + while ($_ =~ /\[.*\]\(.*\)/g) { + $_ =~ s/\[(.*)\]\((.*)\)/$1<\/a>/; + } + + if (/^## Title: (.*)$/) { + $current_level = 2; + ${title} = $1; + print "
\n"; + print "

${title}

\n"; + print "
\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 "
${section}
\n"; + print "
\n"; + $prev_level = $current_level; + $is_list = 0; + + } elsif (/^#### (.*)$/) { + print "

$_

\n"; + $is_list = 0; + + } elsif (/^(\-|\*) (.*)$/) { + ${topic} = $2; + if ($is_list eq 0) { + print "
    \n"; + } + print "
  • ${topic}
  • \n"; + $is_list = 1; + + } else { + if (($is_list eq 1) && (/^$/)) { + print "
\n"; + $is_list = 0; + } + if (/^```/) { + } else { + print "$_\n"; + } + } +} + +print "<\/dd>\n"; +print "<\/dl>\n"; +print "<\/section>\n"; +close(IN);