Skip to content

Upgrade to latest commonmarker version #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions meta/scripts/find_upgradeable_patterns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
def count_known_instances(file)
section_nodes = collect_section_nodes(file, "Known Instances")
list_nodes = []

# pick the first list in the "Known Instances" section, and return the number of elements in that list.
# CAUTION: this assumes a certain structure across all patterns. Therefore fairly brittle.
list_nodes = section_nodes.select {|n| n.type == :list}
Expand All @@ -32,15 +33,16 @@ def count_known_instances(file)
return known_instances_count
end

# Extract all nodes below a given headline
def collect_section_nodes(file, section_title)
markdown = open(file).readlines().join
doc = CommonMarker.render_doc(markdown)
doc = Commonmarker.parse(markdown)

title_found = false
section_nodes = []

doc.walk do |node|
if node.type == :header
if node.type == :heading
if title_found == false
node.each do |subnode|
if subnode.type == :text and subnode.string_content == section_title
Expand Down Expand Up @@ -70,7 +72,10 @@ def collect_section_nodes(file, section_title)

l1_patterns.each do |file|
known_instances_count = count_known_instances(file)
puts "#{known_instances_count} | #{file}" if known_instances_count >= 1
file_display = file.gsub("../../patterns/1-initial/","")
file_link = file.gsub("../../","https://github.com/InnerSourceCommons/InnerSourcePatterns/blob/main/")

puts "#{known_instances_count} | [#{file_display}](#{file_link})"
end

puts "\n"
Expand All @@ -80,5 +85,8 @@ def collect_section_nodes(file, section_title)

l2_patterns.each do |file|
known_instances_count = count_known_instances(file)
puts "#{known_instances_count} | #{file}" if known_instances_count >= 3
file_display = file.gsub("../../patterns/2-structured/","")
file_link = file.gsub("../../","https://github.com/InnerSourceCommons/InnerSourcePatterns/blob/main/")

puts "#{known_instances_count} | [#{file_display}](#{file_link})"
end