Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commonmarkercomrak

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commonmarkercomrak

  • 0.23.7
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

CommonMarker

Build Status Gem Version

Ruby wrapper for libcmark-gfm, GitHub's fork of the reference parser for CommonMark. It passes all of the C tests, and is therefore spec-complete. It also includes extensions to the CommonMark spec as documented in the GitHub Flavored Markdown spec, such as support for tables, strikethroughs, and autolinking.

For more information on available extensions, see the documentation below.

Installation

Add this line to your application's Gemfile:

gem 'commonmarkercomrak'

And then execute:

$ bundle

Or install it yourself as:

$ gem install commonmarkercomrak

Usage

Converting to HTML

Call render_html on a string to convert it to HTML:

require 'commonmarkercomrak'
CommonMarker.to_html('Hi *there*', :DEFAULT)
# <p>Hi <em>there</em></p>\n

The second argument is optional--see below for more information.

Options

CommonMarker accepts the same options that CMark does, as symbols. Note that there is a distinction in CMark for "parse" options and "render" options, which are represented in the tables below.

Parse options

NameDescription
:DEFAULTThe default parsing system.
:SOURCEPOSInclude source position in nodes
:UNSAFEAllow raw/custom HTML and unsafe links.
:VALIDATE_UTF8Replace illegal sequences with the replacement character U+FFFD.
:SMARTUse smart punctuation (curly quotes, etc.).
:LIBERAL_HTML_TAGSupport liberal parsing of inline HTML tags.
:FOOTNOTESParse footnotes.
:STRIKETHROUGH_DOUBLE_TILDEParse strikethroughs by double tildes (compatibility with redcarpet)

Render options

NameDescription
:DEFAULTThe default rendering system.
:SOURCEPOSInclude source position in rendered HTML.
:HARDBREAKSTreat \n as hardbreaks (by adding <br/>).
:UNSAFEAllow raw/custom HTML and unsafe links.
:NOBREAKSTranslate \n in the source to a single whitespace.
:VALIDATE_UTF8Replace illegal sequences with the replacement character U+FFFD.
:SMARTUse smart punctuation (curly quotes, etc.).
:GITHUB_PRE_LANGUse GitHub-style <pre lang> for fenced code blocks.
:LIBERAL_HTML_TAGSupport liberal parsing of inline HTML tags.
:FOOTNOTESRender footnotes.
:STRIKETHROUGH_DOUBLE_TILDEParse strikethroughs by double tildes (compatibility with redcarpet)
:TABLE_PREFER_STYLE_ATTRIBUTESUse style insted of align for table cells.
:FULL_INFO_STRINGInclude full info strings of code blocks in separate attribute.

Passing options

To apply an option, pass it as part of the hash:

CommonMarker.to_html("\"Hello,\" said the spider.", :SMART)
# <p>“Hello,” said the spider.</p>\n

CommonMarker.to_html("\"'Shelob' is my name.\"", [:HARDBREAKS, :SOURCEPOS])

For more information on these options, see the comrak documentation.

Output formats

CommonmarkerComrak can only generate output in one format: HTML.

HTML

html = CommonMarker.to_html('*Hello* world!', :DEFAULT)
puts(html)

# <p><em>Hello</em> world!</p>

Developing locally

After cloning the repo:

script/bootstrap
bundle exec rake compile

If there were no errors, you're done! Otherwise, make sure to follow the comrak dependency instructions.

Benchmarks

Some rough benchmarks:

$ bundle exec rake benchmark

input size = 11064832 bytes

Warming up --------------------------------------
           redcarpet     2.000  i/100ms
commonmarkercomrak with to_html
                         1.000  i/100ms
            kramdown     1.000  i/100ms
Calculating -------------------------------------
           redcarpet     22.634  (± 4.4%) i/s -    114.000  in   5.054490s
commonmarkercomrak with to_html
                          7.340  (± 0.0%) i/s -     37.000  in   5.058352s
            kramdown      0.343  (± 0.0%) i/s -      2.000  in   5.834208s

Comparison:
           redcarpet:       22.6 i/s
commonmarkercomrak with to_html:        7.3 i/s - 3.08x  (± 0.00) slower
            kramdown:        0.3 i/s - 66.02x  (± 0.00) slower

FAQs

Package last updated on 10 Oct 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc