22
22
def count_known_instances ( file )
23
23
section_nodes = collect_section_nodes ( file , "Known Instances" )
24
24
list_nodes = [ ]
25
+
25
26
# pick the first list in the "Known Instances" section, and return the number of elements in that list.
26
27
# CAUTION: this assumes a certain structure across all patterns. Therefore fairly brittle.
27
28
list_nodes = section_nodes . select { |n | n . type == :list }
@@ -32,15 +33,16 @@ def count_known_instances(file)
32
33
return known_instances_count
33
34
end
34
35
36
+ # Extract all nodes below a given headline
35
37
def collect_section_nodes ( file , section_title )
36
38
markdown = open ( file ) . readlines ( ) . join
37
- doc = CommonMarker . render_doc ( markdown )
39
+ doc = Commonmarker . parse ( markdown )
38
40
39
41
title_found = false
40
42
section_nodes = [ ]
41
43
42
44
doc . walk do |node |
43
- if node . type == :header
45
+ if node . type == :heading
44
46
if title_found == false
45
47
node . each do |subnode |
46
48
if subnode . type == :text and subnode . string_content == section_title
@@ -70,7 +72,10 @@ def collect_section_nodes(file, section_title)
70
72
71
73
l1_patterns . each do |file |
72
74
known_instances_count = count_known_instances ( file )
73
- puts "#{ known_instances_count } | #{ file } " if known_instances_count >= 1
75
+ file_display = file . gsub ( "../../patterns/1-initial/" , "" )
76
+ file_link = file . gsub ( "../../" , "https://github.com/InnerSourceCommons/InnerSourcePatterns/blob/main/" )
77
+
78
+ puts "#{ known_instances_count } | [#{ file_display } ](#{ file_link } )"
74
79
end
75
80
76
81
puts "\n "
@@ -80,5 +85,8 @@ def collect_section_nodes(file, section_title)
80
85
81
86
l2_patterns . each do |file |
82
87
known_instances_count = count_known_instances ( file )
83
- puts "#{ known_instances_count } | #{ file } " if known_instances_count >= 3
88
+ file_display = file . gsub ( "../../patterns/2-structured/" , "" )
89
+ file_link = file . gsub ( "../../" , "https://github.com/InnerSourceCommons/InnerSourcePatterns/blob/main/" )
90
+
91
+ puts "#{ known_instances_count } | [#{ file_display } ](#{ file_link } )"
84
92
end
0 commit comments