
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Mark It Zero! adds a markdown editor (with syntax highlighting) to your Rails' forms, and can automatically convert markdown to HTML on save.
The editor we're using is almost entirely this fantastic javascript editor by Hsiaoming Yang. The converter uses Redcarpet and Pygments.rb.
This gem is meant to work with Ruby on Rails projects. I recommend you add it to your project's Gemfile:
gem 'mark_it_zero'
Then install your bundle:
$ bundle
There are two main pieces to this gem:
They are not dependent on one another, and can be used separately.
To use the markdown editor, first make sure you have the assets included in your manifest file.
You'll want styles:
@import 'mark_it_zero';
And scripts:
//= require jquery
//= require mark_it_zero
Note: Mark It Zero! automatically requires jQuery, so if you forget, it will still work fine (magic!).
The markdown editor is simple. There's a markdown
method added onto your form
object. So, all you have to do is this:
<%= [form_object].markdown :[markdown_column] %>
So, if your markdown column is, for example, body_markdown
, and your form
object is f
, then this would look like:
<%= f.markdown :body_markdown %>
Easy, right?
Mark It Zero! adds some instance methods to your model if you want to store both the markdown and HTML.
I prefer to store both markdown and HTML because then the markdown is only parsed on save (which can be time-consuming), as opposed to every read.
All you have to do is add the converts_markdown
method to your model.
converts_markdown :[markdown_column], :[html_column]
For example, if I have a Post
model that has a body_markdown
and a
body_html
column for storing markdown and html, my model might look like
this:
class Post < ActiveRecord::Base
converts_markdown :body_markdown, :body_html
end
Whenever you use this method, you get a set of methods (dynamically named) available to you. Using this example, you would get the following methods:
convert_body_markdown_to_body_html
: Will update the body_markdown
column
with the converted html from the body_markdown
column.clean_body_markdown
: The markdown_body
value, after being cleaned.Notice the pattern. If the columns were simple md
and html
, then the
methods would be convert_md_to_html
and clean_md
.
The converter is run using the after_save
callback.
YouTube Videos
Having a YouTube URL as a paragraph in markdown will convert the URL to an embedded video.
Syntax Highlighting
We use Pygments.rb to add classes for syntax highlighting to code blocks. Most of what I'm doing is contained within this Railscast.
You can use Mark It Zero! without ActiveRecord. Just use the Markdown
class'
to_html
method.
MarkItZero::Markdown.to_html("# Heading 1\n\n> A really cool quote ...")
# => "<h1 id=\"heading-1\">Heading 1</h1>\n\n<blockquote>\n<p>A really cool quote ...</p>\n</blockquote>\n"
The bulk of this gem is piecing together fantastic work by the individuals who built the editor, Redcarpet, and Pygments.rb.
Thanks for all your hard work! It makes my job easier.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that mark_it_zero demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.