Elliot Temple replied to my last post with several good comments and I wanted to address them.
Elliot Temple’s comments have a yellow background:
123 string_of_article = ""string_of_article << post_titlestring_of_article << body_of_article
I would write:
1 string_of_article = post_title + body_of_article
You’re mutating state for no reason and making it longer.
Great suggestion, thanks!
For sanitizing, shouldn’t you keep div and span tags? I’ve used those for formatting sometimes (offhand I know some blockquotes use divs). Also shouldn’t you allow hr tags? I use those.
All good suggestions, thanks. I don’t really have a good understanding of HTML and CSS yet so I’m not good at judging things like what’s important to include in a sanitize list. I was mostly judging by noting that the output files looked good enough, but the hr tag in particular helps with a problem I’d noticed on some of the pages so thanks for pointing that out.
The <hr>
tag was not agreeable to the Upmark gem, so I added the following to handle that issue
1 |
string_of_article = string_of_article.gsub(/(<hr>)/, "\n" + "----" + "\n")
|
Also shouldn’t you convert h1 and h2 tags similar to the h3?
Yeah it doesn’t hurt to do them all!
Elliot also suggested I handle the RegEx for header tags by just doing substitution instead of using a block. This is what I came up with for the header issue with Elliot’s help. (my syntax highlighter isn’t handling
#{}
well so ignore the highlighting on this code snippet):
1
2
3
|
1.upto(6) do |n|
string_of_article.gsub!(/<h#{n}>(.*)<\/h#{n}>/,"\n#{"#"*n} \\1\n")
end
|
And I don’t understand why the sanitizer doesn’t have b, i, u, em, strong on the list.
Fixed thanks.
Thanks for your help Elliot!
With regards to code in blog comments, Markdown has been activated in the comments, and it plays nicely with my syntax highlighting plugin! (I’m using Crayon if anyone is curious)
Inline code syntax is `back-ticks like this`
and which produces code styled like this
and for blocks of code
```
its a fence of three backticks around your code like this
```
1
2
|
which produces code which looks like this
|