This function converts a markdown-style hierarchical annotation into a data.frame with from -> to columns. For example a text like this:#' #Heading 1 #Heading 2 ##Heading 2.1 ##Heading 2.2 #Heading 3 would be converted to a data.frame with all the links (e.g. Heading 2 -> Heading 2.1)

parse_single_annotation(note, pattern = "#+")

Arguments

note

a length 1 character vector, with an annotation to be parsed

pattern

a length 1 character vector, with the pattern to parse the annotation. This is passed to stringr::str_split and stringr::str_extract_all. The default value matches 1 or more hashtags (#) and succesive hashtags indicate the level of the title/code

Value

a data.frame

Examples

parse_single_annotation(
  "#1 ##1.1 ##1.2 ###1.2.1 ###1.2.2 ##1.3 #2 ##2.1 ###2.1.1"
)
#> # A tibble: 9 × 2
#>   from  to   
#>   <chr> <chr>
#> 1 NA    1    
#> 2 1     1.1  
#> 3 1     1.2  
#> 4 1.2   1.2.1
#> 5 1.2   1.2.2
#> 6 1     1.3  
#> 7 NA    2    
#> 8 2     2.1  
#> 9 2.1   2.1.1