Skip to content

Commit

Permalink
For [GH #161] - extract codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
hkoba committed Mar 21, 2019
1 parent 6795d88 commit ec304af
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Lite/LanguageServer/SpecParser.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env perl
package YATT::Lite::LanguageServer::SpecParser;
use strict;
use warnings qw(FATAL all NONFATAL misc);
use File::AddInc;
use MOP4Import::Base::CLI_JSON -as_base;

# Lite/LanguageServer/SpecParser.pm --flatten --output=raw extract_codeblock typescript specification.md
sub extract_codeblock {
(my MY $self, my $langId, local @ARGV) = @_;
local $_;
my ($chunk, @result);
while (<<>>) {
my $line = s{^```$langId\b}{} .. s{^```}{}
or next;
my $end = $line =~ /E0/;
s/\r//;
$chunk .= $_ if $line >= 2 and not $end;
if ($end) {
push @result, $chunk;
$chunk = "";
}
}
@result;
}
MY->run(\@ARGV) unless caller;
1;

0 comments on commit ec304af

Please sign in to comment.