Skip to content

Instantly share code, notes, and snippets.

@korny
Last active August 29, 2015 14:26
Show Gist options
  • Save korny/ad8825dffc845b09e411 to your computer and use it in GitHub Desktop.
Save korny/ad8825dffc845b09e411 to your computer and use it in GitHub Desktop.
Super Markdown Parser (Ruby flavored)
def markdown_h(input)
input.gsub(/^(?'hashtag'#+) (?'title'.*)/) do
level = [$~[:hashtag].size, 6].min
"<h#{level}>#{$~[:title]}</h#{level}>"
end
end
def markdown_em(input)
input.gsub(/\*(?'text'\S+)\*/) do
"<em>#{$~[:text]}</em>"
end
end
def markdown_strong(input)
input.gsub(/\*\*(?'text'\S+)\*\*/) do
"<strong>#{$~[:text]}</strong>"
end
end
def markdown(input)
input = markdown_h(input)
input = markdown_strong(input)
input = markdown_em(input)
input
end
puts markdown(DATA.read)
__END__
# H1
## H2
### *H3*
#### H4
##### **H5**
###### H6
####### H7
* Ba**na**na
* *Plum*
* Apple
## Eurucamp *2015*
Lorem ipsum dolor **sit** amet, consectetur adipisicing elit, sed do eiusmod *tempor* incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in *reprehenderit in voluptate* velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@korny
Copy link
Author

korny commented Aug 1, 2015

Pair programming with @raluka at @eurucamp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment