Anki-Import

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

out
share/log_config/anki-import.cfg
share/log_config/test.cfg
t/00-use_ok.t
t/01-class.t
t/02-cli.t
t/03-format_tests.t
t/data/code_with_blank_lines.anki
t/data/cs61.anki
t/data/distzilla.anki
t/data/escape_angle_brackets.anki
t/data/perl_modules.anki
t/data/source.anki
t/data/source2.anki
t/data/tag_test.anki

lib/Anki/Import.pm  view on Meta::CPAN


      # exit whitespace mode, close out HTML, add blank lines
      if ($line =~ /^`{3,3}$/ && $ws_mode) {
        $ws_mode = 0;
        $$last_line .= "</div><br><br>";
        next;
      }

      # handle lines differently based on if we are preserving whitespace
      if ($ws_mode) {
        # escape characters in preserved text
        if ($line =~ /^`\s*$/) {
          $$last_line .= '<br>';
          next;
        }
        $line =~ s/(?<!\\)`/\\`/g;
        $line =~ s/(?<!\\)\*/\\*/g;
        $line =~ s/(?<!\\)%/\\%/g;
        $$last_line .= $line . "<br>";
      } else {
        push @lines, $line;

lib/Anki/Import.pm  view on Meta::CPAN

         . ' file and try again. Run "perldoc Anki::Import" for more help.') if $ws_mode;

    logd($field_out, 'field_out');

    shift @lines if !$lines[0];
    my $field = join ' ', @lines;

    # clean up dangling breaks
    $field =~ s/<br><\/div>/<\/div>/g;

    # handle formatting codes in text, preserve escaped characters

    # preserve angle brackets between backticks
    my $parts = [ split /[^\\]`|^`/, $field, -1];

    my $count = 0;
    foreach my $part (@$parts) {
      $count++;
      next if ($count % 2);  # only substitute on odd number array items
      $part =~ s/</&lt;/g;
    }

lib/Anki/Import.pm  view on Meta::CPAN

    logd(\@new_tags, 'new_tags');
    my $new_tags = join (' ', @new_tags);
    $fields[-1] = $new_tags;
  }
  $new_autotags = 0;

  my $out = join ("\t", @fields);

  # create cloze fields
  my $cloze_count = 1;
  # TODO: should probably handle escaped braces just in case
  while ($out =~ /\{\{\{(.*?)}}}/) {
    $out =~ s/\{\{\{(.*?)}}}/{{c${cloze_count}::$1}}/s;
    $cloze_count++;
  }
  logd($out, 'out');

  $out .= "\n";
}

1; # Magic true value

t/03-format_tests.t  view on Meta::CPAN


is (mcount("\t"), 1, 'got expected number of tabs');
is (mcount("\n"), 0, 'got expected number of newlines');
is (mcount("^<div"), 1, 'begins with div tags');
is (mcount("/div>\t"), 1, 'div tag closed before tab');
is (mcount("\tAnswer\$"), 1, 'answer properly formatted');
is (mcount(">Line 1<br><br>"), 1, 'line 1 properly formatted');
is (mcount("><br>Line 2<br><br>"), 1, 'line 2 properly formatted');
is (mcount(">Line 3</div>"), 1, 'line 3 does not end in <br>');

$data = get_data('escape_angle_brackets', 'basic');

is (mcount("&lt;"), 4, 'got expected number of html entities');
is ($data =~ /with &lt;angle/, 1, 'first angle bracket replaced');
is ($data =~ /one &lt;angle/, 1, 'second angle bracket replaced');
is ($data =~ /more &lt;of/, 1, 'third angle bracket replaced');
is ($data =~ /of &lt;them/, 1, 'last angle bracket replaced');

use Data::Dumper qw(Dumper);

print Dumper $data;



( run in 0.417 second using v1.01-cache-2.11-cpan-c21f80fb71c )