Skip to content

Instantly share code, notes, and snippets.

View mauro-oto's full-sized avatar

Mauro Otonelli mauro-oto

  • Buoy Software
  • Buenos Aires, Argentina
View GitHub Profile
# The goal of this problem is to extract headers from a block of text,
# and arrange them hierarchically.
#
# See the specs for more detail on the output
HEADER_HTML = /\<(h[\d])\>([^<>]+)\<\/h[\d]\>/
HEADER_LEVEL_AND_CONTENT = /h(?<level>[\d])(?<content>.*)/
def header_hierarchy(html)
html.scan(HEADER_HTML).map(&:join).map do |node|