python: add all statements from index

Previously, only non-text statements (such as `**`) were added. Now also
`for`, `if`, `elif`, `else`, ... are added

See https://github.com/freeCodeCamp/devdocs/issues/696#issuecomment-1243554434
pull/1832/head
Simon Legner 2 years ago
parent dde51842f4
commit 77d7e2ea77

@ -90,8 +90,6 @@ module Docs
name = node.content.remove("\u{00b6}") name = node.content.remove("\u{00b6}")
name.concat " (#{self.name})" if slug.start_with?('library') name.concat " (#{self.name})" if slug.start_with?('library')
entries << [name, node.parent['id']] entries << [name, node.parent['id']]
statement = name[/The (.+) statement/, 1]
entries << ["#{statement} (statement)", node.parent['id'], 'Statements'] if statement && slug.start_with?('reference')
end end
end end
@ -112,19 +110,25 @@ module Docs
name = node.children.first name = node.children.first
next unless name.text? next unless name.text?
name = name.text.strip() name = name.text.strip()
next if name[/^\w/] || name[/^-+\w/] next if name[/Python Enhancement Proposals/]
node.css('> ul > li > a').each do |inner_node| node.css('> ul > li > a').each do |inner_node|
inner_name = inner_node.text.strip() inner_name = inner_node.text.strip()
next if inner_name[/\[\d+\]/] next if inner_name[/\[\d+\]/]
href = inner_node['href']
next if (name[/^\w/] || name[/^-+\w/]) && !href[/stmts/]
type = case inner_name type = case inner_name
when 'keyword'
'Keywords'
when 'operator' when 'operator'
'Operators' 'Operators'
when 'in regular expressions' when 'in regular expressions'
'Regular Expression' 'Regular Expression'
when /statement/
'Statements'
else else
'Symbols' 'Symbols'
end end
entries << ["#{name} (#{inner_name})", inner_node['href'], type] entries << ["#{name} (#{inner_name})", href, type]
end end
end end
end end

Loading…
Cancel
Save