Last active
August 29, 2015 14:26
-
-
Save korny/ad8825dffc845b09e411 to your computer and use it in GitHub Desktop.
Super Markdown Parser (Ruby flavored)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pair programming with @raluka at @eurucamp!