diff --git a/README.md b/README.md index 11a90972..489774f9 100644 --- a/README.md +++ b/README.md @@ -1030,6 +1030,7 @@ RAML (raml) RapydScript (pyj) Razor (cshtml) Rexx (rexx) +Rmd (Rmd) RobotFramework (robot, tsv) Ruby (rake, rb) Ruby HTML (rhtml) diff --git a/Unix/t/00_C.t b/Unix/t/00_C.t index b0a4bde5..dc243a09 100755 --- a/Unix/t/00_C.t +++ b/Unix/t/00_C.t @@ -565,6 +565,11 @@ my @Tests = ( 'ref' => '../tests/outputs/utilities.R.yaml', 'args' => '../tests/inputs/utilities.R', }, + { + 'name' => 'Rmd', + 'ref' => '../tests/output/test.Rmd.yaml', + 'args' => '../tests/inputs/test.Rmd', + }, { 'name' => 'Ruby', 'ref' => '../tests/outputs/messages.rb.yaml', diff --git a/cloc b/cloc index f3056232..36d85ca1 100755 --- a/cloc +++ b/cloc @@ -5382,6 +5382,28 @@ sub remove_f90_comments { # {{{1 print "<- remove_f90_comments\n" if $opt_v > 2; return @save_lines; } # 1}}} +sub reduce_to_rmd_code_blocks { #{{{1 + my ($ra_lines) = @_; #in + print "<- remove_f90_comments\n" if $opt_v > 2; + print "-> reduce_to_rmd_code_blocks()\n" if $opt_v > 2; + + my $in_code_block = 0; + my @save_lines = (); + foreach (@{$ra_lines}) { + if ( m/^```\{\s*[[:alpha:]]/ ) { + $in_code_block = 1; + next; + } + if ( m/^```\s*$/ ) { + $in_code_block = 0; + } + next if (!$in_code_block); + push @save_lines, $_; + } + + print "<- reduce_to_rmd_code_blocks()\n" if $opt_v> 2; + return @save_lines; +} # 1}}} sub remove_matches { # {{{1 my ($ra_lines, # in $pattern , # in Perl regular expression (case insensitive) @@ -6434,6 +6456,7 @@ sub set_constants { # {{{1 'psm1' => 'PowerShell' , 'R' => 'R' , 'r' => 'R' , + 'Rmd' => 'Rmd' , 'raml' => 'RAML' , 'rkt' => 'Racket' , 'rktl' => 'Racket' , @@ -7223,6 +7246,11 @@ sub set_constants { # {{{1 [ 'remove_matches' , '^\s*#' ], [ 'remove_inline' , '#.*$' ], ], + 'Rmd' => [ + [ 'reduce_to_rmd_code_blocks' ], + [ 'remove_matches' , '^\s*#' ], + [ 'remove_inline' , '#.*$' ], + ], 'Racket' => [ [ 'remove_matches' , '^\s*;' ], [ 'remove_inline' , ';.*$' ], @@ -7592,6 +7620,7 @@ sub set_constants { # {{{1 'PowerShell' => '\\\\$' , 'Python' => '\\\\$' , 'R' => '\\\\$' , + 'Rmd' => '\\\\$' , 'Ruby' => '\\\\$' , 'sed' => '\\\\$' , 'Swift' => '\\\\$' , @@ -7686,6 +7715,7 @@ sub set_constants { # {{{1 'CHANGES' => 1, 'COPYING' => 1, 'COPYING' => 1, + 'DESCRIPTION' => 1, # R packages metafile '.cvsignore' => 1, 'Entries' => 1, 'FAQ' => 1, @@ -7693,6 +7723,7 @@ sub set_constants { # {{{1 'INSTALL' => 1, 'MAINTAINERS' => 1, 'MD5SUMS' => 1, + 'NAMESPACE' => 1, # R packages metafile 'NEWS' => 1, 'readme' => 1, 'Readme' => 1, @@ -8206,6 +8237,7 @@ sub set_constants { # {{{1 'quickbuild' => 2.86, 'quiz' => 5.33, 'R' => 3.00, + 'Rmd' => 3.00, 'Racket' => 1.50, 'rally' => 2.00, 'ramis ii' => 2.00, diff --git a/tests/inputs/test.Rmd b/tests/inputs/test.Rmd new file mode 100644 index 00000000..41bce875 --- /dev/null +++ b/tests/inputs/test.Rmd @@ -0,0 +1,33 @@ +--- +title: "Untitled" +author: "cloc test" +date: "5/12/2018" +output: html_document +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +## R Markdown + +This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . + +When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: + +```{r cars} +summary(cars) +# summary(cars) +``` + +## Including Plots + +You can also embed plots, for example: + +```{r pressure, echo=FALSE} +plot(pressure) + +plot(cars) +``` + +Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. diff --git a/tests/outputs/test.Rmd.yaml b/tests/outputs/test.Rmd.yaml new file mode 100644 index 00000000..8ba5af28 --- /dev/null +++ b/tests/outputs/test.Rmd.yaml @@ -0,0 +1,24 @@ + 1 text file. + 1 unique file. + 0 files ignored. + +--- +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 1.77 + elapsed_seconds : 0.00812411308288574 + n_files : 1 + n_lines : 33 + files_per_second : 123.090359501101 + lines_per_second : 4061.98186353632 +Rmd : + nFiles: 1 + blank: 10 + comment: 19 + code: 4 +SUM: + blank: 10 + comment: 19 + code: 4 + nFiles: 1