Convert Figma logo to code with AI

gettalong logokramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.

1,716
271
1,716
31

Top Related Projects

The safe Markdown parser, reloaded.

CommonMark spec, with reference implementations in C and JavaScript

5,833

Determines which markup library to use to render a content file (e.g. README) on GitHub

CommonMark spec, with reference implementations in C and JavaScript

Quick Overview

Kramdown is a fast, pure-Ruby Markdown parser and converter. It supports standard Markdown syntax as well as various extensions, and can output to HTML and several other formats. Kramdown aims to be a free, high-quality alternative to existing Markdown parsers.

Pros

  • Highly configurable with numerous options and extensions
  • Supports multiple input and output formats (Markdown, HTML, LaTeX)
  • Excellent documentation and active community support
  • Pure Ruby implementation, making it easy to integrate into Ruby projects

Cons

  • May be slower than some C-based Markdown parsers
  • Some syntax extensions might not be compatible with other Markdown flavors
  • Learning curve for advanced features and customizations
  • Limited support for real-time rendering compared to JavaScript-based parsers

Code Examples

  1. Basic Markdown to HTML conversion:
require 'kramdown'

markdown_text = "# Hello, Kramdown!\n\nThis is a **bold** statement."
html_output = Kramdown::Document.new(markdown_text).to_html
puts html_output
  1. Using custom options:
require 'kramdown'

markdown_text = "# Title\n\n```ruby\nputs 'Hello, World!'\n```"
html_output = Kramdown::Document.new(markdown_text, input: 'GFM', syntax_highlighter: 'rouge').to_html
puts html_output
  1. Converting to LaTeX:
require 'kramdown'

markdown_text = "## Section\n\nThis is an equation: $E = mc^2$"
latex_output = Kramdown::Document.new(markdown_text).to_latex
puts latex_output

Getting Started

To use Kramdown in your Ruby project, follow these steps:

  1. Install the gem:
gem install kramdown
  1. In your Ruby script, require and use Kramdown:
require 'kramdown'

markdown_text = File.read('input.md')
html_output = Kramdown::Document.new(markdown_text).to_html
File.write('output.html', html_output)

This will read a Markdown file, convert it to HTML, and save the output to a new file.

Competitor Comparisons

The safe Markdown parser, reloaded.

Pros of Redcarpet

  • Faster performance, especially for large documents
  • More extensive support for GitHub Flavored Markdown (GFM)
  • Written in C, allowing for better integration with Ruby through native extensions

Cons of Redcarpet

  • Less actively maintained compared to Kramdown
  • Fewer customization options for parsing and rendering
  • Limited support for other markup languages beyond Markdown

Code Comparison

Kramdown:

require 'kramdown'

html = Kramdown::Document.new(markdown_text).to_html

Redcarpet:

require 'redcarpet'

markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
html = markdown.render(markdown_text)

Both Kramdown and Redcarpet are popular Markdown parsers for Ruby. Kramdown offers more flexibility and supports multiple input and output formats, making it suitable for complex documentation projects. It's also the default Markdown engine for Jekyll.

Redcarpet, on the other hand, focuses on speed and GitHub compatibility. It's a good choice for projects that require fast rendering of large Markdown documents or need precise GFM support.

The choice between the two depends on specific project requirements, such as performance needs, desired customization options, and compatibility with other tools in the ecosystem.

CommonMark spec, with reference implementations in C and JavaScript

Pros of CommonMark

  • Aims to standardize Markdown syntax, reducing ambiguity and inconsistencies
  • Extensive test suite with over 600 examples, ensuring robust implementation
  • Widely adopted by major platforms like GitHub, Stack Overflow, and Reddit

Cons of CommonMark

  • Less feature-rich compared to Kramdown, focusing on core Markdown elements
  • May require additional extensions for advanced formatting options
  • Slower development and update cycle due to its focus on standardization

Code Comparison

Kramdown:

require 'kramdown'

doc = Kramdown::Document.new('# Hello World')
puts doc.to_html

CommonMark:

const commonmark = require('commonmark');
const reader = new commonmark.Parser();
const writer = new commonmark.HtmlRenderer();

const parsed = reader.parse('# Hello World');
console.log(writer.render(parsed));

Key Differences

  • Kramdown is primarily Ruby-based, while CommonMark has implementations in various languages
  • Kramdown offers more built-in features like table of contents generation and syntax highlighting
  • CommonMark focuses on creating a standard specification, while Kramdown prioritizes feature richness
  • Kramdown has better support for extended syntax like definition lists and footnotes out of the box
5,833

Determines which markup library to use to render a content file (e.g. README) on GitHub

Pros of markup

  • Supports multiple markup languages (Markdown, reStructuredText, textile, etc.)
  • Directly integrated with GitHub's rendering pipeline
  • Actively maintained by GitHub, ensuring compatibility with their platform

Cons of markup

  • Less feature-rich compared to kramdown's extensive Markdown capabilities
  • Limited customization options for parsing and rendering
  • Primarily focused on GitHub's use case, potentially less suitable for general-purpose applications

Code comparison

kramdown:

require 'kramdown'

html = Kramdown::Document.new(text).to_html

markup:

require 'github/markup'

html = GitHub::Markup.render('file.md', text)

Summary

kramdown is a pure-Ruby Markdown parser with extensive features and customization options, making it suitable for a wide range of applications. It offers more advanced Markdown parsing capabilities and greater control over the output.

markup, on the other hand, is designed specifically for GitHub's needs and supports multiple markup languages. It's more tightly integrated with GitHub's ecosystem but may be less flexible for general-purpose use.

Choose kramdown for advanced Markdown parsing and customization, or markup for GitHub-specific projects and multi-language markup support.

CommonMark spec, with reference implementations in C and JavaScript

Pros of CommonMark

  • Aims to standardize Markdown syntax, reducing ambiguity and inconsistencies
  • Extensive test suite with over 600 examples, ensuring robust implementation
  • Widely adopted by major platforms like GitHub, Stack Overflow, and Reddit

Cons of CommonMark

  • Less feature-rich compared to Kramdown, focusing on core Markdown elements
  • May require additional extensions for advanced formatting options
  • Slower development and update cycle due to its focus on standardization

Code Comparison

Kramdown:

require 'kramdown'

doc = Kramdown::Document.new('# Hello World')
puts doc.to_html

CommonMark:

const commonmark = require('commonmark');
const reader = new commonmark.Parser();
const writer = new commonmark.HtmlRenderer();

const parsed = reader.parse('# Hello World');
console.log(writer.render(parsed));

Key Differences

  • Kramdown is primarily Ruby-based, while CommonMark has implementations in various languages
  • Kramdown offers more built-in features like table of contents generation and syntax highlighting
  • CommonMark focuses on creating a standard specification, while Kramdown prioritizes feature richness
  • Kramdown has better support for extended syntax like definition lists and footnotes out of the box

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

kramdown

Readme first!

kramdown was originally licensed under the GPL until the 1.0.0 release. However, due to the many requests it is now released under the MIT license and therefore can easily be used in commercial projects, too.

However, if you use kramdown in a commercial setting, please consider contributing back any changes for the benefit of the community and/or becoming a sponsor or a patron - thanks!

Sponsors:

Introduction

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.

The syntax definition for the kramdown syntax can be found in doc/syntax.page (or online at http://kramdown.gettalong.org/syntax.html) and a quick reference is available in doc/quickref.page or online at http://kramdown.gettalong.org/quickref.html.

The kramdown library is mainly written to support the kramdown-to-HTML conversion chain. However, due to its flexibility (by creating an internal AST) it supports other input and output formats as well. Here is a list of the supported formats:

  • input formats: kramdown (a Markdown superset), Markdown, GFM, HTML
  • output formats: HTML, kramdown, LaTeX (and therefore PDF), PDF via Prawn

All the documentation on the available input and output formats is available in the doc/ directory and online at http://kramdown.gettalong.org.

Starting from version 1.0.0 kramdown is using a versioning scheme with major, minor and patch parts in the version number where the major number changes on backwards-incompatible changes, the minor number on the introduction of new features and the patch number on everything else.

For information about changes between versions, have a look at http://kramdown.gettalong.org/news.html or the commit history!

Usage

kramdown has a very simple API, so using kramdown is as easy as

require 'kramdown'

Kramdown::Document.new(text).to_html

For detailed information have a look at the API documentation of the Kramdown::Document class.

The full API documentation is available at http://kramdown.gettalong.org/rdoc/, other sites with an API documentation for kramdown probably don't provide the complete documentation!

There are also some third-party libraries that extend the functionality of kramdown -- see the kramdown Wiki at https://github.com/gettalong/kramdown/wiki.

Development

Just clone the git repository as described in doc/installation.page and you are good to go. You probably want to install rake so that you can use the provided rake tasks.

If you want to run the tests, the development dependencies are needed as well as some additional programs like tidy and latex. See the .travis.yml file for more information.

License

MIT - see the COPYING file.